답안 #496571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496571 2021-12-21T14:47:49 Z vinnipuh01 Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 57908 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.emplace_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";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 18252 KB Ok
2 Correct 31 ms 18320 KB Ok
3 Correct 23 ms 12484 KB Ok
4 Correct 27 ms 12412 KB Ok
5 Correct 29 ms 12492 KB Ok
6 Correct 24 ms 13556 KB Ok
7 Correct 26 ms 12380 KB Ok
8 Correct 25 ms 13628 KB Ok
9 Correct 24 ms 12128 KB Ok
10 Correct 25 ms 15116 KB Ok
11 Correct 25 ms 12380 KB Ok
12 Correct 22 ms 12228 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 15188 KB Ok
2 Correct 28 ms 15180 KB Ok
3 Correct 27 ms 15180 KB Ok
4 Correct 27 ms 15308 KB Ok
5 Correct 28 ms 15208 KB Ok
6 Correct 31 ms 15320 KB Ok
7 Correct 44 ms 15952 KB Ok
8 Correct 34 ms 15536 KB Ok
9 Correct 47 ms 15996 KB Ok
10 Correct 37 ms 15648 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 18292 KB Ok
2 Correct 31 ms 18252 KB Ok
3 Correct 28 ms 15084 KB Ok
4 Correct 28 ms 14144 KB Ok
5 Correct 31 ms 18252 KB Ok
6 Correct 31 ms 18244 KB Ok
7 Correct 29 ms 18252 KB Ok
8 Correct 28 ms 18256 KB Ok
9 Correct 28 ms 18236 KB Ok
10 Correct 28 ms 15188 KB Ok
11 Correct 25 ms 14156 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 15100 KB Ok
2 Correct 27 ms 12896 KB Ok
3 Correct 27 ms 12492 KB Ok
4 Correct 25 ms 12456 KB Ok
5 Correct 26 ms 12360 KB Ok
6 Correct 222 ms 22156 KB Ok
7 Correct 245 ms 22600 KB Ok
8 Correct 411 ms 25564 KB Ok
9 Correct 289 ms 23844 KB Ok
10 Correct 172 ms 18032 KB Ok
11 Correct 260 ms 23972 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 18252 KB Ok
2 Correct 31 ms 18320 KB Ok
3 Correct 23 ms 12484 KB Ok
4 Correct 27 ms 12412 KB Ok
5 Correct 29 ms 12492 KB Ok
6 Correct 24 ms 13556 KB Ok
7 Correct 26 ms 12380 KB Ok
8 Correct 25 ms 13628 KB Ok
9 Correct 24 ms 12128 KB Ok
10 Correct 25 ms 15116 KB Ok
11 Correct 25 ms 12380 KB Ok
12 Correct 22 ms 12228 KB Ok
13 Correct 15 ms 18292 KB Ok
14 Correct 31 ms 18252 KB Ok
15 Correct 28 ms 15084 KB Ok
16 Correct 28 ms 14144 KB Ok
17 Correct 31 ms 18252 KB Ok
18 Correct 31 ms 18244 KB Ok
19 Correct 29 ms 18252 KB Ok
20 Correct 28 ms 18256 KB Ok
21 Correct 28 ms 18236 KB Ok
22 Correct 28 ms 15188 KB Ok
23 Correct 25 ms 14156 KB Ok
24 Correct 27 ms 12148 KB Ok
25 Correct 27 ms 12164 KB Ok
26 Correct 26 ms 12128 KB Ok
27 Correct 25 ms 12172 KB Ok
28 Correct 23 ms 12236 KB Ok
29 Correct 24 ms 12140 KB Ok
30 Correct 23 ms 12108 KB Ok
31 Correct 25 ms 12156 KB Ok
32 Correct 24 ms 12144 KB Ok
33 Correct 25 ms 12168 KB Ok
34 Correct 37 ms 12280 KB Ok
35 Correct 31 ms 12324 KB Ok
36 Correct 36 ms 12288 KB Ok
37 Correct 30 ms 12364 KB Ok
38 Correct 32 ms 12308 KB Ok
39 Correct 30 ms 12356 KB Ok
40 Correct 34 ms 12396 KB Ok
41 Correct 33 ms 12396 KB Ok
42 Correct 33 ms 12292 KB Ok
43 Correct 33 ms 12404 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 18252 KB Ok
2 Correct 31 ms 18320 KB Ok
3 Correct 23 ms 12484 KB Ok
4 Correct 27 ms 12412 KB Ok
5 Correct 29 ms 12492 KB Ok
6 Correct 24 ms 13556 KB Ok
7 Correct 26 ms 12380 KB Ok
8 Correct 25 ms 13628 KB Ok
9 Correct 24 ms 12128 KB Ok
10 Correct 25 ms 15116 KB Ok
11 Correct 25 ms 12380 KB Ok
12 Correct 22 ms 12228 KB Ok
13 Correct 32 ms 15188 KB Ok
14 Correct 28 ms 15180 KB Ok
15 Correct 27 ms 15180 KB Ok
16 Correct 27 ms 15308 KB Ok
17 Correct 28 ms 15208 KB Ok
18 Correct 31 ms 15320 KB Ok
19 Correct 44 ms 15952 KB Ok
20 Correct 34 ms 15536 KB Ok
21 Correct 47 ms 15996 KB Ok
22 Correct 37 ms 15648 KB Ok
23 Correct 15 ms 18292 KB Ok
24 Correct 31 ms 18252 KB Ok
25 Correct 28 ms 15084 KB Ok
26 Correct 28 ms 14144 KB Ok
27 Correct 31 ms 18252 KB Ok
28 Correct 31 ms 18244 KB Ok
29 Correct 29 ms 18252 KB Ok
30 Correct 28 ms 18256 KB Ok
31 Correct 28 ms 18236 KB Ok
32 Correct 28 ms 15188 KB Ok
33 Correct 25 ms 14156 KB Ok
34 Correct 27 ms 12148 KB Ok
35 Correct 27 ms 12164 KB Ok
36 Correct 26 ms 12128 KB Ok
37 Correct 25 ms 12172 KB Ok
38 Correct 23 ms 12236 KB Ok
39 Correct 24 ms 12140 KB Ok
40 Correct 23 ms 12108 KB Ok
41 Correct 25 ms 12156 KB Ok
42 Correct 24 ms 12144 KB Ok
43 Correct 25 ms 12168 KB Ok
44 Correct 37 ms 12280 KB Ok
45 Correct 31 ms 12324 KB Ok
46 Correct 36 ms 12288 KB Ok
47 Correct 30 ms 12364 KB Ok
48 Correct 32 ms 12308 KB Ok
49 Correct 30 ms 12356 KB Ok
50 Correct 34 ms 12396 KB Ok
51 Correct 33 ms 12396 KB Ok
52 Correct 33 ms 12292 KB Ok
53 Correct 33 ms 12404 KB Ok
54 Correct 146 ms 14868 KB Ok
55 Correct 176 ms 15096 KB Ok
56 Correct 164 ms 15216 KB Ok
57 Correct 130 ms 14376 KB Ok
58 Correct 137 ms 14576 KB Ok
59 Correct 141 ms 14516 KB Ok
60 Correct 117 ms 14308 KB Ok
61 Correct 122 ms 14456 KB Ok
62 Correct 152 ms 14884 KB Ok
63 Correct 134 ms 14560 KB Ok
64 Correct 157 ms 15108 KB Ok
65 Correct 149 ms 14776 KB Ok
66 Correct 137 ms 14648 KB Ok
67 Correct 130 ms 14588 KB Ok
68 Correct 136 ms 14632 KB Ok
69 Correct 392 ms 22364 KB Ok
70 Correct 438 ms 22952 KB Ok
71 Correct 364 ms 22444 KB Ok
72 Correct 381 ms 22304 KB Ok
73 Correct 392 ms 22380 KB Ok
74 Correct 356 ms 22192 KB Ok
75 Correct 361 ms 21764 KB Ok
76 Correct 412 ms 22596 KB Ok
77 Correct 354 ms 21840 KB Ok
78 Correct 430 ms 22304 KB Ok
79 Correct 372 ms 22492 KB Ok
80 Correct 364 ms 22596 KB Ok
81 Correct 366 ms 22468 KB Ok
82 Correct 363 ms 22516 KB Ok
83 Correct 327 ms 22048 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 18252 KB Ok
2 Correct 31 ms 18320 KB Ok
3 Correct 23 ms 12484 KB Ok
4 Correct 27 ms 12412 KB Ok
5 Correct 29 ms 12492 KB Ok
6 Correct 24 ms 13556 KB Ok
7 Correct 26 ms 12380 KB Ok
8 Correct 25 ms 13628 KB Ok
9 Correct 24 ms 12128 KB Ok
10 Correct 25 ms 15116 KB Ok
11 Correct 25 ms 12380 KB Ok
12 Correct 22 ms 12228 KB Ok
13 Correct 32 ms 15188 KB Ok
14 Correct 28 ms 15180 KB Ok
15 Correct 27 ms 15180 KB Ok
16 Correct 27 ms 15308 KB Ok
17 Correct 28 ms 15208 KB Ok
18 Correct 31 ms 15320 KB Ok
19 Correct 44 ms 15952 KB Ok
20 Correct 34 ms 15536 KB Ok
21 Correct 47 ms 15996 KB Ok
22 Correct 37 ms 15648 KB Ok
23 Correct 15 ms 18292 KB Ok
24 Correct 31 ms 18252 KB Ok
25 Correct 28 ms 15084 KB Ok
26 Correct 28 ms 14144 KB Ok
27 Correct 31 ms 18252 KB Ok
28 Correct 31 ms 18244 KB Ok
29 Correct 29 ms 18252 KB Ok
30 Correct 28 ms 18256 KB Ok
31 Correct 28 ms 18236 KB Ok
32 Correct 28 ms 15188 KB Ok
33 Correct 25 ms 14156 KB Ok
34 Correct 28 ms 15100 KB Ok
35 Correct 27 ms 12896 KB Ok
36 Correct 27 ms 12492 KB Ok
37 Correct 25 ms 12456 KB Ok
38 Correct 26 ms 12360 KB Ok
39 Correct 222 ms 22156 KB Ok
40 Correct 245 ms 22600 KB Ok
41 Correct 411 ms 25564 KB Ok
42 Correct 289 ms 23844 KB Ok
43 Correct 172 ms 18032 KB Ok
44 Correct 260 ms 23972 KB Ok
45 Correct 27 ms 12148 KB Ok
46 Correct 27 ms 12164 KB Ok
47 Correct 26 ms 12128 KB Ok
48 Correct 25 ms 12172 KB Ok
49 Correct 23 ms 12236 KB Ok
50 Correct 24 ms 12140 KB Ok
51 Correct 23 ms 12108 KB Ok
52 Correct 25 ms 12156 KB Ok
53 Correct 24 ms 12144 KB Ok
54 Correct 25 ms 12168 KB Ok
55 Correct 37 ms 12280 KB Ok
56 Correct 31 ms 12324 KB Ok
57 Correct 36 ms 12288 KB Ok
58 Correct 30 ms 12364 KB Ok
59 Correct 32 ms 12308 KB Ok
60 Correct 30 ms 12356 KB Ok
61 Correct 34 ms 12396 KB Ok
62 Correct 33 ms 12396 KB Ok
63 Correct 33 ms 12292 KB Ok
64 Correct 33 ms 12404 KB Ok
65 Correct 146 ms 14868 KB Ok
66 Correct 176 ms 15096 KB Ok
67 Correct 164 ms 15216 KB Ok
68 Correct 130 ms 14376 KB Ok
69 Correct 137 ms 14576 KB Ok
70 Correct 141 ms 14516 KB Ok
71 Correct 117 ms 14308 KB Ok
72 Correct 122 ms 14456 KB Ok
73 Correct 152 ms 14884 KB Ok
74 Correct 134 ms 14560 KB Ok
75 Correct 157 ms 15108 KB Ok
76 Correct 149 ms 14776 KB Ok
77 Correct 137 ms 14648 KB Ok
78 Correct 130 ms 14588 KB Ok
79 Correct 136 ms 14632 KB Ok
80 Correct 392 ms 22364 KB Ok
81 Correct 438 ms 22952 KB Ok
82 Correct 364 ms 22444 KB Ok
83 Correct 381 ms 22304 KB Ok
84 Correct 392 ms 22380 KB Ok
85 Correct 356 ms 22192 KB Ok
86 Correct 361 ms 21764 KB Ok
87 Correct 412 ms 22596 KB Ok
88 Correct 354 ms 21840 KB Ok
89 Correct 430 ms 22304 KB Ok
90 Correct 372 ms 22492 KB Ok
91 Correct 364 ms 22596 KB Ok
92 Correct 366 ms 22468 KB Ok
93 Correct 363 ms 22516 KB Ok
94 Correct 327 ms 22048 KB Ok
95 Correct 330 ms 19532 KB Ok
96 Correct 456 ms 22620 KB Ok
97 Correct 414 ms 20660 KB Ok
98 Correct 314 ms 20436 KB Ok
99 Correct 388 ms 20232 KB Ok
100 Correct 407 ms 20312 KB Ok
101 Correct 410 ms 21320 KB Ok
102 Correct 405 ms 20612 KB Ok
103 Correct 409 ms 21272 KB Ok
104 Correct 465 ms 22476 KB Ok
105 Correct 451 ms 22552 KB Ok
106 Correct 382 ms 22264 KB Ok
107 Correct 426 ms 21752 KB Ok
108 Correct 478 ms 22448 KB Ok
109 Correct 469 ms 22968 KB Ok
110 Correct 1818 ms 55256 KB Ok
111 Execution timed out 2078 ms 57908 KB Time limit exceeded
112 Halted 0 ms 0 KB -