제출 #430801

#제출 시각아이디문제언어결과실행 시간메모리
430801cfalasPainting Squares (IOI20_squares)C++14
0 / 100
3433 ms57028 KiB
#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[n].size()) ans.clear(), rec(t), mem[n] = ans; ans = mem[n]; //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<(int)ans.size()){ assert(ind<=n); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...