Submission #722289

# Submission time Handle Problem Language Result Execution time Memory
722289 2023-04-11T17:16:13 Z tvladm2009 Secret Permutation (RMI19_permutation) C++17
100 / 100
1859 ms 332 KB
#include <bits/stdc++.h>
#include "permutation.h"

using namespace std;

typedef long long ll;

const int N_MAX = 256;

///mt19937 rnd(time(0));

vector <int> sol, questions;
bool used[N_MAX + 2];

bool found = 0;

void dfs(int pos, int N) {
    if (pos == N - 1) {
        if (abs(sol[0] - sol[pos]) == questions[pos]) {
            found = 1;
        }
        return;
    }
    int next = sol[pos] - questions[pos];
    if (1 <= next && next <= N && !used[next]) {
        sol.push_back(next);
        used[next] = 1;
        dfs(pos + 1, N);
        if (found == 1) {
            return;
        }
        used[next] = 0;
        sol.pop_back();
    }
    next = sol[pos] + questions[pos];
    if (1 <= next && next <= N && !used[next]) {
        sol.push_back(next);
        used[next] = 1;
        dfs(pos + 1, N);
        if (found == 1) {
            return;
        }
        used[next] = 0;
        sol.pop_back();
    }
}

void solve(int N) {
    vector <int> V;
    for (int i = 1; i <= N; i++) {
        V.push_back(i);
    }
    srand(257);
    random_shuffle(V.begin(), V.end());
    vector <int> C = V;
    questions.clear();
    for (int i = 1; i <= N; i++) {
        rotate(V.begin(), V.begin() + 1, V.end());
        questions.push_back(query(V));
    }
    int sum = 0;
    for (int it : questions) {
        sum += it;
    }
    sum /= N - 1;
    for (int &it : questions) {
        it = sum - it;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            used[j] = 0;
        }
        sol.clear();
        sol.push_back(i);
        used[i] = 1;
        found = 0;
        dfs(0, N);
        if (found == 1) {
            vector <int> ret(N);
            for (int j = 0; j < N; j++) {
                ret[C[j] - 1] = sol[j];
            }
            answer(ret);
            return;
        }
    }
}

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 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 18 ms 284 KB Output is correct
18 Correct 13 ms 280 KB Output is correct
19 Correct 160 ms 284 KB Output is correct
20 Correct 1318 ms 284 KB Output is correct
21 Correct 10 ms 328 KB Output is correct
22 Correct 65 ms 288 KB Output is correct
23 Correct 113 ms 288 KB Output is correct
24 Correct 1859 ms 332 KB Output is correct
25 Correct 22 ms 296 KB Output is correct
26 Correct 47 ms 288 KB Output is correct