답안 #633592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633592 2022-08-22T19:22:24 Z fabijan_cikac Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 48276 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("Ofast")

using namespace std;

#define ll long long int
#define pb push_back

const int N = 400100;
const ll INF = 1e18;

int t, n, m; int a[N];
int v[N][2];
int u[N][2]; int tme;

void rec(int x){
    if (u[x][0] != -1 && a[x] == 0) rec(u[x][0]);
    if (u[x][1] != -1 && a[x] == 0) rec(u[x][1]);
    a[x] = --tme;
}

int bio[N]; ll sz = 0;

bool dfs(int x){
	if(bio[x]) return bio[x] == 1;
	bio[x] = 1;
	if(v[x][0] != -1 && dfs(v[x][0])) return 1;
	if(v[x][1] != -1 && dfs(v[x][1])) return 1;
	bio[x] = 2;
	return 0;
}

void clear_it(int k){
    for (int i = 0; i <= k; ++i){
        bio[i] = 0;
        v[i][0] = -1; u[i][0] = -1;
        v[i][1] = -1; u[i][1] = -1;
    }
}

bool good_seq(int k, int samo = 1){
    if (k == 41381){
        cout << "";
    }
    clear_it(k);
    for (int i = n; i <= k; ++i){
        v[i - n][0] = i; u[i][0] = (i - n);
    }
    for (int i = m; i <= k; ++i){
        v[i][1] = (i - m); u[i - m][1] = i;
    }
    for (int i = 0; i <= k; ++i) a[i] = 0;
    for (int i = 0; i <= k; ++i){
        if (!bio[i]){
            if (dfs(i)) return 0;
        }
    }
    for (int i = 0; i <= k; ++i){
        if (!bio[i]) return 0;
    }
    if(samo) return 1;
    for (int i = 0; i <= k; ++i){
        if (a[i] == 0) rec(i);
    }
    for (int i = 1; i <= k; ++i) a[i] -= a[0];
    a[0] = 0; return 1;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    scanf("%d", &t); memset(v, -1, sizeof(v));
    memset(u, -1, sizeof(u));
    while (t--){
        if (t < 0) break;
        scanf("%d%d", &n, &m);
        int l = 0; int r = n + m + 1;
        while (l < r){
            //printf("%d %d\n", l, r);
            int mid = (l + r + 1) / 2;
            if (good_seq(mid))
                l = mid;
            else r = mid - 1;
        }
        good_seq(l, 0);
        printf("%d\n", l);
        for (int i = 1; i <= l; ++i)
            printf("%d ", a[i] - a[i - 1]);
        printf("\n");
    }

    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     scanf("%d", &t); memset(v, -1, sizeof(v));
      |     ~~~~~^~~~~~~~~~
sequence.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6548 KB Ok
4 Correct 3 ms 6612 KB Ok
5 Correct 3 ms 6612 KB Ok
6 Correct 3 ms 6608 KB Ok
7 Correct 4 ms 6484 KB Ok
8 Correct 3 ms 6484 KB Ok
9 Correct 3 ms 6612 KB Ok
10 Correct 3 ms 6612 KB Ok
11 Correct 3 ms 6484 KB Ok
12 Correct 3 ms 6548 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6484 KB Ok
4 Correct 3 ms 6612 KB Ok
5 Correct 3 ms 6612 KB Ok
6 Correct 6 ms 6740 KB Ok
7 Correct 22 ms 7248 KB Ok
8 Correct 10 ms 6868 KB Ok
9 Correct 22 ms 7440 KB Ok
10 Correct 17 ms 7036 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6608 KB Ok
3 Correct 5 ms 6484 KB Ok
4 Correct 3 ms 6484 KB Ok
5 Correct 4 ms 6484 KB Ok
6 Correct 3 ms 6484 KB Ok
7 Correct 3 ms 6484 KB Ok
8 Correct 3 ms 6612 KB Ok
9 Correct 3 ms 6612 KB Ok
10 Correct 3 ms 6656 KB Ok
11 Correct 3 ms 6612 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6616 KB Ok
4 Correct 3 ms 6484 KB Ok
5 Correct 3 ms 6484 KB Ok
6 Correct 199 ms 16268 KB Ok
7 Correct 199 ms 16336 KB Ok
8 Correct 381 ms 18660 KB Ok
9 Correct 261 ms 18892 KB Ok
10 Correct 148 ms 13132 KB Ok
11 Correct 227 ms 19076 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6548 KB Ok
4 Correct 3 ms 6612 KB Ok
5 Correct 3 ms 6612 KB Ok
6 Correct 3 ms 6608 KB Ok
7 Correct 4 ms 6484 KB Ok
8 Correct 3 ms 6484 KB Ok
9 Correct 3 ms 6612 KB Ok
10 Correct 3 ms 6612 KB Ok
11 Correct 3 ms 6484 KB Ok
12 Correct 3 ms 6548 KB Ok
13 Correct 3 ms 6484 KB Ok
14 Correct 3 ms 6608 KB Ok
15 Correct 5 ms 6484 KB Ok
16 Correct 3 ms 6484 KB Ok
17 Correct 4 ms 6484 KB Ok
18 Correct 3 ms 6484 KB Ok
19 Correct 3 ms 6484 KB Ok
20 Correct 3 ms 6612 KB Ok
21 Correct 3 ms 6612 KB Ok
22 Correct 3 ms 6656 KB Ok
23 Correct 3 ms 6612 KB Ok
24 Correct 5 ms 6612 KB Ok
25 Correct 5 ms 6612 KB Ok
26 Correct 5 ms 6612 KB Ok
27 Correct 5 ms 6612 KB Ok
28 Correct 5 ms 6612 KB Ok
29 Correct 5 ms 6612 KB Ok
30 Correct 5 ms 6612 KB Ok
31 Correct 7 ms 6672 KB Ok
32 Correct 6 ms 6612 KB Ok
33 Correct 5 ms 6612 KB Ok
34 Correct 10 ms 6808 KB Ok
35 Correct 9 ms 6868 KB Ok
36 Correct 10 ms 6912 KB Ok
37 Correct 10 ms 6900 KB Ok
38 Correct 9 ms 6868 KB Ok
39 Correct 9 ms 6868 KB Ok
40 Correct 10 ms 6868 KB Ok
41 Correct 12 ms 6868 KB Ok
42 Correct 12 ms 6804 KB Ok
43 Correct 11 ms 6868 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6548 KB Ok
4 Correct 3 ms 6612 KB Ok
5 Correct 3 ms 6612 KB Ok
6 Correct 3 ms 6608 KB Ok
7 Correct 4 ms 6484 KB Ok
8 Correct 3 ms 6484 KB Ok
9 Correct 3 ms 6612 KB Ok
10 Correct 3 ms 6612 KB Ok
11 Correct 3 ms 6484 KB Ok
12 Correct 3 ms 6548 KB Ok
13 Correct 4 ms 6484 KB Ok
14 Correct 3 ms 6484 KB Ok
15 Correct 3 ms 6484 KB Ok
16 Correct 3 ms 6612 KB Ok
17 Correct 3 ms 6612 KB Ok
18 Correct 6 ms 6740 KB Ok
19 Correct 22 ms 7248 KB Ok
20 Correct 10 ms 6868 KB Ok
21 Correct 22 ms 7440 KB Ok
22 Correct 17 ms 7036 KB Ok
23 Correct 3 ms 6484 KB Ok
24 Correct 3 ms 6608 KB Ok
25 Correct 5 ms 6484 KB Ok
26 Correct 3 ms 6484 KB Ok
27 Correct 4 ms 6484 KB Ok
28 Correct 3 ms 6484 KB Ok
29 Correct 3 ms 6484 KB Ok
30 Correct 3 ms 6612 KB Ok
31 Correct 3 ms 6612 KB Ok
32 Correct 3 ms 6656 KB Ok
33 Correct 3 ms 6612 KB Ok
34 Correct 5 ms 6612 KB Ok
35 Correct 5 ms 6612 KB Ok
36 Correct 5 ms 6612 KB Ok
37 Correct 5 ms 6612 KB Ok
38 Correct 5 ms 6612 KB Ok
39 Correct 5 ms 6612 KB Ok
40 Correct 5 ms 6612 KB Ok
41 Correct 7 ms 6672 KB Ok
42 Correct 6 ms 6612 KB Ok
43 Correct 5 ms 6612 KB Ok
44 Correct 10 ms 6808 KB Ok
45 Correct 9 ms 6868 KB Ok
46 Correct 10 ms 6912 KB Ok
47 Correct 10 ms 6900 KB Ok
48 Correct 9 ms 6868 KB Ok
49 Correct 9 ms 6868 KB Ok
50 Correct 10 ms 6868 KB Ok
51 Correct 12 ms 6868 KB Ok
52 Correct 12 ms 6804 KB Ok
53 Correct 11 ms 6868 KB Ok
54 Correct 126 ms 9408 KB Ok
55 Correct 143 ms 10040 KB Ok
56 Correct 156 ms 9736 KB Ok
57 Correct 119 ms 8992 KB Ok
58 Correct 125 ms 9616 KB Ok
59 Correct 113 ms 9548 KB Ok
60 Correct 106 ms 9152 KB Ok
61 Correct 104 ms 9140 KB Ok
62 Correct 136 ms 10032 KB Ok
63 Correct 112 ms 9300 KB Ok
64 Correct 143 ms 9772 KB Ok
65 Correct 137 ms 9684 KB Ok
66 Correct 123 ms 9472 KB Ok
67 Correct 112 ms 9224 KB Ok
68 Correct 120 ms 9596 KB Ok
69 Correct 372 ms 16620 KB Ok
70 Correct 384 ms 16996 KB Ok
71 Correct 343 ms 16584 KB Ok
72 Correct 357 ms 16592 KB Ok
73 Correct 343 ms 16856 KB Ok
74 Correct 344 ms 16472 KB Ok
75 Correct 396 ms 16588 KB Ok
76 Correct 418 ms 16784 KB Ok
77 Correct 348 ms 16512 KB Ok
78 Correct 375 ms 16408 KB Ok
79 Correct 377 ms 17052 KB Ok
80 Correct 380 ms 16560 KB Ok
81 Correct 399 ms 16884 KB Ok
82 Correct 325 ms 16688 KB Ok
83 Correct 340 ms 16848 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Ok
2 Correct 3 ms 6484 KB Ok
3 Correct 3 ms 6548 KB Ok
4 Correct 3 ms 6612 KB Ok
5 Correct 3 ms 6612 KB Ok
6 Correct 3 ms 6608 KB Ok
7 Correct 4 ms 6484 KB Ok
8 Correct 3 ms 6484 KB Ok
9 Correct 3 ms 6612 KB Ok
10 Correct 3 ms 6612 KB Ok
11 Correct 3 ms 6484 KB Ok
12 Correct 3 ms 6548 KB Ok
13 Correct 4 ms 6484 KB Ok
14 Correct 3 ms 6484 KB Ok
15 Correct 3 ms 6484 KB Ok
16 Correct 3 ms 6612 KB Ok
17 Correct 3 ms 6612 KB Ok
18 Correct 6 ms 6740 KB Ok
19 Correct 22 ms 7248 KB Ok
20 Correct 10 ms 6868 KB Ok
21 Correct 22 ms 7440 KB Ok
22 Correct 17 ms 7036 KB Ok
23 Correct 3 ms 6484 KB Ok
24 Correct 3 ms 6608 KB Ok
25 Correct 5 ms 6484 KB Ok
26 Correct 3 ms 6484 KB Ok
27 Correct 4 ms 6484 KB Ok
28 Correct 3 ms 6484 KB Ok
29 Correct 3 ms 6484 KB Ok
30 Correct 3 ms 6612 KB Ok
31 Correct 3 ms 6612 KB Ok
32 Correct 3 ms 6656 KB Ok
33 Correct 3 ms 6612 KB Ok
34 Correct 3 ms 6484 KB Ok
35 Correct 3 ms 6484 KB Ok
36 Correct 3 ms 6616 KB Ok
37 Correct 3 ms 6484 KB Ok
38 Correct 3 ms 6484 KB Ok
39 Correct 199 ms 16268 KB Ok
40 Correct 199 ms 16336 KB Ok
41 Correct 381 ms 18660 KB Ok
42 Correct 261 ms 18892 KB Ok
43 Correct 148 ms 13132 KB Ok
44 Correct 227 ms 19076 KB Ok
45 Correct 5 ms 6612 KB Ok
46 Correct 5 ms 6612 KB Ok
47 Correct 5 ms 6612 KB Ok
48 Correct 5 ms 6612 KB Ok
49 Correct 5 ms 6612 KB Ok
50 Correct 5 ms 6612 KB Ok
51 Correct 5 ms 6612 KB Ok
52 Correct 7 ms 6672 KB Ok
53 Correct 6 ms 6612 KB Ok
54 Correct 5 ms 6612 KB Ok
55 Correct 10 ms 6808 KB Ok
56 Correct 9 ms 6868 KB Ok
57 Correct 10 ms 6912 KB Ok
58 Correct 10 ms 6900 KB Ok
59 Correct 9 ms 6868 KB Ok
60 Correct 9 ms 6868 KB Ok
61 Correct 10 ms 6868 KB Ok
62 Correct 12 ms 6868 KB Ok
63 Correct 12 ms 6804 KB Ok
64 Correct 11 ms 6868 KB Ok
65 Correct 126 ms 9408 KB Ok
66 Correct 143 ms 10040 KB Ok
67 Correct 156 ms 9736 KB Ok
68 Correct 119 ms 8992 KB Ok
69 Correct 125 ms 9616 KB Ok
70 Correct 113 ms 9548 KB Ok
71 Correct 106 ms 9152 KB Ok
72 Correct 104 ms 9140 KB Ok
73 Correct 136 ms 10032 KB Ok
74 Correct 112 ms 9300 KB Ok
75 Correct 143 ms 9772 KB Ok
76 Correct 137 ms 9684 KB Ok
77 Correct 123 ms 9472 KB Ok
78 Correct 112 ms 9224 KB Ok
79 Correct 120 ms 9596 KB Ok
80 Correct 372 ms 16620 KB Ok
81 Correct 384 ms 16996 KB Ok
82 Correct 343 ms 16584 KB Ok
83 Correct 357 ms 16592 KB Ok
84 Correct 343 ms 16856 KB Ok
85 Correct 344 ms 16472 KB Ok
86 Correct 396 ms 16588 KB Ok
87 Correct 418 ms 16784 KB Ok
88 Correct 348 ms 16512 KB Ok
89 Correct 375 ms 16408 KB Ok
90 Correct 377 ms 17052 KB Ok
91 Correct 380 ms 16560 KB Ok
92 Correct 399 ms 16884 KB Ok
93 Correct 325 ms 16688 KB Ok
94 Correct 340 ms 16848 KB Ok
95 Correct 336 ms 14200 KB Ok
96 Correct 472 ms 17836 KB Ok
97 Correct 427 ms 16624 KB Ok
98 Correct 325 ms 15040 KB Ok
99 Correct 410 ms 15444 KB Ok
100 Correct 414 ms 16324 KB Ok
101 Correct 416 ms 16204 KB Ok
102 Correct 432 ms 16172 KB Ok
103 Correct 412 ms 16572 KB Ok
104 Correct 496 ms 17488 KB Ok
105 Correct 443 ms 17596 KB Ok
106 Correct 399 ms 16148 KB Ok
107 Correct 452 ms 16836 KB Ok
108 Correct 504 ms 18012 KB Ok
109 Correct 474 ms 17104 KB Ok
110 Execution timed out 2001 ms 48276 KB Time limit exceeded
111 Halted 0 ms 0 KB -