Submission #39782

# Submission time Handle Problem Language Result Execution time Memory
39782 2018-01-18T13:35:55 Z aome None (JOI16_memory2) C++14
60 / 100
0 ms 2068 KB
#include <bits/stdc++.h>
#include "Memory2_lib.h"
using namespace std;

const int N = 105;

int res[N];
int f[N][N];
int cnt[N];
bool vis[N];
vector<int> v; 

void Solve(int T, int n) {
	memset(f, -1, sizeof f);
	memset(res, -1, sizeof res);
	if (n == 1) {
		Answer(0, 1, 0); return;
	}
	for (int i = 0; i < 3; ++i) v.push_back(i);
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < i; ++j) {
			f[i][j] = f[j][i] = Flip(i, j); 
		}
	}
	for (int i = 3; i < 2 * n; ++i) {
		for (int j = 0; j < 3; ++j) {
			f[i][v[j]] = f[v[j]][i] = Flip(i, v[j]);
		}
		v.push_back(i);
		int mn = 1e9;
		for (int j = 0; j < 4; ++j) {
			cnt[v[j]] = 0;
			for (int k = 0; k < j; ++k) {
				mn = min(mn, f[v[j]][v[k]]);
			}
		}
		int pos = -1;
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (j == k) continue;
				cnt[v[j]] += f[v[j]][v[k]] == mn; 
			}
			if (pos == -1 || cnt[pos] < cnt[v[j]]) pos = v[j];
		}
		res[pos] = mn;
		vector<int> _v = v; v.clear();
		for (int j = 0; j < 4; ++j) {
			if (_v[j] == pos) continue; v.push_back(_v[j]);
		}
	}
	// for (int i = 0; i < n * 2; ++i) cout << res[i] << ' '; cout << '\n';
	for (int i = 0; i < n * 2; ++i) {
		if (res[i] == -1) continue;
		for (int j = i + 1; j < n * 2; ++j) {
			if (res[j] == -1) continue;
			if (res[i] == res[j]) Answer(i, j, res[j]), vis[res[j]] = 1;
		}
	}
	int mn = 1e9, pos = -1;
	for (int i = 0; i < n * 2; ++i) {
		if (res[i] != -1 && !vis[res[i]]) pos = i;
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < i; ++j) {
			if (f[v[i]][v[j]] != res[pos]) {
				Answer(v[i], v[j], f[v[i]][v[j]]);
				for (int k = 0; k < 3; ++k) {
					if (k != i && k != j) {
						Answer(pos, v[k], res[pos]);
					}
				}
			}
		}
	}
}

Compilation message

memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:59:6: warning: unused variable 'mn' [-Wunused-variable]
  int mn = 1e9, pos = -1;
      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2068 KB Output is correct
2 Correct 0 ms 2068 KB Output is correct
3 Correct 0 ms 2068 KB Output is correct
4 Correct 0 ms 2068 KB Output is correct
5 Correct 0 ms 2068 KB Output is correct
6 Correct 0 ms 2068 KB Output is correct
7 Correct 0 ms 2068 KB Output is correct
8 Correct 0 ms 2068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2068 KB Output is correct
2 Correct 0 ms 2068 KB Output is correct
3 Correct 0 ms 2068 KB Output is correct
4 Correct 0 ms 2068 KB Output is correct
5 Correct 0 ms 2068 KB Output is correct
6 Correct 0 ms 2068 KB Output is correct
7 Correct 0 ms 2068 KB Output is correct
8 Correct 0 ms 2068 KB Output is correct
9 Correct 0 ms 2068 KB Output is correct
10 Correct 0 ms 2068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2068 KB Wrong Answer[3]
2 Halted 0 ms 0 KB -