Submission #483768

# Submission time Handle Problem Language Result Execution time Memory
483768 2021-11-01T04:19:33 Z rk42745417 Mouse (info1cup19_mouse) C++17
100 / 100
60 ms 296 KB
// 34/100
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(2e18) + ll(1e15);
const double EPS = 1e-8;

//int query(vector<int>);

void solve(int n) {
	vector<int> arr(n);
	for(int i = 0; i < n; i++)
		arr[i] = i + 1;
	mt19937 rnd(time(0));
	while(true) {
		int w = query(arr);
		if(w == n)
			return;
		if(w == 0)
			break;
		shuffle(arr.begin(), arr.end(), rnd);
	}
	vector<pair<int, int>> valid;
	auto my_query = [&](vector<pair<int, int>> &owo) {
		for(const auto &[a, b] : owo)
			swap(arr[a], arr[b]);
		int w = query(arr);
		for(const auto &[a, b] : owo)
			swap(arr[a], arr[b]);
		return w;
	};
	bool flag = false;
	function<void(int, int, vector<pair<int, int>>&, int)> divide = [&](int l, int r, vector<pair<int, int>> &pairs, int sum) {
		if(sum == 0 || flag)
			return;
		if(l == r - 1) {
			valid.push_back(pairs[l]);
			return;
		}
		vector<pair<int, int>> xdd;
		int m = l + r >> 1;
		for(int i = l; i < m; i++)
			xdd.push_back(pairs[i]);
		int ls = my_query(xdd), rs = sum - ls;
		if(ls == n)
			flag = true;
		divide(l, m, pairs, ls);
		divide(m, r, pairs, rs);
	};
	for(int i = 1; i <= n; i++) {
		vector<pair<int, int>> has;
		for(int j = 0; j < n; j++) {
			int k = (i - j + n) % n;
			if(j < k)
				has.push_back({j, k});
		}
		divide(0, has.size(), has, my_query(has));
		if(flag)
			return;
	}
	assert(!valid.empty() && valid.size() <= n);
	//cerr << "collected all pairs: ";
	//for(const auto &[a, b] : valid)
		//cerr << a << ' ' << b << '\n';
	//cerr << "----------------\n";
	vector<vector<int>> edge(n);
	for(const auto &[a, b] : valid) {
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	vector<bool> vis(n);
	function<void(int, vector<int>&)> dfs = [&](int u, vector<int>&tra) {
		vis[u] = true;
		tra.push_back(u);
		for(int v : edge[u])
			if(!vis[v])
				dfs(v, tra);
	};
	vector<bool> owo;
	vector<vector<int>> travs;
	vector<int> ans = arr;
	for(int i = 0; i < n; i++) {
		if(vis[i])
			continue;
		vector<int> tra;
		dfs(i, tra);
		//cerr << i << "-th traversal: ";
		//for(int a : tra)
			//cerr << a << ' ';
		//cerr << '\n';
		for(int i = 0; i < tra.size(); i++) {
			ans[tra[i]] = arr[tra[(i + 1) % tra.size()]];
		}
		int w = query(ans);
		if(w == n)
			return;
		if(w > 0)
			owo.push_back(true);
		else
			owo.push_back(false);
		travs.push_back(tra);
		ans = arr;
	}
	for(int i = 0; i < owo.size(); i++) {
		if(owo[i]) {
			auto &tra = travs[i];
			for(int j = 0; j < tra.size(); j++) {
				ans[tra[j]] = arr[tra[(j + 1) % tra.size()]];
			}
		}
		else {
			auto &tra = travs[i];
			for(int j = 0; j < tra.size(); j++)
				ans[tra[(j + 1) % tra.size()]] = arr[tra[j]];
		}
	}
	assert(query(ans) == n);
}

/*
vector<int> arr;
int query(vector<int> g) {
	int w = 0;
	for(int i = 0; i < g.size(); i++)
		w += arr[i] == g[i];
	cout << "query: ";
	for(int a : g)
		cout << a << ' ';
	cout << '\n';
	cout << "Answer: " << w << '\n';
	return w;
}
signed main() {
	int n;
	cin >> n;
	arr.resize(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	solve(n);
}
*/

Compilation message

mouse.cpp: In lambda function:
mouse.cpp:49:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |   int m = l + r >> 1;
      |           ~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from mouse.cpp:3:
mouse.cpp: In function 'void solve(int)':
mouse.cpp:69:40: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |  assert(!valid.empty() && valid.size() <= n);
      |                           ~~~~~~~~~~~~~^~~~
mouse.cpp:99:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   for(int i = 0; i < tra.size(); i++) {
      |                  ~~^~~~~~~~~~~~
mouse.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |  for(int i = 0; i < owo.size(); i++) {
      |                 ~~^~~~~~~~~~~~
mouse.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |    for(int j = 0; j < tra.size(); j++) {
      |                   ~~^~~~~~~~~~~~
mouse.cpp:121:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |    for(int j = 0; j < tra.size(); j++)
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 18
2 Correct 0 ms 200 KB Correct! Number of queries: 7
3 Correct 0 ms 200 KB Correct! Number of queries: 14
4 Correct 1 ms 200 KB Correct! Number of queries: 17
5 Correct 1 ms 200 KB Correct! Number of queries: 19
6 Correct 1 ms 200 KB Correct! Number of queries: 20
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 18
2 Correct 0 ms 200 KB Correct! Number of queries: 7
3 Correct 0 ms 200 KB Correct! Number of queries: 14
4 Correct 1 ms 200 KB Correct! Number of queries: 17
5 Correct 1 ms 200 KB Correct! Number of queries: 19
6 Correct 1 ms 200 KB Correct! Number of queries: 20
7 Correct 5 ms 200 KB Correct! Number of queries: 300
8 Correct 5 ms 200 KB Correct! Number of queries: 300
9 Correct 3 ms 200 KB Correct! Number of queries: 300
10 Correct 3 ms 296 KB Correct! Number of queries: 300
11 Correct 3 ms 292 KB Correct! Number of queries: 300
12 Correct 3 ms 200 KB Correct! Number of queries: 300
13 Correct 4 ms 200 KB Correct! Number of queries: 300
14 Correct 5 ms 200 KB Correct! Number of queries: 300
15 Correct 4 ms 200 KB Correct! Number of queries: 300
16 Correct 4 ms 200 KB Correct! Number of queries: 300
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 18
2 Correct 0 ms 200 KB Correct! Number of queries: 7
3 Correct 0 ms 200 KB Correct! Number of queries: 14
4 Correct 1 ms 200 KB Correct! Number of queries: 17
5 Correct 1 ms 200 KB Correct! Number of queries: 19
6 Correct 1 ms 200 KB Correct! Number of queries: 20
7 Correct 5 ms 200 KB Correct! Number of queries: 300
8 Correct 5 ms 200 KB Correct! Number of queries: 300
9 Correct 3 ms 200 KB Correct! Number of queries: 300
10 Correct 3 ms 296 KB Correct! Number of queries: 300
11 Correct 3 ms 292 KB Correct! Number of queries: 300
12 Correct 3 ms 200 KB Correct! Number of queries: 300
13 Correct 4 ms 200 KB Correct! Number of queries: 300
14 Correct 5 ms 200 KB Correct! Number of queries: 300
15 Correct 4 ms 200 KB Correct! Number of queries: 300
16 Correct 4 ms 200 KB Correct! Number of queries: 300
17 Correct 59 ms 292 KB Correct! Number of queries: 1900
18 Correct 52 ms 296 KB Correct! Number of queries: 1800
19 Correct 57 ms 280 KB Correct! Number of queries: 1800
20 Correct 57 ms 292 KB Correct! Number of queries: 1900
21 Correct 53 ms 292 KB Correct! Number of queries: 1800
22 Correct 53 ms 284 KB Correct! Number of queries: 1800
23 Correct 59 ms 292 KB Correct! Number of queries: 1800
24 Correct 60 ms 292 KB Correct! Number of queries: 1900
25 Correct 59 ms 288 KB Correct! Number of queries: 1900
26 Correct 59 ms 280 KB Correct! Number of queries: 1900