답안 #42283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42283 2018-02-25T08:00:27 Z milmillin ZigZag (COCI17_zigzag) C++14
80 / 80
243 ms 13872 KB
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <iostream>

using namespace std;

struct word {
	string x;
	int cnt;
};

bool operator< (const word &a, const word&b) {
	if (a.cnt!=b.cnt) return a.cnt>b.cnt;
	return a.x>b.x;
}

priority_queue<word> qq[30];

int main () {
	int k,n;
	scanf("%d%d",&k,&n);
	string x;
	for (int i=0;i<k;i++) {
		cin>>x;
		qq[x[0]-'a'].push(word{x,0});
	}
	char xx;
	word now;
	for (int i=0;i<n;i++) {
		scanf(" %c",&xx);
		now = qq[xx-'a'].top();
		qq[xx-'a'].pop();
		cout << now.x << '\n';
		now.cnt++;
		qq[xx-'a'].push(now);
	}
	return 0;
}

Compilation message

zigzag.cpp: In function 'int main()':
zigzag.cpp:23:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&k,&n);
                     ^
zigzag.cpp:32:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&xx);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 230 ms 9168 KB Output is correct
8 Correct 237 ms 10628 KB Output is correct
9 Correct 225 ms 12256 KB Output is correct
10 Correct 243 ms 13872 KB Output is correct