Submission #474501

# Submission time Handle Problem Language Result Execution time Memory
474501 2021-09-18T14:21:58 Z hhhhaura Mouse (info1cup19_mouse) C++14
100 / 100
88 ms 556 KB
#define wiwihorz
#include "grader.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

using namespace std;

#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line: " << __LINE__, kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, tot;
vector<int> a, vis, ch;
vector<vector<int>> mp;
random;
/*void init_(int _n) {
	n = _n, tot = 0;
	a.assign(n, 0);
	rep(i, 1, n) a[i - 1] = i;
	shuffle(a.begin(), a.begin() + n, rnd);
}
int query(vector<int> b) {
	assert(b.size() == n);
	int cnt = 0;
	tot ++;
	rep(i, 0, n - 1) cnt += a[i] == b[i];
	return cnt;
}*/
void dfs(int x) {
	ch.push_back(x);
	vis[x] = 1;
	for(auto i : mp[x]) 
		if(!vis[i]) dfs(i);
}
void solve(int n) {
//	init_(n);
	if(n == 1) {
		query({1});
		return;
	}
	vector<int> v(n, 0), ans(n, 0), rot(n + 1, 0);
	vector<vector<int>> p(n, vector<int>(n, 0));
	vis.assign(n, 0);
	mp.assign(n, vector<int>());
	int num = (n % 2 == 0 ? n : n + 1);
	rep(i, 1, n) v[i - 1] = i, rot[i - 1] = i;
	while(query(v)) shuffle(all(v), rnd);
	rep(i, 0, num - 2) {
		int cur = 0 ;
		rep(j, 0, num / 2 - 1) if(rot[j] && rot[num - j - 1])
			swap(v[rot[j] - 1], v[rot[num - j - 1] - 1]);
		cur = query(v);
		rep(j, 0, num / 2 - 1) if(rot[j] && rot[num - j - 1])
			swap(v[rot[j] - 1], v[rot[num - j - 1] - 1]);
		rrep(j, 1, cur) {
			int L = -1, R = num / 2 - 1;
			while(R - L > 1) {
				int mid = (L + R) / 2;
				rep(k, 0, mid) if(rot[k] && rot[num - k - 1])
					swap(v[rot[k] - 1], v[rot[num - k - 1] - 1]);
				if(query(v) < j) L = mid;
				else R = mid;
				rep(k, 0, mid) if(rot[k] && rot[num - k - 1])
					swap(v[rot[k] - 1], v[rot[num - k - 1] - 1]);
			} 
			int x = rot[R] - 1, y = rot[num - R - 1] - 1;
			p[x][y] = p[y][x] = 1;
		}
		vector<int> temp(num, 0);
		temp[0] = 1, temp[1] = rot[num - 1];
		rep(i, 2, num - 1) temp[i] = rot[i - 1];
		rot = temp;
	}
	rep(i, 0, n - 1) rep(j, 0, n - 1) {
		if(p[i][j]) mp[i].push_back(j);
	}
	int sum = 0, val;
	rep(i, 0, n - 1) if(!vis[i]) {
		ch.clear(), dfs(i);
		int sz = ch.size();
		sum += sz;
		if(sz == 1) continue;
		ans = v;
		rep(j, 1, sz - 1) swap(
			ans[ch[j - 1]], ans[ch[j]]
		);
		if(query(ans) == sum) {
			v = ans;
			continue;
		}
		ans = v;
		rrep(j, 1, sz - 1) swap(
			ans[ch[j - 1]], ans[ch[j]]
		);
		v = ans;
		query(ans);
	}
}
/*signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int t; cin >> t;
	while(t--) {
		int n; cin >> n;
		solve(n);
		print(tot);
	}
	return 0;
}*/

Compilation message

mouse.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
mouse.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
mouse.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R)cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
mouse.cpp: In function 'void solve(int)':
mouse.cpp:92:15: warning: unused variable 'val' [-Wunused-variable]
   92 |  int sum = 0, val;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 24
2 Correct 1 ms 200 KB Correct! Number of queries: 9
3 Correct 1 ms 200 KB Correct! Number of queries: 17
4 Correct 1 ms 200 KB Correct! Number of queries: 23
5 Correct 1 ms 200 KB Correct! Number of queries: 26
6 Correct 1 ms 200 KB Correct! Number of queries: 25
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 24
2 Correct 1 ms 200 KB Correct! Number of queries: 9
3 Correct 1 ms 200 KB Correct! Number of queries: 17
4 Correct 1 ms 200 KB Correct! Number of queries: 23
5 Correct 1 ms 200 KB Correct! Number of queries: 26
6 Correct 1 ms 200 KB Correct! Number of queries: 25
7 Correct 6 ms 200 KB Correct! Number of queries: 300
8 Correct 4 ms 200 KB Correct! Number of queries: 300
9 Correct 5 ms 200 KB Correct! Number of queries: 300
10 Correct 5 ms 200 KB Correct! Number of queries: 300
11 Correct 7 ms 200 KB Correct! Number of queries: 300
12 Correct 7 ms 308 KB Correct! Number of queries: 300
13 Correct 5 ms 200 KB Correct! Number of queries: 300
14 Correct 6 ms 312 KB Correct! Number of queries: 300
15 Correct 5 ms 200 KB Correct! Number of queries: 300
16 Correct 6 ms 200 KB Correct! Number of queries: 300
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct! Number of queries: 24
2 Correct 1 ms 200 KB Correct! Number of queries: 9
3 Correct 1 ms 200 KB Correct! Number of queries: 17
4 Correct 1 ms 200 KB Correct! Number of queries: 23
5 Correct 1 ms 200 KB Correct! Number of queries: 26
6 Correct 1 ms 200 KB Correct! Number of queries: 25
7 Correct 6 ms 200 KB Correct! Number of queries: 300
8 Correct 4 ms 200 KB Correct! Number of queries: 300
9 Correct 5 ms 200 KB Correct! Number of queries: 300
10 Correct 5 ms 200 KB Correct! Number of queries: 300
11 Correct 7 ms 200 KB Correct! Number of queries: 300
12 Correct 7 ms 308 KB Correct! Number of queries: 300
13 Correct 5 ms 200 KB Correct! Number of queries: 300
14 Correct 6 ms 312 KB Correct! Number of queries: 300
15 Correct 5 ms 200 KB Correct! Number of queries: 300
16 Correct 6 ms 200 KB Correct! Number of queries: 300
17 Correct 76 ms 552 KB Correct! Number of queries: 2100
18 Correct 88 ms 528 KB Correct! Number of queries: 2000
19 Correct 68 ms 528 KB Correct! Number of queries: 2000
20 Correct 85 ms 552 KB Correct! Number of queries: 2100
21 Correct 85 ms 552 KB Correct! Number of queries: 2000
22 Correct 74 ms 524 KB Correct! Number of queries: 2000
23 Correct 79 ms 540 KB Correct! Number of queries: 2000
24 Correct 81 ms 556 KB Correct! Number of queries: 2100
25 Correct 82 ms 556 KB Correct! Number of queries: 2100
26 Correct 87 ms 556 KB Correct! Number of queries: 2100