답안 #259561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259561 2020-08-08T02:32:48 Z dantoh000 Secret Permutation (RMI19_permutation) C++14
90 / 100
1617 ms 408 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> q;
    for (int i = 1; i <= n; i++){
        q.push_back(i);
    }
    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 pos[n+1];
            for (int i = 0; i < n; i++){
                pos[P[i]] = i+1;
            }
            q.clear();
            for (int i = 1; i <= n; i++){
                q.push_back(pos[i]);
            }
            if (Query(q) != n-1){
                reverse(P,P+n);
            }
            answer(P);
            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);
   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 0 ms 256 KB Partially correct
4 Partially correct 0 ms 256 KB Partially correct
5 Partially correct 0 ms 256 KB Partially correct
6 Partially correct 0 ms 256 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 0 ms 256 KB Partially correct
4 Partially correct 0 ms 256 KB Partially correct
5 Partially correct 0 ms 256 KB Partially correct
6 Partially correct 0 ms 256 KB Partially correct
7 Partially correct 1 ms 256 KB Partially correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 1 ms 256 KB Partially correct
10 Partially correct 1 ms 256 KB Partially correct
11 Partially correct 1 ms 256 KB Partially correct
12 Partially correct 1 ms 256 KB Partially correct
13 Partially correct 1 ms 256 KB Partially correct
14 Partially correct 3 ms 256 KB Partially correct
15 Partially correct 1 ms 256 KB Partially correct
16 Partially correct 1 ms 256 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 0 ms 256 KB Partially correct
4 Partially correct 0 ms 256 KB Partially correct
5 Partially correct 0 ms 256 KB Partially correct
6 Partially correct 0 ms 256 KB Partially correct
7 Partially correct 1 ms 256 KB Partially correct
8 Partially correct 1 ms 256 KB Partially correct
9 Partially correct 1 ms 256 KB Partially correct
10 Partially correct 1 ms 256 KB Partially correct
11 Partially correct 1 ms 256 KB Partially correct
12 Partially correct 1 ms 256 KB Partially correct
13 Partially correct 1 ms 256 KB Partially correct
14 Partially correct 3 ms 256 KB Partially correct
15 Partially correct 1 ms 256 KB Partially correct
16 Partially correct 1 ms 256 KB Partially correct
17 Partially correct 9 ms 376 KB Partially correct
18 Partially correct 26 ms 376 KB Partially correct
19 Partially correct 30 ms 376 KB Partially correct
20 Partially correct 12 ms 384 KB Partially correct
21 Partially correct 93 ms 372 KB Partially correct
22 Partially correct 81 ms 408 KB Partially correct
23 Partially correct 13 ms 256 KB Partially correct
24 Partially correct 1617 ms 376 KB Partially correct
25 Partially correct 98 ms 256 KB Partially correct
26 Partially correct 8 ms 376 KB Partially correct