Submission #886687

# Submission time Handle Problem Language Result Execution time Memory
886687 2023-12-12T16:19:48 Z vjudge1 ZigZag (COCI17_zigzag) C++17
80 / 80
50 ms 6484 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=2e5+100;
#else
    const int lim=2e3+100;
#endif

#include "bits/stdc++.h"
using namespace std;

#define int int64_t
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

inline void solve(){
    int n,m;
    cin>>n>>m;
    deque<string>all[256];
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        all[s[0]].push_back(s);
    }
    for(int i=0;i<256;i++){
        sort(all[i].begin(),all[i].end());
    }
    for(int i=0;i<m;i++){
        char c;
        cin>>c;
        cout<<all[c].front()<<"\n";
        all[c].push_back(all[c].front());
        all[c].pop_front();
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("grass.in","r",stdin);
    //freopen("grass.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}

Compilation message

zigzag.cpp: In function 'void solve()':
zigzag.cpp:24:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   24 |         all[s[0]].push_back(s);
      |                 ^
zigzag.cpp:32:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   32 |         cout<<all[c].front()<<"\n";
      |                   ^
zigzag.cpp:33:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   33 |         all[c].push_back(all[c].front());
      |             ^
zigzag.cpp:33:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   33 |         all[c].push_back(all[c].front());
      |                              ^
zigzag.cpp:34:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   34 |         all[c].pop_front();
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 39 ms 6424 KB Output is correct
8 Correct 40 ms 6420 KB Output is correct
9 Correct 40 ms 6480 KB Output is correct
10 Correct 50 ms 6484 KB Output is correct