Submission #496138

# Submission time Handle Problem Language Result Execution time Memory
496138 2021-12-20T18:38:31 Z vinnipuh01 Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 55356 KB
#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;
 
 
/*
    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;
	for ( int i = 1; i <= 2; i ++ ) {
		int to;
		if ( ans )
			return;
		if ( i == 1 ) {
			if ( nn[ u ] >= 0 )
				to = nn[ u ];
			else
				continue;
		}
		else {
			if ( mm[ u ] >= 0 )
				to = mm[ u ];
			else
				continue;
		}
		if ( !used[ to ] )
			dfs( to );
		else if ( used[ to ] == 1 ) {
			ans = 1;
			return;
		}
	}
		if ( ans )
			return;
	used[ u ] = 2;
}
 
void dfs1( int u ) {
	used[ u ] = 1;
	for ( int i = 1; i <= 2; i ++ ) {
		int to;
		if ( i == 1 ) {
			if ( nn[ u ] >= 0 )
				to = nn[ u ];
			else
				continue;
		}
		else {
			if ( mm[ u ] >= 0 )
				to = mm[ u ];
			else
				continue;
		}
		if ( !used[ to ] )
			dfs1( to );
	}
	ts.push_back( u );
}
 
bool ok( int x ) {
	for ( int i = 0; i <= x; i ++ ) {
		used[ i ] = 0;
		nn[ i ] = -1;
		mm[ i ] = -1; 
		if ( i >= n )
			nn[ i - n ] = i;
		if ( i >= m )
			mm[ i ] = i - m; 
	}
	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, mid;
	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 Correct 37 ms 18328 KB Ok
2 Correct 43 ms 18316 KB Ok
3 Correct 26 ms 12492 KB Ok
4 Correct 25 ms 12492 KB Ok
5 Correct 24 ms 12520 KB Ok
6 Correct 24 ms 13516 KB Ok
7 Correct 24 ms 12392 KB Ok
8 Correct 26 ms 13640 KB Ok
9 Correct 25 ms 12248 KB Ok
10 Correct 26 ms 15188 KB Ok
11 Correct 26 ms 12380 KB Ok
12 Correct 23 ms 12236 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 31 ms 15180 KB Ok
2 Correct 30 ms 15180 KB Ok
3 Correct 32 ms 15208 KB Ok
4 Correct 30 ms 15180 KB Ok
5 Correct 30 ms 15180 KB Ok
6 Correct 30 ms 15300 KB Ok
7 Correct 47 ms 15868 KB Ok
8 Correct 38 ms 15500 KB Ok
9 Correct 57 ms 16076 KB Ok
10 Correct 50 ms 15672 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 18 ms 18324 KB Ok
2 Correct 36 ms 18260 KB Ok
3 Correct 38 ms 15180 KB Ok
4 Correct 30 ms 14160 KB Ok
5 Correct 33 ms 18300 KB Ok
6 Correct 29 ms 18240 KB Ok
7 Correct 38 ms 18252 KB Ok
8 Correct 31 ms 18252 KB Ok
9 Correct 29 ms 18232 KB Ok
10 Correct 29 ms 15188 KB Ok
11 Correct 28 ms 14156 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15180 KB Ok
2 Correct 25 ms 12876 KB Ok
3 Correct 37 ms 12492 KB Ok
4 Correct 26 ms 12364 KB Ok
5 Correct 30 ms 12236 KB Ok
6 Correct 266 ms 22064 KB Ok
7 Correct 249 ms 22588 KB Ok
8 Correct 447 ms 25568 KB Ok
9 Correct 311 ms 23900 KB Ok
10 Correct 170 ms 17916 KB Ok
11 Correct 334 ms 23972 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 37 ms 18328 KB Ok
2 Correct 43 ms 18316 KB Ok
3 Correct 26 ms 12492 KB Ok
4 Correct 25 ms 12492 KB Ok
5 Correct 24 ms 12520 KB Ok
6 Correct 24 ms 13516 KB Ok
7 Correct 24 ms 12392 KB Ok
8 Correct 26 ms 13640 KB Ok
9 Correct 25 ms 12248 KB Ok
10 Correct 26 ms 15188 KB Ok
11 Correct 26 ms 12380 KB Ok
12 Correct 23 ms 12236 KB Ok
13 Correct 18 ms 18324 KB Ok
14 Correct 36 ms 18260 KB Ok
15 Correct 38 ms 15180 KB Ok
16 Correct 30 ms 14160 KB Ok
17 Correct 33 ms 18300 KB Ok
18 Correct 29 ms 18240 KB Ok
19 Correct 38 ms 18252 KB Ok
20 Correct 31 ms 18252 KB Ok
21 Correct 29 ms 18232 KB Ok
22 Correct 29 ms 15188 KB Ok
23 Correct 28 ms 14156 KB Ok
24 Correct 26 ms 12168 KB Ok
25 Correct 26 ms 12184 KB Ok
26 Correct 27 ms 12148 KB Ok
27 Correct 26 ms 12156 KB Ok
28 Correct 25 ms 12116 KB Ok
29 Correct 27 ms 12080 KB Ok
30 Correct 27 ms 12108 KB Ok
31 Correct 25 ms 12180 KB Ok
32 Correct 27 ms 12148 KB Ok
33 Correct 26 ms 12120 KB Ok
34 Correct 31 ms 12252 KB Ok
35 Correct 32 ms 12356 KB Ok
36 Correct 31 ms 12384 KB Ok
37 Correct 32 ms 12340 KB Ok
38 Correct 32 ms 12376 KB Ok
39 Correct 30 ms 12324 KB Ok
40 Correct 42 ms 12280 KB Ok
41 Correct 32 ms 12364 KB Ok
42 Correct 31 ms 12356 KB Ok
43 Correct 41 ms 12380 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 37 ms 18328 KB Ok
2 Correct 43 ms 18316 KB Ok
3 Correct 26 ms 12492 KB Ok
4 Correct 25 ms 12492 KB Ok
5 Correct 24 ms 12520 KB Ok
6 Correct 24 ms 13516 KB Ok
7 Correct 24 ms 12392 KB Ok
8 Correct 26 ms 13640 KB Ok
9 Correct 25 ms 12248 KB Ok
10 Correct 26 ms 15188 KB Ok
11 Correct 26 ms 12380 KB Ok
12 Correct 23 ms 12236 KB Ok
13 Correct 31 ms 15180 KB Ok
14 Correct 30 ms 15180 KB Ok
15 Correct 32 ms 15208 KB Ok
16 Correct 30 ms 15180 KB Ok
17 Correct 30 ms 15180 KB Ok
18 Correct 30 ms 15300 KB Ok
19 Correct 47 ms 15868 KB Ok
20 Correct 38 ms 15500 KB Ok
21 Correct 57 ms 16076 KB Ok
22 Correct 50 ms 15672 KB Ok
23 Correct 18 ms 18324 KB Ok
24 Correct 36 ms 18260 KB Ok
25 Correct 38 ms 15180 KB Ok
26 Correct 30 ms 14160 KB Ok
27 Correct 33 ms 18300 KB Ok
28 Correct 29 ms 18240 KB Ok
29 Correct 38 ms 18252 KB Ok
30 Correct 31 ms 18252 KB Ok
31 Correct 29 ms 18232 KB Ok
32 Correct 29 ms 15188 KB Ok
33 Correct 28 ms 14156 KB Ok
34 Correct 26 ms 12168 KB Ok
35 Correct 26 ms 12184 KB Ok
36 Correct 27 ms 12148 KB Ok
37 Correct 26 ms 12156 KB Ok
38 Correct 25 ms 12116 KB Ok
39 Correct 27 ms 12080 KB Ok
40 Correct 27 ms 12108 KB Ok
41 Correct 25 ms 12180 KB Ok
42 Correct 27 ms 12148 KB Ok
43 Correct 26 ms 12120 KB Ok
44 Correct 31 ms 12252 KB Ok
45 Correct 32 ms 12356 KB Ok
46 Correct 31 ms 12384 KB Ok
47 Correct 32 ms 12340 KB Ok
48 Correct 32 ms 12376 KB Ok
49 Correct 30 ms 12324 KB Ok
50 Correct 42 ms 12280 KB Ok
51 Correct 32 ms 12364 KB Ok
52 Correct 31 ms 12356 KB Ok
53 Correct 41 ms 12380 KB Ok
54 Correct 151 ms 14888 KB Ok
55 Correct 183 ms 15144 KB Ok
56 Correct 170 ms 15240 KB Ok
57 Correct 123 ms 14404 KB Ok
58 Correct 143 ms 14616 KB Ok
59 Correct 170 ms 14516 KB Ok
60 Correct 143 ms 14240 KB Ok
61 Correct 138 ms 14428 KB Ok
62 Correct 161 ms 14988 KB Ok
63 Correct 142 ms 14500 KB Ok
64 Correct 158 ms 15172 KB Ok
65 Correct 171 ms 14912 KB Ok
66 Correct 139 ms 14636 KB Ok
67 Correct 127 ms 14564 KB Ok
68 Correct 187 ms 14660 KB Ok
69 Correct 377 ms 22356 KB Ok
70 Correct 447 ms 22852 KB Ok
71 Correct 389 ms 22400 KB Ok
72 Correct 410 ms 22308 KB Ok
73 Correct 375 ms 22508 KB Ok
74 Correct 401 ms 22264 KB Ok
75 Correct 381 ms 21856 KB Ok
76 Correct 501 ms 22700 KB Ok
77 Correct 383 ms 21896 KB Ok
78 Correct 437 ms 22444 KB Ok
79 Correct 396 ms 22492 KB Ok
80 Correct 436 ms 22680 KB Ok
81 Correct 389 ms 22572 KB Ok
82 Correct 418 ms 22464 KB Ok
83 Correct 382 ms 21868 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 37 ms 18328 KB Ok
2 Correct 43 ms 18316 KB Ok
3 Correct 26 ms 12492 KB Ok
4 Correct 25 ms 12492 KB Ok
5 Correct 24 ms 12520 KB Ok
6 Correct 24 ms 13516 KB Ok
7 Correct 24 ms 12392 KB Ok
8 Correct 26 ms 13640 KB Ok
9 Correct 25 ms 12248 KB Ok
10 Correct 26 ms 15188 KB Ok
11 Correct 26 ms 12380 KB Ok
12 Correct 23 ms 12236 KB Ok
13 Correct 31 ms 15180 KB Ok
14 Correct 30 ms 15180 KB Ok
15 Correct 32 ms 15208 KB Ok
16 Correct 30 ms 15180 KB Ok
17 Correct 30 ms 15180 KB Ok
18 Correct 30 ms 15300 KB Ok
19 Correct 47 ms 15868 KB Ok
20 Correct 38 ms 15500 KB Ok
21 Correct 57 ms 16076 KB Ok
22 Correct 50 ms 15672 KB Ok
23 Correct 18 ms 18324 KB Ok
24 Correct 36 ms 18260 KB Ok
25 Correct 38 ms 15180 KB Ok
26 Correct 30 ms 14160 KB Ok
27 Correct 33 ms 18300 KB Ok
28 Correct 29 ms 18240 KB Ok
29 Correct 38 ms 18252 KB Ok
30 Correct 31 ms 18252 KB Ok
31 Correct 29 ms 18232 KB Ok
32 Correct 29 ms 15188 KB Ok
33 Correct 28 ms 14156 KB Ok
34 Correct 28 ms 15180 KB Ok
35 Correct 25 ms 12876 KB Ok
36 Correct 37 ms 12492 KB Ok
37 Correct 26 ms 12364 KB Ok
38 Correct 30 ms 12236 KB Ok
39 Correct 266 ms 22064 KB Ok
40 Correct 249 ms 22588 KB Ok
41 Correct 447 ms 25568 KB Ok
42 Correct 311 ms 23900 KB Ok
43 Correct 170 ms 17916 KB Ok
44 Correct 334 ms 23972 KB Ok
45 Correct 26 ms 12168 KB Ok
46 Correct 26 ms 12184 KB Ok
47 Correct 27 ms 12148 KB Ok
48 Correct 26 ms 12156 KB Ok
49 Correct 25 ms 12116 KB Ok
50 Correct 27 ms 12080 KB Ok
51 Correct 27 ms 12108 KB Ok
52 Correct 25 ms 12180 KB Ok
53 Correct 27 ms 12148 KB Ok
54 Correct 26 ms 12120 KB Ok
55 Correct 31 ms 12252 KB Ok
56 Correct 32 ms 12356 KB Ok
57 Correct 31 ms 12384 KB Ok
58 Correct 32 ms 12340 KB Ok
59 Correct 32 ms 12376 KB Ok
60 Correct 30 ms 12324 KB Ok
61 Correct 42 ms 12280 KB Ok
62 Correct 32 ms 12364 KB Ok
63 Correct 31 ms 12356 KB Ok
64 Correct 41 ms 12380 KB Ok
65 Correct 151 ms 14888 KB Ok
66 Correct 183 ms 15144 KB Ok
67 Correct 170 ms 15240 KB Ok
68 Correct 123 ms 14404 KB Ok
69 Correct 143 ms 14616 KB Ok
70 Correct 170 ms 14516 KB Ok
71 Correct 143 ms 14240 KB Ok
72 Correct 138 ms 14428 KB Ok
73 Correct 161 ms 14988 KB Ok
74 Correct 142 ms 14500 KB Ok
75 Correct 158 ms 15172 KB Ok
76 Correct 171 ms 14912 KB Ok
77 Correct 139 ms 14636 KB Ok
78 Correct 127 ms 14564 KB Ok
79 Correct 187 ms 14660 KB Ok
80 Correct 377 ms 22356 KB Ok
81 Correct 447 ms 22852 KB Ok
82 Correct 389 ms 22400 KB Ok
83 Correct 410 ms 22308 KB Ok
84 Correct 375 ms 22508 KB Ok
85 Correct 401 ms 22264 KB Ok
86 Correct 381 ms 21856 KB Ok
87 Correct 501 ms 22700 KB Ok
88 Correct 383 ms 21896 KB Ok
89 Correct 437 ms 22444 KB Ok
90 Correct 396 ms 22492 KB Ok
91 Correct 436 ms 22680 KB Ok
92 Correct 389 ms 22572 KB Ok
93 Correct 418 ms 22464 KB Ok
94 Correct 382 ms 21868 KB Ok
95 Correct 344 ms 19524 KB Ok
96 Correct 487 ms 22656 KB Ok
97 Correct 457 ms 20672 KB Ok
98 Correct 363 ms 20344 KB Ok
99 Correct 417 ms 20196 KB Ok
100 Correct 423 ms 20280 KB Ok
101 Correct 433 ms 21256 KB Ok
102 Correct 413 ms 20556 KB Ok
103 Correct 425 ms 21308 KB Ok
104 Correct 475 ms 22468 KB Ok
105 Correct 448 ms 22512 KB Ok
106 Correct 402 ms 22296 KB Ok
107 Correct 435 ms 21908 KB Ok
108 Correct 499 ms 22740 KB Ok
109 Correct 474 ms 22968 KB Ok
110 Correct 1873 ms 55356 KB Ok
111 Execution timed out 2068 ms 55240 KB Time limit exceeded
112 Halted 0 ms 0 KB -