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 fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
#define printl(args...) printf(args)
#else
#define printl(args...) 0
#endif
int n, m;
int timer, len;
bool used[400005];
int pref[400005];
void dfs(int v){
used[v] = true;
{
int to = v - m;
if(to >= 0 && !used[to])
dfs(to);
}
{
int to = v + n;
if(to <= len && !used[to])
dfs(to);
}
pref[v] = timer++;
}
bool check(int len){
::len = len;
fill(pref, pref + len + 1, 0);
fill(used, used + len + 1, false);
timer = 0;
for(int i = 0; i <= len; i++)
if(!used[i])
dfs(i);
for(int i = n; i <= len; i++)
if(pref[i] - pref[i - n] > 0)
return false;
for(int i = m; i <= len; i++)
if(pref[i] - pref[i - m] < 0)
return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int tests;
cin >> tests;
while(tests--){
cin >> n >> m;
int l = 0, r = n + m;
while(l < r){
int mid = (l + r + 1) >> 1;
if(check(mid))l = mid;
else r = mid - 1;
}
check(l);
cout << l << '\n';
if(l){
for(int i = 1; i <= l; i++)
cout << pref[i] - pref[i - 1] << ' ';
cout << '\n';
}
}
}
# | 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... |