#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
int len, n, m, pref[N];
bool vis[N];
vector<int>top;
void dfs(int u){
vis[u] = 1;
if(u + n >= 0 && !vis[u + n]) dfs(u + n);
if(u - m <= len && !vis[u - m]) dfs(u - m);
top.pb(u);
}
bool check(int x){
len = x;
top.clear();
for(int i = 0; i <= len; i++){
vis[i] = 0;
}
for(int i = 0; i <= len; i++){
if(!vis[i]) dfs(i);
}
for(int i = 0; i <= len; i++){
pref[top[i]] = i;
}
for(int i = 0;i <= len; i++){
if(i - m >= 0&& pref[i] <= pref[i - m]) return 0;
if(i + n <= len && pref[i] <= pref[i + n]) return 0;
}
return 1;
}
void solve(){
cin>>n>>m;
int l = 0, r = 400000;
while(l < r){
int mid = (l+r) >> 1;
if(check(mid)) l = mid;
else r = mid-1;
}
check(l);
cout<<l<<"\n";
for(int i=1;i<=l;i++) cout<<pref[i] - pref[i-1]<<" ";
cout<<"\n";
return;
}
int main(){
//fastios
int t = 1;
cin>>t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
486 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
257 ms |
189128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
214 ms |
141876 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
253 ms |
188212 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
486 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
486 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
486 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |