# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
239394 | Sorting | Secret Permutation (RMI19_permutation) | C++14 | 2589 ms | 544 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "permutationc.h"
using namespace std;
int query(int v[]);
int query(vector<int> v);
void answer(int v[]);
void answer(vector<int> v);
void recursion(const vector<int> &v, const vector<int> &arr, vector<int> &ans, vector<int> &vis, int pos){
if(pos == v.size() - 1){
if(abs(ans[0] - ans[v.size() - 1]) == arr[pos]){
vector<int> x(v.size());
for(int i = 0; i < v.size(); ++i)
x[v[i] - 1] = ans[i];
answer(x);
exit(0);
}
return;
}
int choice1 = ans[pos] + arr[pos];
int choice2 = ans[pos] - arr[pos];
if(choice1 <= v.size() && !vis[choice1]){
ans[pos + 1] = choice1;
vis[choice1] = true;
recursion(v, arr, ans, vis, pos + 1);
ans[pos + 1] = 0;
vis[choice1] = false;
}
if(choice2 >= 1 && !vis[choice2]){
ans[pos + 1] = choice2;
vis[choice2] = true;
recursion(v, arr, ans, vis, pos + 1);
ans[pos + 1] = 0;
vis[choice2] = false;
}
}
void solve(int n){
vector<int> v;
for(int i = 1; i <= n; ++i)
v.push_back(i);
mt19937 mt(7);
random_shuffle(v.begin(), v.end(), [&](int mod){return mt() % mod;});
vector<int> arr(n + 1);
for(int i = 0; i < n; ++i){
rotate(v.begin(), v.begin() + 1, v.end());
arr[i] = query(v);
}
int sum = 0;
for(int i = 0; i < n; ++i)
sum += arr[i];
sum /= n - 1;
for(int i = 0; i < n; ++i)
arr[i] = sum - arr[i];
//for(int i = 0; i < n; ++i)
// cout << arr[i] << " ";
//cout << endl;
vector<int> ans(n), vis(n + 1, false);
for(int i = 1; i <= n; ++i){
ans[0] = i;
vis[i] = true;
recursion(v, arr, ans, vis, 0);
ans[0] = 0;
vis[i] = false;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |