# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307248 | tincamatei | Painting Squares (IOI20_squares) | C++14 | 139 ms | 996 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "squares.h"
#include <vector>
#include <algorithm>
#include <cstdio>
struct Edge {
int b, c;
bool marked;
};
std::vector<Edge> debrujin[1<<9];
std::vector<int> magic;
void euler(int nod) {
int i = 0;
while(i < debrujin[nod].size()) {
while(i < debrujin[nod].size() && debrujin[nod][i].marked)
++i;
if(i < debrujin[nod].size()) {
debrujin[nod][i].marked = true;
euler(debrujin[nod][i].b);
magic.push_back(debrujin[nod][i].c);
}
}
}
std::vector<int> paint(int n) {
std::vector<int> labels(n + 1, 1);
int k = 10;
for(int i = 0; i < (1 << (k - 1)); ++i) {
debrujin[i].push_back({(i << 1) & ((1 << (k - 1)) - 1), 0, false});
debrujin[i].push_back({((i << 1) | 1) & ((1 << (k - 1)) - 1), 1, false});
}
euler(0);
for(int i = 0; i < k - 1; ++i)
magic.push_back(0);
std::reverse(magic.begin(), magic.end());
for(int i = 0; i < n; ++i)
labels[i] = magic[i];
labels[n] = k;
return labels;
}
bool built = false;
int table[1<<10];
int find_location(int n, std::vector<int> c) {
int k = 10;
if(!built) {
built = true;
std::vector<int> labels = paint(n);
for(int i = 0; i + k - 1 < magic.size(); ++i) {
int val = 0;
for(int j = 0; j < k; ++j)
val = val * 2 + magic[i + j];
table[val] = i;
}
}
int i = 0, val = 0;
while(i < k && c[i] != -1) {
val = val * 2 + c[i];
++i;
}
if(i < k)
return n - i;
return table[val];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |