답안 #1054307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054307 2024-08-12T08:35:28 Z socpite Secret Permutation (RMI19_permutation) C++17
50 / 100
14 ms 600 KB
#include "permutation.h"
#include<bits/stdc++.h>
using namespace std;
 
const int maxn = 300;
 
namespace {
	long long D[maxn], DP[maxn];
	int p, n;
	bool vis[maxn];
	vector<int> crr;
	vector<vector<int>> allans;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	bool check(int val, int pos){
		if(vis[val] || val < 1 || val > n)return false;
		if((pos+p)%n < pos && abs(val - crr[(pos+p)%n]) != DP[(pos+p)%n])return false;
		if((pos+n-p)%n < pos && abs(val - crr[(pos+n-p)%n]) != DP[pos])return false;
		if(pos == n-1 && abs(crr[0] - val) != D[0])return false;
		return true;
	}
}
 
void bt(int pos){
	if(pos == n){
		allans.push_back(crr);
		return;
	}
	int tmp = crr.back() + D[pos]; 
	if(check(tmp, pos)){
		crr.push_back(tmp);
		vis[tmp] = 1;
		bt(pos+1);
		vis[tmp] = 0;
		crr.pop_back();
	}
	
	tmp = crr.back() - D[pos]; 
	if(check(tmp, pos)){
		crr.push_back(tmp);
		vis[tmp] = 1;
		bt(pos+1);
		vis[tmp] = 0;
		crr.pop_back();
	}
}
 
void solve(int N) {
	n = N;
	long long sum = 0;
	vector<int> P(N);
	for(int i = 2; i <= N; i++){
		if(__gcd(i, N) == 1){
			p = i;
			break;
		}
	}
	iota(P.begin(), P.end(), 1);
	for(int i = 0; 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 = 0; i < N; i++){
		D[i] = sum - D[i];
		// cout << D[i] << endl;
	}

	sum = 0;
	for(int i = 0; i < N; i++)P[i] = i*p%N  + 1;
	for(int i = 0; i < N; i++){
		DP[P[0]-1] = query(P);
		sum += DP[P[0]-1];
		P.push_back(P[0]);
		P.erase(P.begin());
	}
	sum/=N-1;
	for(int i = 0; i < N; i++){
		DP[i] = sum - DP[i];
	}
	allans.clear();
 
	for(int i = 1; i <= N; i++){
		crr.push_back(i);
		vis[i] = 1;
		bt(1);
		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);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 1 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 1 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 1 ms 344 KB Partially correct
8 Partially correct 1 ms 344 KB Partially correct
9 Partially correct 1 ms 344 KB Partially correct
10 Partially correct 1 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 2 ms 344 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 1 ms 344 KB Partially correct
16 Partially correct 2 ms 344 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 0 ms 344 KB Partially correct
3 Partially correct 0 ms 344 KB Partially correct
4 Partially correct 1 ms 344 KB Partially correct
5 Partially correct 0 ms 344 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 1 ms 344 KB Partially correct
8 Partially correct 1 ms 344 KB Partially correct
9 Partially correct 1 ms 344 KB Partially correct
10 Partially correct 1 ms 344 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 2 ms 344 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 1 ms 344 KB Partially correct
15 Partially correct 1 ms 344 KB Partially correct
16 Partially correct 2 ms 344 KB Partially correct
17 Partially correct 14 ms 444 KB Partially correct
18 Partially correct 7 ms 600 KB Partially correct
19 Partially correct 7 ms 344 KB Partially correct
20 Partially correct 10 ms 424 KB Partially correct
21 Partially correct 7 ms 344 KB Partially correct
22 Partially correct 6 ms 432 KB Partially correct
23 Partially correct 14 ms 344 KB Partially correct
24 Partially correct 8 ms 452 KB Partially correct
25 Partially correct 7 ms 344 KB Partially correct
26 Partially correct 8 ms 424 KB Partially correct