Submission #856940

# Submission time Handle Problem Language Result Execution time Memory
856940 2023-10-04T23:27:12 Z mihajanez Prisoner Challenge (IOI22_prison) C++17
100 / 100
8 ms 1116 KB
#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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 8 ms 856 KB Output is correct
6 Correct 8 ms 1112 KB Output is correct
7 Correct 8 ms 1116 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 7 ms 860 KB Output is correct