This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2e3 + 9;
const ll mod = 1e9 + 7;
vector<ll> g[N];
deque<ll> ans;
ll b[N],pow2[N],p1,p2;
void process(){
p1 = p2 = 0;
for (ll i = 0;i < 9;i++) p1 += pow2[9 - i - 1]*b[i];
for (ll i = 1;i <= 9;i++) p2 += pow2[9 - i]*b[i];
g[p1].push_back(p2);
}
void f(ll i){
if (i > 9){
process(); return;
}
b[i] = 1; f(i + 1);
b[i] = 0; f(i + 1);
}
void dfs(ll u){
while(g[u].size()){
ll v = g[u].back(); g[u].pop_back();
dfs(v);
}
ans.push_back(u%2);
}
void Init(ll n){
pow2[0] = 1;
for (ll i = 1;i <= 10;i++) pow2[i] = pow2[i - 1]*2; f(0);
dfs(0); reverse(ans.begin(),ans.end());
for (ll i = 0;i < 8;i++) ans.push_front(0);
while(ans.size() > n) ans.pop_back();
}
vector<int> paint(int n) {
if (ans.empty()) Init(n);
vector<int> a(n + 1);
a[n] = 10;
for (int i = 0; i < n; i++) a[i] = ans[i];
return a;
}
vector<int> now;
int find_location(int n, vector<int> c) {
if (ans.empty()) Init(n);
/*for (int i = 0; i < 10; i++) cout << c[i] <<" ";cout << endl;
for (int i = 0; i < 10; i++) cout << need[i] <<" ";cout << endl;*/
for (int i = 0; i < n; i++) {
now.clear();
for (int j = 0; j < 10; j++) {
if (i + j >= n) now.push_back(-1);
else now.push_back(ans[i + j]);
}
if (now == c) return i;
}
assert(false);
}
/*
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n; paint(n); /// 00000000001000000001
v.push_back(0); v.push_back(1);
while(v.size() < 10) v.push_back(-1);
cout<<find_location(n,v);
}
*/
Compilation message (stderr)
squares.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
squares.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
squares.cpp: In function 'void Init(int)':
squares.cpp:44:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
44 | for (ll i = 1;i <= 10;i++) pow2[i] = pow2[i - 1]*2; f(0);
| ^~~
squares.cpp:44:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
44 | for (ll i = 1;i <= 10;i++) pow2[i] = pow2[i - 1]*2; f(0);
| ^
squares.cpp:47:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(ans.size() > n) ans.pop_back();
| ~~~~~~~~~~~^~~
# | 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... |