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>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N = 1e6 + 5, NN = 4e5;
int F[N];
int n, m, M;
bool ok;
void dfs (int k, int p){
//cout<<k<<" "<<p<<" "<<M<<" "<<n<<" "<<m<<" "<<F[k]<<endl;
if (ok == 0)
return;
if (F[k] == p){
ok = 0;
return;
}
if (F[k])
return;
F[k] = p;
if (k + m <= M)
dfs (k + m, p);
if (k - n >= 0)
dfs (k - n, p);
}
int nn;
int a[N], b[N];
void go (int k){
if (F[k])
return;
F[k] = 1;
if (k + n <= M)
go (k + n);
if (k - m >= 0)
go (k - m);
a[++nn] = k;
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while (T--){
cin>>n>>m;
int l = 0, r = NN;
while (l < r){
M = (l + r + 1) / 2;
ok = 1;
for (int i = 0; i <= M; i++)
F[i] = 0;
for (int i = 0; i <= M && ok == 1; i++)
if (F[i] == 0)
dfs (i, i + 1);
if (ok)
l = M;
else
r = M - 1;
//cout<<M<<" "<<ok<<endl;
}
M = l;
nn = -1;
for (int i = 0; i <= M; i++)
F[i] = 0;
for (int i = 0; i <= M; i++)
if (F[i] == 0)
go (i);
for (int i = 0; i <= M; i++)
b[a[i]] = i;
cout<<M<<endl;
for (int i = 1; i <= M; i++)
cout<<b[i] - b[i - 1]<<" ";
cout<<endl;
}
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... |