Submission #1072828

#TimeUsernameProblemLanguageResultExecution timeMemory
1072828kunzaZa183Fibonacci representations (CEOI18_fib)C++17
0 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; void add(set<int> &si, int x) { queue<int> qi; qi.push(x); while(!qi.empty()) { int tmp = qi.front(); qi.pop(); if(si.count(tmp)) { si.erase(tmp); if(tmp==1) { qi.push(2); } else if(tmp==2) { qi.push(1); qi.push(3); } else { qi.push(tmp-2); qi.push(tmp + 1); } continue; } else if(si.count(tmp + 1)) { si.erase(tmp + 1); qi.push(tmp + 2); } else if(si.count(tmp - 1)) { si.erase(tmp - 1); qi.push(tmp + 1); } else { si.insert(tmp); } } } const int mod = 1e9+7; map<set<int>,int> msii[101]; int state(set<int> vi, int cur) { if(vi.empty()) return 1; int x = *vi.rbegin(); if(msii[cur].count(vi)) return msii[cur][vi]; int total = 0; vi.erase(x); if( x <=cur) { total += state(vi,x - 1); } if(x - 1<=cur && x>2) { add(vi, x - 2); total += state(vi,x - 2); } vi.insert(x); msii[cur][vi] = total%mod; // if(x==2 && cur==4) { // cout<<"TOTAL = "<<total<<'\n'; // } return total % mod; } int main() { int n; cin>>n; vector<int> vi(n); for(auto &a:vi) cin>>a; set<int> cur; for(auto a:vi) { add(cur,a); // cout<<"CUR\n"; // for(auto a:cur) // cout<<a<<' '; // cout<<"\n"; cout<<state(cur, 100)<<"\n"; } set<int> si; si.insert(2); cout<<msii[4][si]<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...