Submission #259615

#TimeUsernameProblemLanguageResultExecution timeMemory
259615tqbfjotldSecret Permutation (RMI19_permutation)C++14
3 / 100
3807 ms384 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...