# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
319903 | gustason | ZigZag (COCI17_zigzag) | C++14 | 270 ms | 12588 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;
using ll = long long;
struct S {
string word;
int used;
bool operator<(S other) const {
if (used == other.used) {
return word < other.word;
}
return used < other.used;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
set<S> s[30];
for(int i = 0; i < n; i++) {
string str;
cin >> str;
s[str[0]-'a'].insert({str, 0});
}
while(m--) {
char letter;
cin >> letter;
auto it = s[letter-'a'].begin();
S curr = *it;
cout << curr.word << "\n";
s[letter-'a'].erase(it);
s[letter-'a'].insert({curr.word, curr.used+1});
// for(auto i : s[letter-'a']) {
// cout << i.word << " " << i.used << "\n";
// }
// cout << "\n";
}
return 0;
}
//~ check for overflows
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |