답안 #334935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334935 2020-12-10T10:55:32 Z juggernaut Nice sequence (IZhO18_sequence) C++14
100 / 100
1908 ms 44880 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,len,pref[1000005],timer,vis[1000005];
bool flag;
void dfs(int v){
    vis[v]=1;
    if(v-m>=0){
        if(vis[v-m]==0)dfs(v-m);
        else if(vis[v-m]==1)flag=false;
    }
    if(v+n<=len){
        if(vis[v+n]==0)dfs(v+n);
        else if(vis[v+n]==1)flag=false;
    }
    vis[v]=2;
    pref[v]=timer++;
}
bool check(int x){
    len=x;
    flag=true;
    timer=0;
    for(int i=0;i<=len;i++)vis[i]=0;
    for(int i=0;i<=len;i++)if(!vis[i])dfs(i);
    return flag;
}
int main(){
    int test;
    scanf("%d",&test);
    while(test--){
        scanf("%d%d",&n,&m);
        int l=0,r=400000;
        while(l<r){
            int mid=(l+r+1)>>1;
            if(check(mid))l=mid;
            else r=mid-1;
        }
        check(l);
        printf("%d\n",l);
        if(l){
            for(int i=1;i<=l;i++)printf("%d ",pref[i]-pref[i-1]);
            puts("");
        }
    }
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     scanf("%d",&test);
      |     ~~~~~^~~~~~~~~~~~
sequence.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 8172 KB Ok
2 Correct 54 ms 8216 KB Ok
3 Correct 47 ms 2432 KB Ok
4 Correct 49 ms 2796 KB Ok
5 Correct 48 ms 2432 KB Ok
6 Correct 46 ms 3436 KB Ok
7 Correct 49 ms 2156 KB Ok
8 Correct 48 ms 3440 KB Ok
9 Correct 50 ms 2284 KB Ok
10 Correct 49 ms 4972 KB Ok
11 Correct 48 ms 2156 KB Ok
12 Correct 47 ms 2028 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 8172 KB Ok
2 Correct 57 ms 8172 KB Ok
3 Correct 52 ms 8172 KB Ok
4 Correct 56 ms 8300 KB Ok
5 Correct 50 ms 8172 KB Ok
6 Correct 53 ms 8300 KB Ok
7 Correct 73 ms 8556 KB Ok
8 Correct 70 ms 8300 KB Ok
9 Correct 76 ms 8764 KB Ok
10 Correct 66 ms 8428 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 8192 KB Ok
2 Correct 63 ms 8300 KB Ok
3 Correct 56 ms 8172 KB Ok
4 Correct 62 ms 8300 KB Ok
5 Correct 64 ms 8172 KB Ok
6 Correct 67 ms 8172 KB Ok
7 Correct 59 ms 8172 KB Ok
8 Correct 71 ms 8300 KB Ok
9 Correct 68 ms 8172 KB Ok
10 Correct 64 ms 8172 KB Ok
11 Correct 59 ms 8172 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 8216 KB Ok
2 Correct 72 ms 8172 KB Ok
3 Correct 68 ms 8172 KB Ok
4 Correct 78 ms 8300 KB Ok
5 Correct 69 ms 8172 KB Ok
6 Correct 298 ms 11628 KB Ok
7 Correct 289 ms 10496 KB Ok
8 Correct 528 ms 13804 KB Ok
9 Correct 367 ms 12896 KB Ok
10 Correct 224 ms 9612 KB Ok
11 Correct 324 ms 11756 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 8172 KB Ok
2 Correct 54 ms 8216 KB Ok
3 Correct 47 ms 2432 KB Ok
4 Correct 49 ms 2796 KB Ok
5 Correct 48 ms 2432 KB Ok
6 Correct 46 ms 3436 KB Ok
7 Correct 49 ms 2156 KB Ok
8 Correct 48 ms 3440 KB Ok
9 Correct 50 ms 2284 KB Ok
10 Correct 49 ms 4972 KB Ok
11 Correct 48 ms 2156 KB Ok
12 Correct 47 ms 2028 KB Ok
13 Correct 34 ms 8192 KB Ok
14 Correct 63 ms 8300 KB Ok
15 Correct 56 ms 8172 KB Ok
16 Correct 62 ms 8300 KB Ok
17 Correct 64 ms 8172 KB Ok
18 Correct 67 ms 8172 KB Ok
19 Correct 59 ms 8172 KB Ok
20 Correct 71 ms 8300 KB Ok
21 Correct 68 ms 8172 KB Ok
22 Correct 64 ms 8172 KB Ok
23 Correct 59 ms 8172 KB Ok
24 Correct 54 ms 1900 KB Ok
25 Correct 53 ms 2028 KB Ok
26 Correct 52 ms 2412 KB Ok
27 Correct 54 ms 2412 KB Ok
28 Correct 53 ms 2096 KB Ok
29 Correct 49 ms 4060 KB Ok
30 Correct 54 ms 2156 KB Ok
31 Correct 56 ms 2028 KB Ok
32 Correct 53 ms 2028 KB Ok
33 Correct 54 ms 2284 KB Ok
34 Correct 75 ms 8300 KB Ok
35 Correct 90 ms 8300 KB Ok
36 Correct 80 ms 8356 KB Ok
37 Correct 80 ms 8300 KB Ok
38 Correct 76 ms 8300 KB Ok
39 Correct 74 ms 8300 KB Ok
40 Correct 80 ms 8300 KB Ok
41 Correct 91 ms 8428 KB Ok
42 Correct 77 ms 8300 KB Ok
43 Correct 85 ms 8300 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 8172 KB Ok
2 Correct 54 ms 8216 KB Ok
3 Correct 47 ms 2432 KB Ok
4 Correct 49 ms 2796 KB Ok
5 Correct 48 ms 2432 KB Ok
6 Correct 46 ms 3436 KB Ok
7 Correct 49 ms 2156 KB Ok
8 Correct 48 ms 3440 KB Ok
9 Correct 50 ms 2284 KB Ok
10 Correct 49 ms 4972 KB Ok
11 Correct 48 ms 2156 KB Ok
12 Correct 47 ms 2028 KB Ok
13 Correct 61 ms 8172 KB Ok
14 Correct 57 ms 8172 KB Ok
15 Correct 52 ms 8172 KB Ok
16 Correct 56 ms 8300 KB Ok
17 Correct 50 ms 8172 KB Ok
18 Correct 53 ms 8300 KB Ok
19 Correct 73 ms 8556 KB Ok
20 Correct 70 ms 8300 KB Ok
21 Correct 76 ms 8764 KB Ok
22 Correct 66 ms 8428 KB Ok
23 Correct 34 ms 8192 KB Ok
24 Correct 63 ms 8300 KB Ok
25 Correct 56 ms 8172 KB Ok
26 Correct 62 ms 8300 KB Ok
27 Correct 64 ms 8172 KB Ok
28 Correct 67 ms 8172 KB Ok
29 Correct 59 ms 8172 KB Ok
30 Correct 71 ms 8300 KB Ok
31 Correct 68 ms 8172 KB Ok
32 Correct 64 ms 8172 KB Ok
33 Correct 59 ms 8172 KB Ok
34 Correct 54 ms 1900 KB Ok
35 Correct 53 ms 2028 KB Ok
36 Correct 52 ms 2412 KB Ok
37 Correct 54 ms 2412 KB Ok
38 Correct 53 ms 2096 KB Ok
39 Correct 49 ms 4060 KB Ok
40 Correct 54 ms 2156 KB Ok
41 Correct 56 ms 2028 KB Ok
42 Correct 53 ms 2028 KB Ok
43 Correct 54 ms 2284 KB Ok
44 Correct 75 ms 8300 KB Ok
45 Correct 90 ms 8300 KB Ok
46 Correct 80 ms 8356 KB Ok
47 Correct 80 ms 8300 KB Ok
48 Correct 76 ms 8300 KB Ok
49 Correct 74 ms 8300 KB Ok
50 Correct 80 ms 8300 KB Ok
51 Correct 91 ms 8428 KB Ok
52 Correct 77 ms 8300 KB Ok
53 Correct 85 ms 8300 KB Ok
54 Correct 200 ms 3564 KB Ok
55 Correct 233 ms 3948 KB Ok
56 Correct 229 ms 3948 KB Ok
57 Correct 159 ms 3180 KB Ok
58 Correct 211 ms 3436 KB Ok
59 Correct 172 ms 3308 KB Ok
60 Correct 156 ms 3180 KB Ok
61 Correct 167 ms 3308 KB Ok
62 Correct 213 ms 3692 KB Ok
63 Correct 175 ms 3436 KB Ok
64 Correct 217 ms 3948 KB Ok
65 Correct 196 ms 3692 KB Ok
66 Correct 180 ms 3584 KB Ok
67 Correct 160 ms 3308 KB Ok
68 Correct 181 ms 3564 KB Ok
69 Correct 375 ms 14188 KB Ok
70 Correct 393 ms 14700 KB Ok
71 Correct 371 ms 14316 KB Ok
72 Correct 382 ms 14060 KB Ok
73 Correct 361 ms 14196 KB Ok
74 Correct 379 ms 14176 KB Ok
75 Correct 385 ms 13676 KB Ok
76 Correct 396 ms 14444 KB Ok
77 Correct 361 ms 13676 KB Ok
78 Correct 390 ms 14480 KB Ok
79 Correct 392 ms 14488 KB Ok
80 Correct 368 ms 14572 KB Ok
81 Correct 382 ms 14316 KB Ok
82 Correct 372 ms 14316 KB Ok
83 Correct 369 ms 13932 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 8172 KB Ok
2 Correct 54 ms 8216 KB Ok
3 Correct 47 ms 2432 KB Ok
4 Correct 49 ms 2796 KB Ok
5 Correct 48 ms 2432 KB Ok
6 Correct 46 ms 3436 KB Ok
7 Correct 49 ms 2156 KB Ok
8 Correct 48 ms 3440 KB Ok
9 Correct 50 ms 2284 KB Ok
10 Correct 49 ms 4972 KB Ok
11 Correct 48 ms 2156 KB Ok
12 Correct 47 ms 2028 KB Ok
13 Correct 61 ms 8172 KB Ok
14 Correct 57 ms 8172 KB Ok
15 Correct 52 ms 8172 KB Ok
16 Correct 56 ms 8300 KB Ok
17 Correct 50 ms 8172 KB Ok
18 Correct 53 ms 8300 KB Ok
19 Correct 73 ms 8556 KB Ok
20 Correct 70 ms 8300 KB Ok
21 Correct 76 ms 8764 KB Ok
22 Correct 66 ms 8428 KB Ok
23 Correct 34 ms 8192 KB Ok
24 Correct 63 ms 8300 KB Ok
25 Correct 56 ms 8172 KB Ok
26 Correct 62 ms 8300 KB Ok
27 Correct 64 ms 8172 KB Ok
28 Correct 67 ms 8172 KB Ok
29 Correct 59 ms 8172 KB Ok
30 Correct 71 ms 8300 KB Ok
31 Correct 68 ms 8172 KB Ok
32 Correct 64 ms 8172 KB Ok
33 Correct 59 ms 8172 KB Ok
34 Correct 69 ms 8216 KB Ok
35 Correct 72 ms 8172 KB Ok
36 Correct 68 ms 8172 KB Ok
37 Correct 78 ms 8300 KB Ok
38 Correct 69 ms 8172 KB Ok
39 Correct 298 ms 11628 KB Ok
40 Correct 289 ms 10496 KB Ok
41 Correct 528 ms 13804 KB Ok
42 Correct 367 ms 12896 KB Ok
43 Correct 224 ms 9612 KB Ok
44 Correct 324 ms 11756 KB Ok
45 Correct 54 ms 1900 KB Ok
46 Correct 53 ms 2028 KB Ok
47 Correct 52 ms 2412 KB Ok
48 Correct 54 ms 2412 KB Ok
49 Correct 53 ms 2096 KB Ok
50 Correct 49 ms 4060 KB Ok
51 Correct 54 ms 2156 KB Ok
52 Correct 56 ms 2028 KB Ok
53 Correct 53 ms 2028 KB Ok
54 Correct 54 ms 2284 KB Ok
55 Correct 75 ms 8300 KB Ok
56 Correct 90 ms 8300 KB Ok
57 Correct 80 ms 8356 KB Ok
58 Correct 80 ms 8300 KB Ok
59 Correct 76 ms 8300 KB Ok
60 Correct 74 ms 8300 KB Ok
61 Correct 80 ms 8300 KB Ok
62 Correct 91 ms 8428 KB Ok
63 Correct 77 ms 8300 KB Ok
64 Correct 85 ms 8300 KB Ok
65 Correct 200 ms 3564 KB Ok
66 Correct 233 ms 3948 KB Ok
67 Correct 229 ms 3948 KB Ok
68 Correct 159 ms 3180 KB Ok
69 Correct 211 ms 3436 KB Ok
70 Correct 172 ms 3308 KB Ok
71 Correct 156 ms 3180 KB Ok
72 Correct 167 ms 3308 KB Ok
73 Correct 213 ms 3692 KB Ok
74 Correct 175 ms 3436 KB Ok
75 Correct 217 ms 3948 KB Ok
76 Correct 196 ms 3692 KB Ok
77 Correct 180 ms 3584 KB Ok
78 Correct 160 ms 3308 KB Ok
79 Correct 181 ms 3564 KB Ok
80 Correct 375 ms 14188 KB Ok
81 Correct 393 ms 14700 KB Ok
82 Correct 371 ms 14316 KB Ok
83 Correct 382 ms 14060 KB Ok
84 Correct 361 ms 14196 KB Ok
85 Correct 379 ms 14176 KB Ok
86 Correct 385 ms 13676 KB Ok
87 Correct 396 ms 14444 KB Ok
88 Correct 361 ms 13676 KB Ok
89 Correct 390 ms 14480 KB Ok
90 Correct 392 ms 14488 KB Ok
91 Correct 368 ms 14572 KB Ok
92 Correct 382 ms 14316 KB Ok
93 Correct 372 ms 14316 KB Ok
94 Correct 369 ms 13932 KB Ok
95 Correct 417 ms 7116 KB Ok
96 Correct 634 ms 8880 KB Ok
97 Correct 580 ms 8044 KB Ok
98 Correct 414 ms 7148 KB Ok
99 Correct 526 ms 7532 KB Ok
100 Correct 549 ms 7660 KB Ok
101 Correct 548 ms 7916 KB Ok
102 Correct 539 ms 7788 KB Ok
103 Correct 516 ms 8044 KB Ok
104 Correct 637 ms 9196 KB Ok
105 Correct 611 ms 8940 KB Ok
106 Correct 541 ms 8556 KB Ok
107 Correct 566 ms 8300 KB Ok
108 Correct 633 ms 9144 KB Ok
109 Correct 589 ms 9088 KB Ok
110 Correct 1707 ms 40940 KB Ok
111 Correct 1760 ms 43744 KB Ok
112 Correct 1802 ms 43628 KB Ok
113 Correct 1714 ms 42952 KB Ok
114 Correct 1703 ms 44880 KB Ok
115 Correct 1908 ms 42588 KB Ok
116 Correct 1885 ms 43968 KB Ok
117 Correct 1895 ms 42492 KB Ok
118 Correct 1744 ms 42548 KB Ok
119 Correct 1892 ms 42476 KB Ok
120 Correct 1766 ms 42220 KB Ok
121 Correct 1860 ms 40932 KB Ok
122 Correct 1817 ms 43348 KB Ok
123 Correct 1822 ms 43808 KB Ok
124 Correct 1820 ms 41252 KB Ok
125 Correct 1474 ms 26092 KB Ok