이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define FORi(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define FOR(i,n) FORi(i,0,n)
#define FOA(v, a) for(auto v : a)
#define ll long long
#define F first
#define S second
typedef pair<int, int> ii;
#include "squares.h"
int ss = 0;
int n;
int bcnt(int x){
int cnt=0;
while(x) cnt++, x/=2;
return cnt;
}
vector<int> mem[2000];
vector<int> ans;
void rec(vector<int> x){
//cout<<"x "<<x<<endl;
if((int)x.size()==n){ ans=x; return; }
// slide da windo
set<int> all;
int i=0;
int c=0;
int ind=-ss+1;
while(i<(int)x.size()){
c = c*2 % (1<<ss);
//cout<<"( "<<c<<" ";
if(x[i]) c++;
//cout<<c<<") ";
if(ind>=0) all.insert(c);
ind++;
i++;
}
//cout<<"all ";FOA(v, all) cout<<v<<" ";
//cout<<endl;
int next = c*2 % (1<<ss);
x.push_back(0);
if(!all.count(next)) rec(x);
if(ans.size()) return;
x.back() = 1;
if(!all.count(next+1)) rec(x);
}
vector<int> paint(int N) {
n = N;
ans.clear();
ss = bcnt(n);
//cout<<"ss "<<ss<<endl;
vector<int> t(ss, 0);
rec(t);
//FOA(v,ans) cout<<v<<" ";
//cout<<endl;
ans.push_back(ss);
return ans;
}
int find_location(int n, std::vector<int> f) {
ss = bcnt(n);
//cout<<"finding "<<endl;
vector<int> t(bcnt(n), 0);
if(!mem[ss].size()) rec(t), mem[ss] = ans;
ans = mem[ss];
//cout<<endl;
int x =0;
int ind=0;
FOA(v,f){
x*=2;
x+=v;
if(v==-1) return n-ind;
ind++;
}
//cout<<"target "<<x<<endl;
int i=0;
int c=0;
ind=-ss+1;
while(i>=0){
c = c*2 % (1<<ss);
//cout<<"( "<<c<<" ";
if(ans[i]) c++;
//cout<<c<<") ";
//cout<<ind<<" "<<c<<" "<<x<<endl;
if(ind>=0 && x==c) return ind;
ind++;
i++;
}
//cout<<endl;
return -1;
}
# | 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... |