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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int INF = 2e9, N = 1005, M = 1e9+7, LOG = 16;
const ll LINF = 1e18;
string res[N];
map<string, bool> vis;
void dfs(string node, int d) {
for(int i = 0; i < 2; i++) {
string to = node + char('0' + i);
if(!vis[to]) {
vis[to] = true;
dfs(to.substr(1), d);
res[d] += to.back();
}
}
}
map<deque<int>, int> idx[N];
void deBruijn (int d) {
vis.clear();
res[d].clear();
string s = string(d-1, '0');
dfs(s, d);
res[d] += s;
}
vector<int> paint(int n) {
int len = min(10, n);
deBruijn(len);
vector<int> labels(n);
for(int i = 0; i < n; ++i)
labels[i] = res[len][i]-'0';
deque<int> cur (labels.begin(), labels.begin() + len);
for(int i = 0; i < n; i++) {
if(i+len < n) cur.push_back(labels[i+len]);
cur.pop_front();
idx[len][cur] = i+1;
}
labels.push_back(len);
return labels;
}
int find_location(int n, vector<int> c) {
while(c.back() == -1) c.pop_back();
return idx[min(10, n)][deque<int>(all(c))];
}
# | 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... |