Submission #963165

#TimeUsernameProblemLanguageResultExecution timeMemory
963165starchanNice sequence (IZhO18_sequence)C++17
100 / 100
1567 ms76928 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e17 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) const int MX = 4e5+2; int dp[MX]; vector<int> adj[MX]; vector<bool> vis(MX); int solve(int u) { if(vis[u]) return dp[u]; dp[u] = 0; vis[u] = 1; for(int v: adj[u]) dp[u] = max(dp[u], solve(v)); return ++dp[u]; } signed main() { fast(); int t; cin >> t; while(t--) { int n, m; cin >> n >> m; int p = m; int N = 0; while(true) { N = max(N, p); p%=n; if(p == 0) break; p+=m; } N--; for(int i = 0; i <= N; i++) { adj[i].clear(); if((i+m) <= N) adj[i].pb(i+m); if((i-n) >= 0) adj[i].pb(i-n); } vis.assign(N+1, false); vector<array<int, 2>> vi; for(int i = 0; i <= N; i++) vi.pb({-solve(i), i}); sort(vi.begin(), vi.end()); vector<int> a(N+1); for(int i = 0; i <= N; i++) a[vi[i][1]] = i; for(int i = N; i >= 1; i--) a[i]-=a[i-1]; cout << N << "\n"; for(int i = 1; i <= N; i++) cout << a[i] << " "; 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...