답안 #56233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56233 2018-07-10T11:34:30 Z youngyojun Memory 2 (JOI16_memory2) C++11
100 / 100
5 ms 952 KB
#include "Memory2_lib.h"
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
using namespace std;
typedef pair<int, int> pii;

unordered_map<int, int> MP;

int A[555];

int ask(int a, int b) {
	if(a > b) swap(a, b);
	int key = (a<<10) + b;
	auto it = MP.find(key);
	if(MP.end() != it) return it -> second;
	int ret = Flip(a, b);
	MP[key] = ret;
	return ret;
}
int hsh(int a, int b) { return (a<<10)|b; }
void rhsh(int k, int &a, int &b) { b = k&1023; a = k>>10; }

void Solve(int T, int N) {
	vector<pii> V;
	for(int i = 0; i < N*2; i += 2)
		V.eb(hsh(i, i+1), ask(i, i+1));
	for(int a, b, t; !V.empty();) {
		a = b = -1;
		for(int i = 0; i < sz(V); i++) for(int j = i+1; j < sz(V); j++)
			if(V[i].second == V[j].second)
				tie(a, b) = pii(i, j);
		if(a < 0) break;

		int n[2], m[2];
		
		t = V[a].second;
		rhsh(V[a].first, n[0], n[1]);
		rhsh(V[b].first, m[0], m[1]);
		V.erase(V.begin() + b);
		V.erase(V.begin() + a);

		for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) {
			if(ask(n[i], m[j]) != t) {
				V.eb(hsh(n[i], m[j]), ask(n[i], m[j]));
				A[n[!i]] = A[m[!j]] = t;
			}
		}
	}

	for(auto &v : V) {
		int a, b; rhsh(v.first, a, b);
		A[a] = A[b] = v.second;
	}

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N*2; j++) for(int k = j+1; k < N*2; k++)
			if(A[j] == i && A[k] == i)
				Answer(j, k, i);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 3 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 688 KB Output is correct
2 Correct 3 ms 692 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 724 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 732 KB Output is correct
8 Correct 2 ms 736 KB Output is correct
9 Correct 3 ms 864 KB Output is correct
10 Correct 3 ms 864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 864 KB Output is correct
2 Correct 3 ms 864 KB Output is correct
3 Correct 4 ms 864 KB Output is correct
4 Correct 3 ms 864 KB Output is correct
5 Correct 3 ms 864 KB Output is correct
6 Correct 5 ms 864 KB Output is correct
7 Correct 3 ms 864 KB Output is correct
8 Correct 3 ms 952 KB Output is correct
9 Correct 4 ms 952 KB Output is correct
10 Correct 3 ms 952 KB Output is correct