# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40456 | Pajaraja | Nice sequence (IZhO18_sequence) | C++14 | 1612 ms | 52904 KiB |
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;
vector<int> g[400007];
int pv[400007],deg[400007],parc[400007];
int nzd(int a,int b)
{
if(a==0) return b;
return nzd(b%a,a);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int x=m+n-1-nzd(m,n);
printf("%d\n",x);
fill(deg,deg+x+1,0);
for(int i=0;i<=x;i++) g[i].clear();
for(int i=n;i<=x;i++)
{
g[i].push_back(i-n);
deg[i-n]++;
}
for(int i=m;i<=x;i++)
{
g[i-m].push_back(i);
deg[i]++;
}
queue<int> q;
for(int i=0;i<=x;i++) if(deg[i]==0) q.push(i);
int cnt=0;
while(!q.empty())
{
int u=q.front();
pv[u]=cnt++;
q.pop();
for(int i=0;i<g[u].size();i++)
{
deg[g[u][i]]--;
if(deg[g[u][i]]==0) q.push(g[u][i]);
}
}
for(int i=1;i<=x;i++) printf("%d ",pv[i]-pv[i-1]);
printf("\n");
}
}
Compilation message (stderr)
# | 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... |