답안 #365390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365390 2021-02-11T15:08:30 Z Mlxa Mouse (info1cup19_mouse) C++14
81.6923 / 100
227 ms 1648 KB
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 1000;

int n;
int p[N];
int c[N][N];
bool b[N][N];
int bc[N];
int kn[N];

mt19937 rnd;

int query(vector<int>);

void block(int i, int j) {
	if (b[i][j]) {
		return;
	}
	b[i][j] = true;
	++bc[i];
	if (bc[i] == n - 1) {
		kn[i] = 1;
		while (b[i][kn[i]]) {
			++kn[i];
		}
		for (int ii = 0; ii < n; ++ii) {
			if (ii != i) {
				block(ii, kn[i]);
			}
		}
	}
}

bool bad(vector<int> q) {
	for (int i = 0; i < (int)q.size(); ++i) {
		if (q[i] == kn[i]) {
			return true;
		}
	}
	return false;
}

void solve(int _n) {
	n = _n;
	vector<int> q(n);
	iota(all(q), 1);
	for (int it = 1; ; ++it) {
		int cur = query(q);
		if (cur == n) {
			return;
		}
		if (cur > 2) {
			for (int i = 0; i < n; ++i) {
				c[i][q[i]] += cur;
			}
		} else if (!cur) {
			for (int i = 0; i < n; ++i) {
				block(i, q[i]);
			}
		}
		shuffle(all(q), rnd);
		while (bad(q)) {
			shuffle(all(q), rnd);
		}
		if (*min_element(bc, bc + n) == n - 1) {
#ifdef LC
			cout << it << " queries" << endl;
#endif
			q.assign(kn, kn + n);
			assert(query(q) == n);
			return;
		}
	}
}

#ifdef LC
int query(vector<int> q) {
	int cnt = 0;
	for (int i = 0; i < (int)q.size(); ++i) {
		cnt += p[i] == q[i];
	}
	return cnt;
}
signed main() {
	assert(freopen("input.txt", "r", stdin));
	int _n;
	cin >> _n;
	for (int i = 0; i < _n; ++i) {
		cin >> p[i];
	}
	solve(_n);
	return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 500 KB Correct! Number of queries: 35
2 Correct 1 ms 364 KB Correct! Number of queries: 3
3 Correct 1 ms 388 KB Correct! Number of queries: 31
4 Correct 1 ms 364 KB Correct! Number of queries: 35
5 Correct 1 ms 364 KB Correct! Number of queries: 25
6 Correct 1 ms 388 KB Correct! Number of queries: 16
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 500 KB Correct! Number of queries: 35
2 Correct 1 ms 364 KB Correct! Number of queries: 3
3 Correct 1 ms 388 KB Correct! Number of queries: 31
4 Correct 1 ms 364 KB Correct! Number of queries: 35
5 Correct 1 ms 364 KB Correct! Number of queries: 25
6 Correct 1 ms 388 KB Correct! Number of queries: 16
7 Correct 10 ms 620 KB Correct! Number of queries: 500
8 Correct 9 ms 620 KB Correct! Number of queries: 500
9 Correct 10 ms 620 KB Correct! Number of queries: 600
10 Correct 13 ms 620 KB Correct! Number of queries: 600
11 Correct 6 ms 492 KB Correct! Number of queries: 400
12 Correct 12 ms 620 KB Correct! Number of queries: 600
13 Correct 9 ms 620 KB Correct! Number of queries: 500
14 Correct 9 ms 620 KB Correct! Number of queries: 600
15 Correct 8 ms 620 KB Correct! Number of queries: 500
16 Correct 11 ms 640 KB Correct! Number of queries: 600
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 500 KB Correct! Number of queries: 35
2 Correct 1 ms 364 KB Correct! Number of queries: 3
3 Correct 1 ms 388 KB Correct! Number of queries: 31
4 Correct 1 ms 364 KB Correct! Number of queries: 35
5 Correct 1 ms 364 KB Correct! Number of queries: 25
6 Correct 1 ms 388 KB Correct! Number of queries: 16
7 Correct 10 ms 620 KB Correct! Number of queries: 500
8 Correct 9 ms 620 KB Correct! Number of queries: 500
9 Correct 10 ms 620 KB Correct! Number of queries: 600
10 Correct 13 ms 620 KB Correct! Number of queries: 600
11 Correct 6 ms 492 KB Correct! Number of queries: 400
12 Correct 12 ms 620 KB Correct! Number of queries: 600
13 Correct 9 ms 620 KB Correct! Number of queries: 500
14 Correct 9 ms 620 KB Correct! Number of queries: 600
15 Correct 8 ms 620 KB Correct! Number of queries: 500
16 Correct 11 ms 640 KB Correct! Number of queries: 600
17 Correct 195 ms 1644 KB Correct! Number of queries: 3900
18 Correct 189 ms 1516 KB Correct! Number of queries: 3600
19 Correct 182 ms 1516 KB Correct! Number of queries: 3500
20 Correct 227 ms 1648 KB Correct! Number of queries: 4000
21 Correct 158 ms 1516 KB Correct! Number of queries: 3500
22 Correct 192 ms 1516 KB Correct! Number of queries: 3900
23 Correct 160 ms 1644 KB Correct! Number of queries: 3500
24 Correct 217 ms 1648 KB Correct! Number of queries: 3900
25 Correct 167 ms 1644 KB Correct! Number of queries: 3500
26 Correct 176 ms 1648 KB Correct! Number of queries: 3700