Submission #238896

#TimeUsernameProblemLanguageResultExecution timeMemory
238896SortingSecret Permutation (RMI19_permutation)C++14
0 / 100
5 ms384 KiB
#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); swap(v[1], v[n - 1]); int after = query(v); swap(v[1], v[n - 1]); 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; //cout << best_idx << " best_idx" << endl; 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); swap(v[1], v[n - 1]); int after = query(v); swap(v[1], v[n - 1]); 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); }

Compilation message (stderr)

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