Submission #344178

#TimeUsernameProblemLanguageResultExecution timeMemory
344178VEGAnnNice sequence (IZhO18_sequence)C++14
100 / 100
516 ms44644 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define ft first #define sd second #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define pll pair<ll, ll> #define MP make_pair #define PB push_back using namespace std; typedef long long ll; const int N = 400100; vector<int> ts; int n, m, len, mrk[N], pf[N]; void DFS(int v){ mrk[v] = 1; if (v >= m){ if (mrk[v - m] == 0) DFS(v - m); } if (v + n <= len){ if (mrk[v + n] == 0) DFS(v + n); } ts.PB(v); } int main(){ #ifdef _LOCAL freopen("in.txt","r",stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif // _LOCAL int qq; cin >> qq; for (; qq; qq--){ cin >> n >> m; int l = n + m - __gcd(n, m) - 1; cout << l << '\n'; len = l; fill(mrk, mrk + len + 1, 0); fill(pf, pf + len + 1, -1); ts.clear(); for (int i = 0; i <= len; i++) if (!mrk[i]) DFS(i); int it = -len; for (int v : ts){ int mx = it; it++; if (v >= m) mx = max(mx, pf[v - m]); if (v + n <= len) mx = max(mx, pf[v + n]); pf[v] = mx + 1; } for (int i = 1; i <= len; i++) cout << pf[i] - pf[i - 1] << " "; cout << '\n'; } return 0; }
#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...