Submission #496134

# Submission time Handle Problem Language Result Execution time Memory
496134 2021-12-20T18:30:20 Z vinnipuh01 Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 52772 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 ( 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;
		}
	}
	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 43 ms 18252 KB Ok
2 Correct 44 ms 18428 KB Ok
3 Correct 39 ms 12432 KB Ok
4 Correct 36 ms 12436 KB Ok
5 Correct 37 ms 12408 KB Ok
6 Correct 39 ms 13676 KB Ok
7 Correct 39 ms 12364 KB Ok
8 Correct 41 ms 13640 KB Ok
9 Correct 44 ms 12240 KB Ok
10 Correct 40 ms 15184 KB Ok
11 Correct 37 ms 12364 KB Ok
12 Correct 37 ms 12268 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15216 KB Ok
2 Correct 39 ms 15180 KB Ok
3 Correct 44 ms 15100 KB Ok
4 Correct 40 ms 15100 KB Ok
5 Correct 44 ms 15200 KB Ok
6 Correct 43 ms 15300 KB Ok
7 Correct 62 ms 15984 KB Ok
8 Correct 48 ms 15472 KB Ok
9 Correct 62 ms 16068 KB Ok
10 Correct 49 ms 15612 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 18 ms 18288 KB Ok
2 Correct 44 ms 18324 KB Ok
3 Correct 44 ms 15200 KB Ok
4 Correct 39 ms 14156 KB Ok
5 Correct 41 ms 18252 KB Ok
6 Correct 41 ms 18244 KB Ok
7 Correct 40 ms 18324 KB Ok
8 Correct 40 ms 18320 KB Ok
9 Correct 43 ms 18316 KB Ok
10 Correct 38 ms 15084 KB Ok
11 Correct 38 ms 14144 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 37 ms 15180 KB Ok
2 Correct 37 ms 12876 KB Ok
3 Correct 39 ms 12492 KB Ok
4 Correct 48 ms 12444 KB Ok
5 Correct 37 ms 12236 KB Ok
6 Correct 255 ms 22156 KB Ok
7 Correct 258 ms 22512 KB Ok
8 Correct 438 ms 25556 KB Ok
9 Correct 323 ms 23844 KB Ok
10 Correct 185 ms 17928 KB Ok
11 Correct 291 ms 24072 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18252 KB Ok
2 Correct 44 ms 18428 KB Ok
3 Correct 39 ms 12432 KB Ok
4 Correct 36 ms 12436 KB Ok
5 Correct 37 ms 12408 KB Ok
6 Correct 39 ms 13676 KB Ok
7 Correct 39 ms 12364 KB Ok
8 Correct 41 ms 13640 KB Ok
9 Correct 44 ms 12240 KB Ok
10 Correct 40 ms 15184 KB Ok
11 Correct 37 ms 12364 KB Ok
12 Correct 37 ms 12268 KB Ok
13 Correct 18 ms 18288 KB Ok
14 Correct 44 ms 18324 KB Ok
15 Correct 44 ms 15200 KB Ok
16 Correct 39 ms 14156 KB Ok
17 Correct 41 ms 18252 KB Ok
18 Correct 41 ms 18244 KB Ok
19 Correct 40 ms 18324 KB Ok
20 Correct 40 ms 18320 KB Ok
21 Correct 43 ms 18316 KB Ok
22 Correct 38 ms 15084 KB Ok
23 Correct 38 ms 14144 KB Ok
24 Correct 47 ms 12156 KB Ok
25 Correct 50 ms 12108 KB Ok
26 Correct 49 ms 12156 KB Ok
27 Correct 46 ms 12108 KB Ok
28 Correct 47 ms 12144 KB Ok
29 Correct 41 ms 12140 KB Ok
30 Correct 48 ms 12140 KB Ok
31 Correct 50 ms 12240 KB Ok
32 Correct 46 ms 12160 KB Ok
33 Correct 45 ms 12144 KB Ok
34 Correct 57 ms 12356 KB Ok
35 Correct 57 ms 12372 KB Ok
36 Correct 63 ms 12332 KB Ok
37 Correct 59 ms 12388 KB Ok
38 Correct 54 ms 12392 KB Ok
39 Correct 65 ms 12308 KB Ok
40 Correct 63 ms 12420 KB Ok
41 Correct 59 ms 12324 KB Ok
42 Correct 59 ms 12332 KB Ok
43 Correct 58 ms 12356 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18252 KB Ok
2 Correct 44 ms 18428 KB Ok
3 Correct 39 ms 12432 KB Ok
4 Correct 36 ms 12436 KB Ok
5 Correct 37 ms 12408 KB Ok
6 Correct 39 ms 13676 KB Ok
7 Correct 39 ms 12364 KB Ok
8 Correct 41 ms 13640 KB Ok
9 Correct 44 ms 12240 KB Ok
10 Correct 40 ms 15184 KB Ok
11 Correct 37 ms 12364 KB Ok
12 Correct 37 ms 12268 KB Ok
13 Correct 38 ms 15216 KB Ok
14 Correct 39 ms 15180 KB Ok
15 Correct 44 ms 15100 KB Ok
16 Correct 40 ms 15100 KB Ok
17 Correct 44 ms 15200 KB Ok
18 Correct 43 ms 15300 KB Ok
19 Correct 62 ms 15984 KB Ok
20 Correct 48 ms 15472 KB Ok
21 Correct 62 ms 16068 KB Ok
22 Correct 49 ms 15612 KB Ok
23 Correct 18 ms 18288 KB Ok
24 Correct 44 ms 18324 KB Ok
25 Correct 44 ms 15200 KB Ok
26 Correct 39 ms 14156 KB Ok
27 Correct 41 ms 18252 KB Ok
28 Correct 41 ms 18244 KB Ok
29 Correct 40 ms 18324 KB Ok
30 Correct 40 ms 18320 KB Ok
31 Correct 43 ms 18316 KB Ok
32 Correct 38 ms 15084 KB Ok
33 Correct 38 ms 14144 KB Ok
34 Correct 47 ms 12156 KB Ok
35 Correct 50 ms 12108 KB Ok
36 Correct 49 ms 12156 KB Ok
37 Correct 46 ms 12108 KB Ok
38 Correct 47 ms 12144 KB Ok
39 Correct 41 ms 12140 KB Ok
40 Correct 48 ms 12140 KB Ok
41 Correct 50 ms 12240 KB Ok
42 Correct 46 ms 12160 KB Ok
43 Correct 45 ms 12144 KB Ok
44 Correct 57 ms 12356 KB Ok
45 Correct 57 ms 12372 KB Ok
46 Correct 63 ms 12332 KB Ok
47 Correct 59 ms 12388 KB Ok
48 Correct 54 ms 12392 KB Ok
49 Correct 65 ms 12308 KB Ok
50 Correct 63 ms 12420 KB Ok
51 Correct 59 ms 12324 KB Ok
52 Correct 59 ms 12332 KB Ok
53 Correct 58 ms 12356 KB Ok
54 Correct 184 ms 14896 KB Ok
55 Correct 220 ms 15168 KB Ok
56 Correct 209 ms 15124 KB Ok
57 Correct 140 ms 14576 KB Ok
58 Correct 191 ms 14612 KB Ok
59 Correct 152 ms 14448 KB Ok
60 Correct 145 ms 14332 KB Ok
61 Correct 147 ms 14464 KB Ok
62 Correct 195 ms 14892 KB Ok
63 Correct 157 ms 14532 KB Ok
64 Correct 211 ms 15220 KB Ok
65 Correct 175 ms 14784 KB Ok
66 Correct 169 ms 14600 KB Ok
67 Correct 152 ms 14488 KB Ok
68 Correct 179 ms 14660 KB Ok
69 Correct 455 ms 22392 KB Ok
70 Correct 471 ms 22848 KB Ok
71 Correct 454 ms 22452 KB Ok
72 Correct 419 ms 22288 KB Ok
73 Correct 441 ms 22336 KB Ok
74 Correct 459 ms 22252 KB Ok
75 Correct 461 ms 22016 KB Ok
76 Correct 457 ms 22556 KB Ok
77 Correct 453 ms 21920 KB Ok
78 Correct 457 ms 22312 KB Ok
79 Correct 451 ms 22692 KB Ok
80 Correct 458 ms 22656 KB Ok
81 Correct 454 ms 22532 KB Ok
82 Correct 448 ms 22468 KB Ok
83 Correct 441 ms 21888 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18252 KB Ok
2 Correct 44 ms 18428 KB Ok
3 Correct 39 ms 12432 KB Ok
4 Correct 36 ms 12436 KB Ok
5 Correct 37 ms 12408 KB Ok
6 Correct 39 ms 13676 KB Ok
7 Correct 39 ms 12364 KB Ok
8 Correct 41 ms 13640 KB Ok
9 Correct 44 ms 12240 KB Ok
10 Correct 40 ms 15184 KB Ok
11 Correct 37 ms 12364 KB Ok
12 Correct 37 ms 12268 KB Ok
13 Correct 38 ms 15216 KB Ok
14 Correct 39 ms 15180 KB Ok
15 Correct 44 ms 15100 KB Ok
16 Correct 40 ms 15100 KB Ok
17 Correct 44 ms 15200 KB Ok
18 Correct 43 ms 15300 KB Ok
19 Correct 62 ms 15984 KB Ok
20 Correct 48 ms 15472 KB Ok
21 Correct 62 ms 16068 KB Ok
22 Correct 49 ms 15612 KB Ok
23 Correct 18 ms 18288 KB Ok
24 Correct 44 ms 18324 KB Ok
25 Correct 44 ms 15200 KB Ok
26 Correct 39 ms 14156 KB Ok
27 Correct 41 ms 18252 KB Ok
28 Correct 41 ms 18244 KB Ok
29 Correct 40 ms 18324 KB Ok
30 Correct 40 ms 18320 KB Ok
31 Correct 43 ms 18316 KB Ok
32 Correct 38 ms 15084 KB Ok
33 Correct 38 ms 14144 KB Ok
34 Correct 37 ms 15180 KB Ok
35 Correct 37 ms 12876 KB Ok
36 Correct 39 ms 12492 KB Ok
37 Correct 48 ms 12444 KB Ok
38 Correct 37 ms 12236 KB Ok
39 Correct 255 ms 22156 KB Ok
40 Correct 258 ms 22512 KB Ok
41 Correct 438 ms 25556 KB Ok
42 Correct 323 ms 23844 KB Ok
43 Correct 185 ms 17928 KB Ok
44 Correct 291 ms 24072 KB Ok
45 Correct 47 ms 12156 KB Ok
46 Correct 50 ms 12108 KB Ok
47 Correct 49 ms 12156 KB Ok
48 Correct 46 ms 12108 KB Ok
49 Correct 47 ms 12144 KB Ok
50 Correct 41 ms 12140 KB Ok
51 Correct 48 ms 12140 KB Ok
52 Correct 50 ms 12240 KB Ok
53 Correct 46 ms 12160 KB Ok
54 Correct 45 ms 12144 KB Ok
55 Correct 57 ms 12356 KB Ok
56 Correct 57 ms 12372 KB Ok
57 Correct 63 ms 12332 KB Ok
58 Correct 59 ms 12388 KB Ok
59 Correct 54 ms 12392 KB Ok
60 Correct 65 ms 12308 KB Ok
61 Correct 63 ms 12420 KB Ok
62 Correct 59 ms 12324 KB Ok
63 Correct 59 ms 12332 KB Ok
64 Correct 58 ms 12356 KB Ok
65 Correct 184 ms 14896 KB Ok
66 Correct 220 ms 15168 KB Ok
67 Correct 209 ms 15124 KB Ok
68 Correct 140 ms 14576 KB Ok
69 Correct 191 ms 14612 KB Ok
70 Correct 152 ms 14448 KB Ok
71 Correct 145 ms 14332 KB Ok
72 Correct 147 ms 14464 KB Ok
73 Correct 195 ms 14892 KB Ok
74 Correct 157 ms 14532 KB Ok
75 Correct 211 ms 15220 KB Ok
76 Correct 175 ms 14784 KB Ok
77 Correct 169 ms 14600 KB Ok
78 Correct 152 ms 14488 KB Ok
79 Correct 179 ms 14660 KB Ok
80 Correct 455 ms 22392 KB Ok
81 Correct 471 ms 22848 KB Ok
82 Correct 454 ms 22452 KB Ok
83 Correct 419 ms 22288 KB Ok
84 Correct 441 ms 22336 KB Ok
85 Correct 459 ms 22252 KB Ok
86 Correct 461 ms 22016 KB Ok
87 Correct 457 ms 22556 KB Ok
88 Correct 453 ms 21920 KB Ok
89 Correct 457 ms 22312 KB Ok
90 Correct 451 ms 22692 KB Ok
91 Correct 458 ms 22656 KB Ok
92 Correct 454 ms 22532 KB Ok
93 Correct 448 ms 22468 KB Ok
94 Correct 441 ms 21888 KB Ok
95 Correct 381 ms 19544 KB Ok
96 Correct 559 ms 22592 KB Ok
97 Correct 462 ms 20792 KB Ok
98 Correct 348 ms 20352 KB Ok
99 Correct 433 ms 20116 KB Ok
100 Correct 467 ms 20380 KB Ok
101 Correct 483 ms 21344 KB Ok
102 Correct 452 ms 20456 KB Ok
103 Correct 469 ms 21164 KB Ok
104 Correct 551 ms 22460 KB Ok
105 Correct 517 ms 22468 KB Ok
106 Correct 464 ms 22244 KB Ok
107 Correct 488 ms 21740 KB Ok
108 Correct 586 ms 22512 KB Ok
109 Correct 551 ms 22984 KB Ok
110 Execution timed out 2073 ms 52772 KB Time limit exceeded
111 Halted 0 ms 0 KB -