Submission #842623

#TimeUsernameProblemLanguageResultExecution timeMemory
842623WLZChoreography (IOI23_choreography)C++17
100 / 100
97 ms9300 KiB
#include "choreography.h" #include <bits/stdc++.h> using namespace std; int n, cur; vector< vector<int> > p, shift_p, add_p; vector<int> add; void init(int N, std::vector<int> P) { n = N; cur = 0; p = {P, vector<int>(n)}; add = {0, 0}; add_p = shift_p = {{0, 0}, {0, 0}}; for (int i = 0; i < n; i++) p[1][p[0][i]] = i; return; } void move_right(int K) { if (shift_p[cur][0] % 2 == 0) { shift_p[cur][0] = (shift_p[cur][0] + K) % n; shift_p[cur][1] = (shift_p[cur][1] + K) % n; } else { int a = shift_p[cur][0], b = shift_p[cur][1]; shift_p[cur][0] = (a + K) % n; shift_p[cur][1] = (b + K) % n; } //shift[cur] = (shift[cur] + K) % n; add[!cur] = (add[!cur] + K) % n; return; } void move_left(int K) { if (shift_p[cur][0] % 2 == 0) { shift_p[cur][0] = ((shift_p[cur][0] - K) % n + n) % n; shift_p[cur][1] = ((shift_p[cur][1] - K) % n + n) % n; } else { int a = shift_p[cur][0], b = shift_p[cur][1]; shift_p[cur][0] = ((a - K) % n + n) % n; shift_p[cur][1] = ((b - K) % n + n) % n; } add[!cur] = ((add[!cur] - K) % n + n) % n; return; } void swap_places() { //int x = (shift_p[cur][0]) % n; if (shift_p[cur][0] % 2 == 0) { int a = shift_p[cur][0], b = shift_p[cur][1]; shift_p[cur][0] = ((a + 1) % n + n) % n; shift_p[cur][1] = ((b - 1) % n + n) % n; } else { int a = shift_p[cur][0], b = shift_p[cur][1]; shift_p[cur][0] = ((a - 1) % n + n) % n; shift_p[cur][1] = ((b + 1) % n + n) % n; } //if (shift_p[cur][0] % 2 == 0) { //shift_p[cur][0] = (shift_p[cur][0] + 1) % n; //shift_p[cur][1] = ((shift_p[cur][1] - 1) % n + n) % n; //} else { //shift_p[cur][1] = (shift_p[cur][1] + 1) % n; //shift_p[cur][0] = ((shift_p[cur][0] - 1) % n + n) % n; //} int x = (add_p[!cur][0] + add[!cur]) % n; if (x % 2 == 0) { add_p[!cur][0] = (add_p[!cur][0] + 1) % n; add_p[!cur][1] = ((add_p[!cur][1] - 1) % n + n) % n; } else { add_p[!cur][1] = (add_p[!cur][1] + 1) % n; add_p[!cur][0] = ((add_p[!cur][0] - 1) % n + n) % n; } return; } void move_around() { cur = !cur; return; } int get_position(int i) { if ((shift_p[!cur][i % 2]) % 2 == 0) { i = ((i - shift_p[!cur][i % 2]) % n + n) % n; // i = ((i - shift[!cur]) % n + n) % n; } else { i = ((i - shift_p[!cur][1 - (i % 2)]) % n + n) % n; //i = ((i - shift[!cur]) % n + n) % n; } int ans = p[!cur][i]; ans = (ans + add_p[!cur][ans % 2]) % n; ans = (ans + add[!cur]) % n; return ans; }
#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...