답안 #471850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471850 2021-09-11T07:28:13 Z dennisstar Memory 2 (JOI16_memory2) C++17
100 / 100
1 ms 288 KB
#include "Memory2_lib.h"
#include <bits/stdc++.h>

using namespace std;

void Solve(int t, int n) {
	vector<int> val(2*n, -1), cnt(n, 0);
	vector<vector<int>> st(n);
	priority_queue<int> pq;
	for (int i=0; i<2*n; i++) pq.emplace(i);
	int lx;
	while (pq.size()) {
		int x=pq.top();
		pq.pop();
		while (pq.size()) {
			int y=pq.top();
			pq.pop();
			int r=Flip(x, y);
			if (st[r].size()+cnt[r]==2) {
				val[x]=r;
				cnt[r]++;
				pq.emplace(y);
				for (auto &i:st[r]) pq.emplace(i);
				for (int i=0; i<n; i++) {
					if (i!=r) for (auto &j:st[i]) val[j]=i, cnt[i]++;
					st[i].clear();
				}
				break;
			}
			st[r].emplace_back(y);
		}
		lx=x;
	}
	for (int i=0; i<2*n; i++) if (val[i]!=-1) st[val[i]].emplace_back(i);
	for (int i=0; i<n; i++) {
		if (st[i].size()==1) st[i].emplace_back(lx);
		Answer(st[i][0], st[i][1], i);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct