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 pb push_back
#define LL long long
#define Kultivator ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;
vector <int> Top;
int A[Mxn];
bool Used[Mxn];
void Dfs(int v, int Mid, int N, int M){
Used[v] = true;
if(v + N <= Mid && !Used[v + N]) Dfs(v + N, Mid, N, M);
if(v >= M && !Used[v - M]) Dfs(v - M, Mid, N, M);
Top.pb(v);
}
bool Check(int Mid, int N, int M){
Top.clear();
for(int i = 0; i <= Mid; i++){
Used[i] = 0;
}
//return cout << 'h', 0;
for(int i = 0; i <= Mid; i++){
if(!Used[i]) Dfs(i, Mid, N, M);
}
for(int i = 0; i <= Mid; i++){
A[Top[i]] = i;
}
for(int i = 0; i <= Mid; i++){
if(i + N <= Mid && A[i] < A[i + N]) return false;
if(i >= M && A[i] < A[i - M]) return false;
}
return true;
}
int main() {
Kultivator;
int tt;
cin >> tt;
while(tt--){
int N, M;
cin >> N >> M;
int L = 1, R = 4e5 + 1;
while(L <= R){
int Mid = (L + R) / 2;
if(Check(Mid, N, M)) L = Mid + 1;
else R = Mid - 1;
}
Check(R, N, M);
cout << R << '\n';
for(int i = 1; i <= R; i++){
cout << A[i] - A[i - 1] << ' ';
}
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... |