Submission #53199

# Submission time Handle Problem Language Result Execution time Memory
53199 2018-06-29T01:40:48 Z ainta None (JOI16_memory2) C++17
100 / 100
3 ms 828 KB
#include "Memory2_lib.h"

int w[220][220], R[220][2], RC[220];

int Get(int a, int b) {
	if (w[a][b] == 0) {
		int t = Flip(a, b);
		w[a][b] = w[b][a] = t + 1;
	}
	return w[a][b] - 1;
}

void Solve(int T, int N){
	if (N == 1) {
		Answer(0, 1, 0);
		return;
	}
	Get(0, 1);
	int i, t1 = 0, t2 = 1, t3 = -1;
	for (i = 2; i < 2*N; i++) {
		if (t3 == -1) {
			int c1 = Get(t1, t2);
			int c2 = Get(t1, i);
			int c3 = Get(t2, i);
			if (c1 == c2&&c2 == c3) {
				t3 = i;
				continue;
			}
			else {
				if (c1 == c2) {
					R[c1][RC[c1]++] = t1;
					t1 = i;
				}
				else if (c1 == c3) {
					R[c1][RC[c1]++] = t2;
					t2 = i;
				}
				else {
					R[c2][RC[c2]++] = i;
				}
			}
		}
		else {
			int cc = Get(t1, t2);
			int c1 = Get(t1, i);
			int c2 = Get(t2, i);
			int cnt = (cc == c1) + (cc == c2);
			if (cnt == 0) {
				R[c1][RC[c1]++] = i;
			}
			else {
				int c3 = Get(t3, i);
				if (cc == c1)R[cc][RC[cc]++] = t1;
				if (cc == c2)R[cc][RC[cc]++] = t2;
				if (cc == c3)R[cc][RC[cc]++] = t3;
				if (cc != c1)t2 = t1;
				if (cc != c2)t2 = t2;
				if (cc != c3)t2 = t3;
				t1 = i;
				t3 = -1;
			}
		}
	}
	for (i = 0; i < N; i++) {
		if (RC[i] == 0)Answer(t1, t2, i);
		else Answer(R[i][0], R[i][1], i);
	}
	return;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 2 ms 572 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 2 ms 696 KB Output is correct
7 Correct 3 ms 696 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 708 KB Output is correct
2 Correct 3 ms 712 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 2 ms 720 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 2 ms 828 KB Output is correct
8 Correct 2 ms 828 KB Output is correct
9 Correct 2 ms 828 KB Output is correct
10 Correct 2 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 828 KB Output is correct
2 Correct 2 ms 828 KB Output is correct
3 Correct 2 ms 828 KB Output is correct
4 Correct 2 ms 828 KB Output is correct
5 Correct 3 ms 828 KB Output is correct
6 Correct 2 ms 828 KB Output is correct
7 Correct 3 ms 828 KB Output is correct
8 Correct 2 ms 828 KB Output is correct
9 Correct 2 ms 828 KB Output is correct
10 Correct 3 ms 828 KB Output is correct