Submission #55417

# Submission time Handle Problem Language Result Execution time Memory
55417 2018-07-07T08:47:34 Z kriii None (JOI16_memory2) C++17
100 / 100
3 ms 924 KB
#include <vector>
#include "Memory2_lib.h"
using namespace std;

int mem[101][101],A[101];

int manage(int i, int j)
{
	if (mem[i][j] == -1){
		mem[i][j] = mem[j][i] = Flip(i,j);
	}
	return mem[i][j];
}

void Solve(int T, int N){
	if (N == 1){
		Answer(0,1,0);
		return;
	}
	for (int i=0;i<2*N;i++) for (int j=0;j<2*N;j++) mem[i][j] = -1;

	vector<int> u;
	u.push_back(0); u.push_back(1); u.push_back(2);
	for (int i=3;i<2*N;i++){
		u.push_back(i);
		for (int p=0;p<4;p++){
			int k = -1;
			for (int q=0;q<4;q++) if (p != q){
				if (k == -1) k = manage(u[p],u[q]);
				else if (k != manage(u[p],u[q])){
					k = -2; break;
				}
			}
			if (k != -2){
				A[u[p]] = k;
				u.erase(u.begin()+p);
				break;
			}
		}
	}
	
	int a = manage(u[0],u[1]);
	int b = manage(u[1],u[2]);
	int c = manage(u[2],u[0]);
	
	if (a == b){
		A[u[0]] = c;
		A[u[1]] = a;
		A[u[2]] = c;
	}
	else if (b == c){
		A[u[0]] = a;
		A[u[1]] = a;
		A[u[2]] = b;
	}
	else{
		A[u[0]] = c;
		A[u[1]] = b;
		A[u[2]] = b;
	}

	for (int x=0;x<N;x++){
		int p = -1,q = -1;
		for (int i=0;i<2*N;i++) if (A[i] == x){p = i; break;}
		for (int i=p+1;i<2*N;i++) if (A[i] == x){q = i; break;}
		Answer(p,q,x);
	}
}
# 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 2 ms 480 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 696 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 700 KB Output is correct
2 Correct 2 ms 700 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 2 ms 868 KB Output is correct
6 Correct 2 ms 868 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 3 ms 868 KB Output is correct
10 Correct 3 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 868 KB Output is correct
2 Correct 3 ms 868 KB Output is correct
3 Correct 3 ms 924 KB Output is correct
4 Correct 3 ms 924 KB Output is correct
5 Correct 3 ms 924 KB Output is correct
6 Correct 2 ms 924 KB Output is correct
7 Correct 2 ms 924 KB Output is correct
8 Correct 3 ms 924 KB Output is correct
9 Correct 3 ms 924 KB Output is correct
10 Correct 2 ms 924 KB Output is correct