# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
674442 | 2022-12-24T08:59:08 Z | QwertyPi | Mouse (info1cup19_mouse) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define TEST #ifndef TEST #include "grader.h" int query(vector<int> q); #else vector<int> p; int qc = 0; int query(vector<int> q){ qc++; int cnt = 0; int n = p.size(); for(int i = 0; i < n; i++){ if(p[i] == q[i]) cnt++; } return cnt; } #endif void solve(int N){ vector<int> a; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); for(int i = 1; i <= N; i++){ a.push_back(i); } for(int i = 0; i < N; i++){ swap(a[i], a[rng() % (i + 1)]); } int qry = 0; while(qry != N){ int i = 0, j = 0; while(i == j) i = rng() % N, j = rng() % N; swap(a[i], a[j]); int new_qry = query(a); if(new_qry < qry) swap(a[i], a[j]); else qry = new_qry; } } #ifdef TEST int main(){ int N; cin >> N; p.resize(N); for(int i = 0; i < N; i++) cin >> p[i]; solve(N); cout << qc << endl; } #endif