Submission #379416

#TimeUsernameProblemLanguageResultExecution timeMemory
379416fhvirusNice sequence (IZhO18_sequence)C++17
100 / 100
1384 ms34120 KiB
// Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define ff first #define ss second #define pb emplace_back #define FOR(i,n) for(int i=0;i<(n);++i) #define FOO(i,a,b) for(int i=(a);i<=int(b);++i) #define OOF(i,a,b) for(int i=(a);i>=int(b);--i) #define AI(x) begin(x),end(x) template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;} template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;} inline ll cdiv(ll x,ll m){return x/m+(x%m?(x<0)^(m>0):0);} #ifdef OWO #define safe cerr<<"\033[1;32m"<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<" JIZZ\033[0m\n" #define debug(args...) SDF(#args, args) #define OIU(args...) ostream& operator<<(ostream&O,args) #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss) template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';} template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} #else #pragma GCC optimize("Ofast") #define safe ((void)0) #define debug(...) ((void)0) #endif const ll inf = 1e9, INF = 4e18; bool check(int n, int m, int len, bool out = false){ vector<int> in(len + 1, 0); FOO(i,0,len){ if(i + n <= len) ++in[i + n]; if(i - m >= 0) ++in[i - m]; } vector<int> q; FOO(i,0,len) if(in[i] == 0) q.pb(i); if(q.empty()) return false; FOR(i,q.size()){ int u = q[i]; if(u + n <= len) if(--in[u + n] == 0) q.pb(u + n); if(u - m >= 0) if(--in[u - m] == 0) q.pb(u - m); } if(q.size() != len + 1) return false; if(!out) return true; vector<int> ans(len + 1); int val = len + 1; FOO(i,0,len){ int p = q[i]; ans[p] = --val; if(q[i] == 0) ans[p] = 0; val = ans[p]; } cout << len << '\n'; FOO(i,1,len) cout << ans[i] - ans[i-1] << ' '; cout << endl; return true; } void solve(){ int n, m; cin >> n >> m; int l = 16; while(check(n, m, l << 1)) l <<= 1; int ans = 0; for(; l > 0; l >>= 1) if(check(n, m, ans | l)) ans |= l; check(n, m, ans, true); } int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin >> t; for(; t; --t) solve(); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'bool check(int, int, int, bool)':
sequence.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define FOR(i,n) for(int i=0;i<(n);++i)
      |                               ^
sequence.cpp:42:2: note: in expansion of macro 'FOR'
   42 |  FOR(i,q.size()){
      |  ^~~
sequence.cpp:50:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |  if(q.size() != len + 1) return false;
      |     ~~~~~~~~~^~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...