Submission #319903

# Submission time Handle Problem Language Result Execution time Memory
319903 2020-11-06T17:27:48 Z gustason ZigZag (COCI17_zigzag) C++14
80 / 80
270 ms 12588 KB
#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
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 258 ms 12588 KB Output is correct
8 Correct 264 ms 12388 KB Output is correct
9 Correct 262 ms 12388 KB Output is correct
10 Correct 270 ms 12516 KB Output is correct