#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);
#define int LL
using namespace std;
const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;
vector <int> Top;
int A[Mxn], Ans;
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();
Ans = Mid;
for(int i = 0; i <= Mid; i++){
Used[i] = false;
}
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 = 1; 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;
}
signed main() {
//Kultivator;
int tt;
cin >> tt;
while(tt--){
int N, M;
cin >> N >> M;
int L = 1, R = 5e5 + 1;
while(L <= R){
int Mid = (L + R) >> 1;
if(Check(Mid, N, M)) L = Mid;
else R = Mid - 1;
}
Check(L, N, M);
cout << Ans << '\n';
for(int i = 1; i <= Ans; i++){
cout << A[i] - A[i - 1] << ' ';
}
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2080 ms |
16348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2079 ms |
10460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2053 ms |
8540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2041 ms |
10460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2080 ms |
16348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2080 ms |
16348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2080 ms |
16348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |