#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos, mid;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, p[ 400001 ], used[ 400001 ], nn[ 400001 ], mm[ 400001 ];
vector <int> v[ 400001 ], ts, vv;
void dfs( int u ) {
used[ u ] = 1;
int to = u + n;
int too = u - m;
if ( used[ to ] == 1 ) {
ans = 1;
return;
}
if ( used[ too ] == 1 ) {
ans = 1;
return;
}
if ( to <= mid && !used[ to ] )
dfs( to );
if ( too >= 0 && !used[ too ] )
dfs( too );
used[ u ] = 2;
}
void dfs1( int u ) {
used[ u ] = 1;
int to = u + n;
int too = u - m;
if ( to <= mid && !used[ to ] )
dfs1( to );
if ( too >= 0 && !used[ too ] )
dfs1( too );
ts.push_back( u );
}
bool ok( int x ) {
for ( int i = 0; i <= x; i ++ ) {
used[ i ] = 0;
}
ans = 0;
for ( int i = 0; i <= x; i ++ ) {
if ( !used[ i ] )
dfs( i );
}
if ( ans )
return false;
if ( sum ) {
ts.clear();
for ( int i = 0; i <= x; i ++ ) {
p[ i ] = 0;
used[ i ] = 0;
}
for ( int i = 0; i<= x; i ++ ) {
if ( !used[ i ] )
dfs1( i );
}
num = 0;
for ( auto i : ts )
p[ i ] = ++num;
for ( int i = 1; i <= x; i ++ ) {
p[ i ] -= p[ 0 ];
}
p[ 0 ] = 0;
}
return true;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
int l, r;
while ( t -- ) {
cin >> n >> m;
mx = max( n, m );
l = mx - 1;
r = 400000;
sum = 0;
while ( r - l > 1 ) {
mid = ( r + l ) / 2;
if ( ok( mid ) )
l = mid;
else
r = mid - 1;
}
if ( ok( r ) ) {
sum = 1;
ok( r );
cout << r << "\n";
for ( int i = 1; i <= r; i ++ )
cout << p[ i ] - p[ i - 1 ] << " ";
}
else {
sum = 1;
ok( l );
cout << l << "\n";
for ( int i = 1; i <= l; i ++ )
cout << p[ i ] - p[ i - 1 ] << " ";
}
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
11980 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
15168 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
15180 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
15184 KB |
Jury has the better answer : jans = 5, pans = 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
11980 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
11980 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
11980 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |