Submission #238898

# Submission time Handle Problem Language Result Execution time Memory
238898 2020-06-13T12:14:47 Z Sorting Secret Permutation (RMI19_permutation) C++14
53.1429 / 100
42 ms 384 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 solve(int n){
    vector<int> v;
    for(int i = 1; i <= n; ++i)
        v.push_back(i);

    int best_diff = 0, best_idx = 1;
    for(int i = 2; i < n; ++i){
        swap(v[i], v[n - 1]);
        int curr = query(v);
        reverse(v.begin() + 1, v.end());
        int after = query(v);
        reverse(v.begin() + 1, v.end());
        swap(v[i], v[n - 1]);

        int curr_diff = after - curr;
        if(curr_diff > best_diff){
            best_diff = curr_diff;
            best_idx = i;
        }
    }

    int best_val = best_idx + 1;

    swap(v[best_idx], v[0]);
    vector<int> diff(n);
    diff[1] = 0;
    for(int i = 2; i < n; ++i){
        swap(v[i], v[n - 1]);
        int curr = query(v);
        reverse(v.begin() + 1, v.end());;
        int after = query(v);
        reverse(v.begin() + 1, v.end());
        swap(v[i], v[n - 1]);

        diff[i] = after - curr;
    }

    int min_diff = 100000;
    for(int i = 1; i < n; ++i)
        min_diff = min(diff[i], min_diff);

    for(int i = 1; i < n; ++i){
        diff[i] -= min_diff;
        diff[i] += 2;
    }
    diff[0] = 1;
    swap(diff[best_idx], diff[0]);

    answer(diff);
}
/*
8
4 7 1 2 3 6 8 5
*/

Compilation message

permutation.cpp: In function 'void solve(int)':
permutation.cpp:32:9: warning: unused variable 'best_val' [-Wunused-variable]
     int best_val = best_idx + 1;
         ^~~~~~~~
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 Partially correct 5 ms 256 KB Partially correct
2 Partially correct 4 ms 384 KB Partially correct
3 Partially correct 5 ms 384 KB Partially correct
4 Partially correct 5 ms 256 KB Partially correct
5 Partially correct 5 ms 256 KB Partially correct
6 Partially correct 5 ms 256 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 256 KB Partially correct
2 Partially correct 4 ms 384 KB Partially correct
3 Partially correct 5 ms 384 KB Partially correct
4 Partially correct 5 ms 256 KB Partially correct
5 Partially correct 5 ms 256 KB Partially correct
6 Partially correct 5 ms 256 KB Partially correct
7 Partially correct 7 ms 360 KB Partially correct
8 Partially correct 8 ms 384 KB Partially correct
9 Partially correct 7 ms 256 KB Partially correct
10 Partially correct 7 ms 384 KB Partially correct
11 Partially correct 7 ms 256 KB Partially correct
12 Partially correct 8 ms 256 KB Partially correct
13 Partially correct 7 ms 384 KB Partially correct
14 Partially correct 8 ms 256 KB Partially correct
15 Partially correct 7 ms 256 KB Partially correct
16 Partially correct 7 ms 256 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 256 KB Partially correct
2 Partially correct 4 ms 384 KB Partially correct
3 Partially correct 5 ms 384 KB Partially correct
4 Partially correct 5 ms 256 KB Partially correct
5 Partially correct 5 ms 256 KB Partially correct
6 Partially correct 5 ms 256 KB Partially correct
7 Partially correct 7 ms 360 KB Partially correct
8 Partially correct 8 ms 384 KB Partially correct
9 Partially correct 7 ms 256 KB Partially correct
10 Partially correct 7 ms 384 KB Partially correct
11 Partially correct 7 ms 256 KB Partially correct
12 Partially correct 8 ms 256 KB Partially correct
13 Partially correct 7 ms 384 KB Partially correct
14 Partially correct 8 ms 256 KB Partially correct
15 Partially correct 7 ms 256 KB Partially correct
16 Partially correct 7 ms 256 KB Partially correct
17 Partially correct 39 ms 256 KB Partially correct
18 Partially correct 34 ms 256 KB Partially correct
19 Partially correct 42 ms 256 KB Partially correct
20 Partially correct 38 ms 256 KB Partially correct
21 Partially correct 33 ms 256 KB Partially correct
22 Partially correct 33 ms 256 KB Partially correct
23 Partially correct 36 ms 256 KB Partially correct
24 Partially correct 38 ms 384 KB Partially correct
25 Partially correct 33 ms 384 KB Partially correct
26 Partially correct 41 ms 384 KB Partially correct