Submission #1054178

# Submission time Handle Problem Language Result Execution time Memory
1054178 2024-08-12T07:19:40 Z socpite Secret Permutation (RMI19_permutation) C++17
40 / 100
5000 ms 604 KB
#include "permutation.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 300;

namespace {
	long long D[maxn];
	bool vis[maxn];
	vector<int> crr;
	vector<vector<int>> allans;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
}

void bt(int pos, int n, const vector<int> &P){
	if(pos > n){
		if(abs(crr.back() - crr[0]) != D[1])return;
		vector<int> nw(n);
		for(int i = 0; i < n; i++){
			nw[P[i]-1] = crr[i];
		}
		allans.push_back(nw);
		return;
	}
	int tmp = crr.back() + D[pos]; 
	if(tmp <= n && !vis[tmp]){
		crr.push_back(tmp);
		vis[tmp] = 1;
		bt(pos+1, n, P);
		vis[tmp] = 0;
		crr.pop_back();
	}
	
	tmp = crr.back() - D[pos]; 
	if(tmp > 0 && !vis[tmp]){
		crr.push_back(tmp);
		vis[tmp] = 1;
		bt(pos+1, n, P);
		vis[tmp] = 0;
		crr.pop_back();
	}
}

void solve(int N) {
	long long sum = 0;
	vector<int> P(N);
	iota(P.begin(), P.end(), 1);
	shuffle(P.begin(), P.end(), rng);
	for(int i = 1; i <= N; i++){
		D[i] = query(P);
		sum += D[i];
		P.push_back(P[0]);
		P.erase(P.begin());
	}
	sum /= N-1;
	for(int i = 1; i <= N; i++){
		D[i] = sum - D[i];
		// cout << D[i] << endl;
	}
	allans.clear();

	for(int i = 1; i <= N; i++){
		crr.push_back(i);
		vis[i] = 1;
		bt(2, N, P);
		vis[i] = 0;
		crr.pop_back();
	}
	while(allans.size() > 2){
		shuffle(P.begin(), P.end(), rng);
		vector<vector<int>> nw;
		int chksum = query(P);
		for(auto vec: allans){
			int csum = 0;
			for(int i = 1; i < N; i++)csum += abs(vec[P[i]-1] - vec[P[i-1]-1]);
			if(csum == chksum)nw.push_back(vec);
		}
		allans = nw;
	}
	answer(allans.back());

}

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 8 ms 444 KB Output is correct
18 Correct 24 ms 448 KB Output is correct
19 Correct 4 ms 444 KB Output is correct
20 Correct 703 ms 444 KB Output is correct
21 Correct 230 ms 604 KB Output is correct
22 Correct 14 ms 600 KB Output is correct
23 Correct 83 ms 456 KB Output is correct
24 Execution timed out 5017 ms 432 KB Time limit exceeded
25 Halted 0 ms 0 KB -