This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |