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 <bits/stdc++.h>
#include "prison.h"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
const int N = 2e5 + 5;
vector <vi> ans;
/*
when we go into node p,the previous number was in the range [L,R],
and (dep,id) represents the next node that we will travel to if our number is in [l,r].
Thus for [L,l],[R,r] we can already decide the answer, otherwise we need to keep moving.
*/
void work(int p,int dep,int id,int L,int R,int l,int r){
int u = 3 * dep + id;
rep(i,l,r)ans[p][i] = u;
rep(i,L,l)ans[u][i] = -1 - ans[u][0];
rep(i,r,R)ans[u][i] = -2 + ans[u][0];
l++,r--;
if(r < l)return;
if(r - l < 2){
work(u,dep + 1,1,l - 1,r + 1,l,r);
return;
}
if(r - l < 4){
work(u,dep + 1,1,l - 1,r + 1,l,(l + r) / 2);
work(u,dep + 1,2,l - 1,r + 1,(l + r) / 2 + 1,r);
return;
}
int m1 = (l + l + r) / 3,m2 = (l + r + r) / 3;
l--,r++;
work(u,dep + 1,1,l,r,l,m1);
work(u,dep + 1,2,l,r,m1 + 1,m2);
work(u,dep + 1,3,l,r,m2 + 1,r);
}
vector <vi> devise_strategy(int n){
rep(i,0,20){
ans.pb(vi(n + 1,0));
if((i + 2) % 6 < 3)ans[i][0] = 1;
}
work(0,-1,3,1,n,1,n);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |