Submission #259567

# Submission time Handle Problem Language Result Execution time Memory
259567 2020-08-08T02:42:18 Z dantoh000 Secret Permutation (RMI19_permutation) C++14
100 / 100
867 ms 376 KB
#include <bits/stdc++.h>
#include "permutationc.h"
using namespace std;

int n;
int Query(vector<int> q){
    int a[n];
    for (int i = 0; i < n; i++){
        a[i] = q[i];
    }
    return query(a);
}

int d[257];
int vis[257];
int P[257];
bool findperm(int id){
    if (id == n) return abs(P[n-1]-P[0]) == d[id];
    int last = P[id-1];
    int dif = d[id];
    //printf("%d: %d +- %d\n",id,last,dif);
    int cur = last+dif;
    if (cur >= 1 && cur <= n && !vis[cur]){
        P[id] = cur;
        vis[cur] = 1;
        if (findperm(id+1)) return true;
        vis[cur] = 0;
        P[id] = 0;
    }
    cur = last-dif;
    if (cur >= 1 && cur <= n && !vis[cur]){
        P[id] = cur;
        vis[cur] = 1;
        if (findperm(id+1)) return true;
        vis[cur] = 0;
        P[id] = 0;
    }
    return false;
}

void solve(int _N){
    n = _N;
    vector<int> _p;
    vector<int> q;
    for (int i = 1; i <= n; i++){
        q.push_back(i);
    }
    srand(1232323);
    random_shuffle(q.begin(),q.end());
    for (auto x : q) _p.push_back(x);
    d[n] = Query(q);
    for (int j = n-1; j >= 1; j--){
        q.insert(q.begin(),q.back());
        q.pop_back();
        d[j] = Query(q);
    }
    int sum = 0;
    for (int i = 1; i <= n; i++){
        sum += d[i];
    }
    assert(sum % (n-1) == 0);
    sum /= n-1;
    for (int i = 1; i <= n; i++){
        d[i] = sum-d[i];
        //printf("%d ",d[i]);
        //assert(d[i] == abs(ans[i-1]-ans[i%N]));
    }
    //printf("\n");
    for (int i = 1; i <= n; i++){
        vis[i] = 1;
        P[0] = i;
        if (findperm(1)){
            int ret[n+1];
            for (int i = 0; i < n; i++){
                ret[_p[i]-1] = P[i];
            }
            answer(ret);
            return;
        }
        vis[i] = 0;
    }
}

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]
   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]
   fscanf(stdin, "%d", &N);
   ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 867 ms 256 KB Output is correct
19 Correct 638 ms 376 KB Output is correct
20 Correct 105 ms 376 KB Output is correct
21 Correct 71 ms 376 KB Output is correct
22 Correct 35 ms 256 KB Output is correct
23 Correct 533 ms 376 KB Output is correct
24 Correct 17 ms 376 KB Output is correct
25 Correct 142 ms 376 KB Output is correct
26 Correct 43 ms 376 KB Output is correct