Submission #856940

#TimeUsernameProblemLanguageResultExecution timeMemory
856940mihajanezPrisoner Challenge (IOI22_prison)C++17
100 / 100
8 ms1116 KiB
#include <bits/stdc++.h> #include <vector> #include <math.h> using namespace std; vector<vector<int>> devise_strategy(int N) { vector<vector<int>> strategy; vector<int> partCurrent(N + 1, 0); signed char bag = 0; signed char x = 0; signed char maxX = 0; signed char nextX = 0; strategy.reserve(static_cast<unsigned long long>(3) * (unsigned long long)ceil(log(N) / log(3)) * (static_cast<unsigned long long>(N) + 1)); while (x <= maxX) { bag = (x / 3 + (x % 3 != 0)) % 2; if (bag != partCurrent[0]) { nextX = maxX; } partCurrent[0] = bag; vector<int> partX; vector<int>::iterator itBegin = partCurrent.begin(); vector<int>::iterator itEnd = partCurrent.end(); signed char chooseThis = -(*itBegin) - 1; signed char chooseOther = (chooseThis % 2) - 1; signed char maxX1 = nextX; partX.reserve(partCurrent.capacity()); partX.push_back(*itBegin++); while (itBegin != itEnd) { while (itBegin != itEnd && *itBegin != x) { partX.push_back(chooseThis); itBegin++; } vector<int>::iterator itX = itBegin; int partLen = 0; while (itBegin != itEnd && *itBegin == x) { partLen++; itBegin++; } if (partLen > 0) { partX.push_back(chooseThis); *itX++ = -3; if (partLen >= 2) { partLen -= 2; if (partLen == 1) { partX.push_back(nextX + 1); *itX++ = nextX + 1; } else if (partLen == 2) { partX.push_back(nextX + 1); *itX++ = nextX + 1; partX.push_back(nextX + 1); *itX++ = nextX + 1; } else if (partLen == 3) { partX.push_back(nextX + 1); *itX++ = nextX + 1; partX.push_back(nextX + 1); *itX++ = nextX + 1; partX.push_back(nextX + 2); *itX++ = nextX + 2; } else if (partLen > 3) { int newPartLen = partLen / 3 + (partLen % 3 != 0); for (int i = 0; i < newPartLen; i++) { partX.push_back(nextX + 1); *itX++ = nextX + 1; } for (int i = 0; i < newPartLen; i++) { partX.push_back(nextX + 2); *itX++ = nextX + 2; } for (int i = 0; i < partLen - 2 * newPartLen; i++) { partX.push_back(nextX + 3); *itX++ = nextX + 3; } } if (maxX1 < partX.back()) { maxX1 = partX.back(); } partX.push_back(chooseOther); *itX = chooseOther; } } while (itBegin != itEnd && *itBegin != -3) { partX.push_back(chooseOther); itBegin++; } } strategy.push_back(partX); if (maxX < maxX1) { maxX = maxX1; } x++; } return strategy; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...