Submission #239393

# Submission time Handle Problem Language Result Execution time Memory
239393 2020-06-15T13:19:40 Z Sorting Secret Permutation (RMI19_permutation) C++14
50 / 100
5000 ms 632 KB
#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);

    random_shuffle(v.begin(), v.end());

    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;
    }
}

Compilation message

permutation.cpp: In function 'void recursion(const std::vector<int>&, const std::vector<int>&, std::vector<int>&, std::vector<int>&, int)':
permutation.cpp:12:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(pos == v.size() - 1){
        ~~~~^~~~~~~~~~~~~~~
permutation.cpp:15:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < v.size(); ++i)
                            ~~^~~~~~~~~~
permutation.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(choice1 <= v.size() && !vis[choice1]){
        ~~~~~~~~^~~~~~~~~~~
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 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 306 ms 384 KB Output is correct
18 Correct 35 ms 376 KB Output is correct
19 Correct 218 ms 516 KB Output is correct
20 Correct 48 ms 384 KB Output is correct
21 Correct 24 ms 376 KB Output is correct
22 Correct 384 ms 632 KB Output is correct
23 Correct 42 ms 376 KB Output is correct
24 Execution timed out 5017 ms 504 KB Time limit exceeded
25 Halted 0 ms 0 KB -