# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475306 | Beboo44 | ZigZag (COCI17_zigzag) | C++14 | 2087 ms | 9348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0)
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
ll n,m;
cin>>n>>m;
vector<vector<string>>v(26);
string s;
for(int i=0; i<n; ++i){
cin>>s;
int x = (int)s[0]-'a';
v[x].push_back(s);
}
vector<string>t;
for(int i=0; i<26; ++i){
for(int j=0; j< v[i].size(); ++j){
t.push_back(v[i][j]);
}
sort(t.begin(),t.end());
for(int j=0; j<v[i].size(); ++j){
v[i][j] = t[j];
}
t.clear();
}
char y;
while(m--){
cin>>y;
ll f = (int)y-'a';
cout<<v[f][0]<<endl;
v[f].push_back(v[f][0]);
v[f].erase(v[f].begin());
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |