#include <bits/stdc++.h>
using namespace std;
typedef pair<int,string> ps;
priority_queue<ps, vector<ps>, greater<ps> > pq;
int n,k;
int main()
{
// freopen("doanchu.inp","r",stdin);
// freopen("doanchu.out","w",stdout);
cin >> n >> k;
for (int i = 1; i <= n; i++){
string s;
cin >> s; pq.push({0,s});
}
for (int i = 1 ; i <= k ; i++){
char c;
cin >> c;
vector<ps> temp;
while(!pq.empty()){
if (pq.top().second[0]!=c) {temp.push_back(pq.top()); pq.pop();}
else{
string v = pq.top().second; int u = pq.top().first;
cout << v << endl;
pq.pop();
pq.push({u+1,v});
for (int i = 0; i < temp.size(); i++) pq.push(temp[i]);
temp.clear();
break;
}
}
}
return 0;
}
Compilation message
zigzag.cpp: In function 'int main()':
zigzag.cpp:31:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < temp.size(); i++) pq.push(temp[i]);
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
19 ms |
332 KB |
Output is correct |
4 |
Correct |
23 ms |
332 KB |
Output is correct |
5 |
Correct |
26 ms |
372 KB |
Output is correct |
6 |
Correct |
30 ms |
356 KB |
Output is correct |
7 |
Execution timed out |
2087 ms |
14812 KB |
Time limit exceeded |
8 |
Execution timed out |
2083 ms |
18620 KB |
Time limit exceeded |
9 |
Execution timed out |
2091 ms |
16012 KB |
Time limit exceeded |
10 |
Execution timed out |
2079 ms |
16032 KB |
Time limit exceeded |