Submission #259615

# Submission time Handle Problem Language Result Execution time Memory
259615 2020-08-08T04:23:41 Z tqbfjotld Secret Permutation (RMI19_permutation) C++14
3 / 100
3807 ms 384 KB
#include "permutation.h"
#include <bits/stdc++.h>
using namespace std;

int arr[300];
int n;
vector<int> inv(){
    vector<int> ans;
    for (int x = 0; x<n; x++){
        ans.push_back(0);
    }
    for (int x = 1; x<=n; x++){
        ans[arr[x]-1] = x;
    }
    return ans;
}

void solve(int N) {
    n = N;
    for (int x = 1; x<=n; x++){
        arr[x] = x;
    }
    while (true){
        if (query(inv())==n-1){
            vector<int> ans;
            for (int x = 1; x<=n; x++){
                ans.push_back(arr[x]);
            }
            answer(ans);
            break;
        }
        pair<int,int> best = {-1,-1};
        int bestv = 999999999;
        vector<pair<int,pair<int,int> > >rem;
        for (int x = 1; x<=n; x++){
            for (int y = x+1; y<=n; y++){
                rem.push_back({rand(),{x,y}});
            }
        }
        sort(rem.begin(),rem.end());
        int threshold = n*n;
        for (int x = 0; x<min(threshold,(int)rem.size()); x++){
            swap(arr[rem[x].second.first],arr[rem[x].second.second]);
            int t = query(inv());
            if (t<bestv){
                best = rem[x].second;
                bestv = t;
            }
            swap(arr[rem[x].second.first],arr[rem[x].second.second]);
        }
        swap(arr[best.first],arr[best.second]);
    }
}

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 Partially correct 2 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
7 Execution timed out 3807 ms 384 KB Time limit exceeded (wall clock)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 256 KB Partially correct
2 Partially correct 0 ms 256 KB Partially correct
3 Partially correct 1 ms 256 KB Partially correct
4 Partially correct 2 ms 256 KB Partially correct
5 Partially correct 1 ms 256 KB Partially correct
6 Partially correct 1 ms 256 KB Partially correct
7 Execution timed out 3807 ms 384 KB Time limit exceeded (wall clock)
8 Halted 0 ms 0 KB -