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;
bool chk[101010];
bool chkc[101010];
int p[100];
int rev[101010];
int K = 2;
int M = 10;
void chkf(int x) {
while (1) {
if (chkc[x]) break;
chkc[x] = 1;
x = x / K + p[M - 1] * (x % K);
}
}
int cnt;
void f(int v) {
while (1) {
rev[cnt++] = v / p[M - 1];
chk[v] = 1;
int c = v % K;
int nv = v / K + p[M - 1] * ((c + 1) % K);
if (!chkc[nv]) {
chkf(nv);
f(nv);
}
nv = v / K + p[M - 1] * c;
if (chk[nv]) break;
v = nv;
}
}
map<vector<int>, int> mp;
std::vector<int> paint(int n) {
memset(chk, 0, sizeof(chk));
memset(chkc, 0, sizeof(chkc));
memset(p, 0, sizeof(p));
memset(rev, 0, sizeof(rev));
int i;
cnt = M - 1;
p[0] = 1;
for (i = 1; i < M; i++) p[i] = p[i - 1] * K;
chk[0] = chkc[0] = 1;
vector<int> v;
f(0);
assert(rev[112] && rev[113]);
for (i = n; i <= 2000; i++) rev[i] = -1;
for (i = 0; i < n; i++) v.push_back(rev[i]);
for (auto x : v) assert(x >= 0);
auto cpy = v;
v.push_back(10);
mp.clear();
for (i = 0; i < 10; i++) cpy.push_back(-1);
for (i = 0; i < n; i++) {
vector<int> nv;
int j;
for (j = 0; j < 10; j++) nv.push_back(cpy[i + j]);
mp[nv] = i;
}
return v;
}
int find_location(int n, std::vector<int> c) {
int i, j;
for (i = 0; i < c.size(); i++) if (c[i] == -1) return n - i;
return mp[c];
for (i = 0; i < n + 20; i++) {
int chk = 1;
for (j = 0; j < 10; j++) {
if (rev[i + j] != c[j]) {
chk = 0;
break;
}
}
if (chk) return i;
}
//assert(0);
return 0;
}
Compilation message (stderr)
squares.cpp: In function 'int find_location(int, std::vector<int>)':
squares.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (i = 0; i < c.size(); i++) if (c[i] == -1) return n - i;
| ~~^~~~~~~~~~
# | 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... |