/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int t, n, m, deg[N], ord[N];
vector<int> adj[N];
bool check(int mid) {
for(int i=1; i<=mid; i++) {
if(i>=m) {
adj[i-m].pb(i); deg[i]++;
}
if(i>=n) {
adj[i].pb(i-n); deg[i-n]++;
}
}
queue<int> q;
for(int i=0; i<=mid; i++) {
if(deg[i] == 0) q.push(i);
}
int cnt = 0;
while(size(q) > 0) {
int v = q.front();
q.pop();
ord[v] = cnt++;
for(int u : adj[v]) {
deg[u] --;
if(deg[u] == 0) q.push(u);
}
}
fill(deg, deg+n+2, 0);
for(int i=0; i<=mid; i++) adj[i].clear();
if(cnt == mid+1) return 1;
return 0;
}
void solve() {
cin>>n>>m;
int l=0, r=n+m+1;
while(r-l > 1) {
int mid = (l+r)/2;
if(check(mid)) l = mid;
else r = mid;
}
check(l);
cout<<l<<endl;
for(int i=1; i<=l; i++) {
ord[i] -= ord[0];
cout<<(i==1?ord[i]:ord[i]-ord[i-1])<<' ';
}
cout<<endl;
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>t;
while(t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Ok |
2 |
Incorrect |
3 ms |
8848 KB |
Jury has the better answer : jans = 4, pans = 3 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 5, pans = 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |