Submission #170327

# Submission time Handle Problem Language Result Execution time Memory
170327 2019-12-24T20:04:26 Z ngmh ZigZag (COCI17_zigzag) C++11
80 / 80
1080 ms 12524 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<string, long long> pi;

struct cool_compare {
	bool operator() (const pi p, const pi q) const {
		if(p.first[0] != q.first[0]) return p.first[0] < q.first[0];
		else if(p.second != q.second) return p.second < q.second;
		else return p.first < q.first;
	}
};

long long k, n, b;
string x, a;
set<pi, cool_compare> words;
set<pi, cool_compare>::iterator it;
int main(){
	cin >> k >> n;
	for(int i = 0 ; i < k; i++){
		cin >> x;
		words.insert(pi(x, 0));
	}
	for(int i = 0; i < n; i++){
		cin >> x;
		it = words.lower_bound(pi(x, 0));
		cout << it->first << "\n";
		a = it->first;
		b = it->second;
		b++;
		words.erase(it);
		words.insert(pi(a, b));
	} 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 1080 ms 12476 KB Output is correct
8 Correct 1077 ms 12524 KB Output is correct
9 Correct 1071 ms 12460 KB Output is correct
10 Correct 1074 ms 12476 KB Output is correct