Submission #1195154

#TimeUsernameProblemLanguageResultExecution timeMemory
1195154madamadam3Sorting (IOI15_sorting)C++20
8 / 100
344 ms589824 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int i = a; i < b; i++) #define each(a, x) for (auto &x : a) #define srt(x) sort(all(x)) #define sz(x) (int) (x).size() #define pb push_back #define trace(x) for (auto &el : x) cout << el << " " using pi = pair<int, int>; using vi = vector<int>; using vpi = vector<pi>; struct State { vi cur; int turn; vpi steps; }; bool is_sorted(vi inp) { int n = sz(inp); vi to_srt = vi(all(inp)); srt(to_srt); FOR(i, 0, n) { if (inp[i] != to_srt[i]) return false; } return true; } /* N = length of seq S = initial seq M = swaps by ermek X[i], Y[i] = ith swap of ermek P[i], Q[i] = swaps player makes function returns R (number of swaps) */ int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int n = N; vi initial; FOR(i, 0, n) initial.pb(S[i]); queue<State> q; q.push(State{initial, 0, {}}); State best; while (!q.empty()) { auto cur = q.front(); q.pop(); if (is_sorted(cur.cur)) { best = cur; break; } vi narr = vi(all(cur.cur)); swap(narr[X[cur.turn]], narr[Y[cur.turn]]); FOR(i, 0, n) { FOR(j, i + 1, n) { vi nnarr = vi(all(narr)); swap(nnarr[i], nnarr[j]); vpi nsteps = vpi(all(cur.steps)); nsteps.pb({i, j}); q.push(State {nnarr, cur.turn + 1, nsteps}); } } } int R = sz(best.steps); FOR(i, 0, R) { P[i] = best.steps[i].first; Q[i] = best.steps[i].second; } // trace(best.cur); cout << "\n"; return R; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...