Submission #879416

#TimeUsernameProblemLanguageResultExecution timeMemory
879416dimashhhNice sequence (IZhO18_sequence)C++17
76 / 100
1205 ms56948 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 10, MOD = 998244353; #define int long long int timer = 1,pref[N],n,m,used[N]; vector<int> g[N],ord; bool ok = false; void dfs(int v){ used[v] = 1; for(int to:g[v]){ if(used[to] == 1){ ok = false; } if(!used[to]){ dfs(to); } } used[v] = 2; ord.push_back(v); } bool can(int len){ for(int i = 1;i <= len; i++){ if(i - m >= 0){ g[i - m].push_back(i); } if(i - n >= 0){ g[i].push_back(i - n); } } for(int i = 0;i <= len;i++){ if(!used[i]){ dfs(i); } } reverse(ord.begin(),ord.end()); for(auto i:ord){ pref[i] = timer++; } bool res = ok; ok = true; timer = 1; ord.clear(); for(int i = 0;i <= len;i++){ g[i].clear(); } for(int i = 0;i <= len;i++){ used[i] = 0; } return res; } void test(){ cin >> n >> m; int l = 0,r = 5e5; while(r - l > 1){ int mid = (l + r) >> 1; if(can(mid)){ l = mid; }else{ r = mid; } } can(l); cout << l << '\n'; for(int i = 1;i <= l;i++){ cout << pref[i] - pref[i - 1] << ' '; } cout << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; cin >> T; for (int i = 1; i <= T; i++) { test(); } }
#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...