답안 #369951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369951 2021-02-22T19:39:48 Z nicolaalexandra Nice sequence (IZhO18_sequence) C++14
100 / 100
1150 ms 86124 KB
#include <bits/stdc++.h>
#define DIM 2000010
using namespace std;

vector <int> L[DIM];
int v[DIM],g[DIM];
int n,m,k,t,i,j,idx,ok;

void dfs (int nod, int k){
    v[nod] = ++idx;

    if (nod >= n){
        if (!v[nod-n])
            dfs (nod-n,k);
        else ok = 0;
    }

    if (nod + m <= k){
        if (!v[nod+m])
            dfs (nod+m,k);
        else ok = 0;
    }

}

int verif (int k){
    int i;

    for (i=0;i<=k;i++)
        v[i] = g[i] = 0;

    for (i=1;i<=k;i++){
        if (i >= n)
            ++g[i-n];
        if (i >= m)
            ++g[i];
    }

    idx = 0, ok = 1;
    for (i=0;i<=k;++i){
        if (!g[i]){
            dfs (i,k);
            if (!ok)
                return 0;
        }}

    if (!idx)
        return 0;

    for (i=1;i<=k;++i){
        if (i >= n && v[i] >= v[i-n])
            return 0;
        if (i >= m && v[i] <= v[i-m])
            return 0;
    }

    return 1;
}

int main (){

    ios_base::sync_with_stdio(false);

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>t;
    for (;t--;){
        cin>>n>>m;
        if (n % m == 0){
            cout<<n-1<<"\n";
            for (i=1;i<=n-1;++i)
                cout<<"1 ";
            if (n > 1)
                cout<<"\n";
            continue;
        }

        if (m % n == 0){
            cout<<m-1<<"\n";
            for (i=1;i<=m-1;++i)
                cout<<"-1 ";
            if (m > 1)
                cout<<"\n";
            continue;
        }

        int st = min(n,m)-1, dr = 400000, sol = 0;
        while (st <= dr){
            int mid = (st+dr)>>1;
            if (verif(mid)){
                sol = mid;
                st = mid+1;
            } else dr = mid-1;
        }

        verif (sol);

        cout<<sol<<"\n";
        for (i=1;i<=sol;++i)
            cout<<v[i]-v[i-1]<<" ";
        if (sol)
            cout<<"\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47340 KB Ok
2 Correct 27 ms 47340 KB Ok
3 Correct 28 ms 47340 KB Ok
4 Correct 28 ms 47340 KB Ok
5 Correct 27 ms 47356 KB Ok
6 Correct 27 ms 47340 KB Ok
7 Correct 28 ms 47344 KB Ok
8 Correct 28 ms 47340 KB Ok
9 Correct 28 ms 47340 KB Ok
10 Correct 28 ms 47340 KB Ok
11 Correct 28 ms 47340 KB Ok
12 Correct 28 ms 47340 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 48876 KB Ok
2 Correct 34 ms 48876 KB Ok
3 Correct 35 ms 48876 KB Ok
4 Correct 35 ms 48876 KB Ok
5 Correct 34 ms 48876 KB Ok
6 Correct 37 ms 49020 KB Ok
7 Correct 48 ms 49516 KB Ok
8 Correct 40 ms 49132 KB Ok
9 Correct 46 ms 49644 KB Ok
10 Correct 40 ms 49260 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 49004 KB Ok
2 Correct 28 ms 47340 KB Ok
3 Correct 34 ms 48896 KB Ok
4 Correct 36 ms 48876 KB Ok
5 Correct 44 ms 48876 KB Ok
6 Correct 37 ms 48876 KB Ok
7 Correct 36 ms 48876 KB Ok
8 Correct 38 ms 48876 KB Ok
9 Correct 36 ms 48876 KB Ok
10 Correct 37 ms 48876 KB Ok
11 Correct 37 ms 48876 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 48876 KB Ok
2 Correct 41 ms 48876 KB Ok
3 Correct 41 ms 48876 KB Ok
4 Correct 41 ms 48876 KB Ok
5 Correct 45 ms 48876 KB Ok
6 Correct 210 ms 55788 KB Ok
7 Correct 187 ms 54508 KB Ok
8 Correct 346 ms 58476 KB Ok
9 Correct 257 ms 57708 KB Ok
10 Correct 166 ms 53484 KB Ok
11 Correct 260 ms 57196 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47340 KB Ok
2 Correct 27 ms 47340 KB Ok
3 Correct 28 ms 47340 KB Ok
4 Correct 28 ms 47340 KB Ok
5 Correct 27 ms 47356 KB Ok
6 Correct 27 ms 47340 KB Ok
7 Correct 28 ms 47344 KB Ok
8 Correct 28 ms 47340 KB Ok
9 Correct 28 ms 47340 KB Ok
10 Correct 28 ms 47340 KB Ok
11 Correct 28 ms 47340 KB Ok
12 Correct 28 ms 47340 KB Ok
13 Correct 29 ms 49004 KB Ok
14 Correct 28 ms 47340 KB Ok
15 Correct 34 ms 48896 KB Ok
16 Correct 36 ms 48876 KB Ok
17 Correct 44 ms 48876 KB Ok
18 Correct 37 ms 48876 KB Ok
19 Correct 36 ms 48876 KB Ok
20 Correct 38 ms 48876 KB Ok
21 Correct 36 ms 48876 KB Ok
22 Correct 37 ms 48876 KB Ok
23 Correct 37 ms 48876 KB Ok
24 Correct 35 ms 48876 KB Ok
25 Correct 37 ms 49004 KB Ok
26 Correct 36 ms 49004 KB Ok
27 Correct 36 ms 48876 KB Ok
28 Correct 35 ms 48876 KB Ok
29 Correct 32 ms 48876 KB Ok
30 Correct 35 ms 48876 KB Ok
31 Correct 39 ms 48876 KB Ok
32 Correct 38 ms 48876 KB Ok
33 Correct 37 ms 48876 KB Ok
34 Correct 47 ms 49132 KB Ok
35 Correct 51 ms 49260 KB Ok
36 Correct 47 ms 49132 KB Ok
37 Correct 46 ms 49132 KB Ok
38 Correct 45 ms 49132 KB Ok
39 Correct 47 ms 49132 KB Ok
40 Correct 47 ms 49132 KB Ok
41 Correct 46 ms 49132 KB Ok
42 Correct 48 ms 49260 KB Ok
43 Correct 47 ms 49132 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47340 KB Ok
2 Correct 27 ms 47340 KB Ok
3 Correct 28 ms 47340 KB Ok
4 Correct 28 ms 47340 KB Ok
5 Correct 27 ms 47356 KB Ok
6 Correct 27 ms 47340 KB Ok
7 Correct 28 ms 47344 KB Ok
8 Correct 28 ms 47340 KB Ok
9 Correct 28 ms 47340 KB Ok
10 Correct 28 ms 47340 KB Ok
11 Correct 28 ms 47340 KB Ok
12 Correct 28 ms 47340 KB Ok
13 Correct 34 ms 48876 KB Ok
14 Correct 34 ms 48876 KB Ok
15 Correct 35 ms 48876 KB Ok
16 Correct 35 ms 48876 KB Ok
17 Correct 34 ms 48876 KB Ok
18 Correct 37 ms 49020 KB Ok
19 Correct 48 ms 49516 KB Ok
20 Correct 40 ms 49132 KB Ok
21 Correct 46 ms 49644 KB Ok
22 Correct 40 ms 49260 KB Ok
23 Correct 29 ms 49004 KB Ok
24 Correct 28 ms 47340 KB Ok
25 Correct 34 ms 48896 KB Ok
26 Correct 36 ms 48876 KB Ok
27 Correct 44 ms 48876 KB Ok
28 Correct 37 ms 48876 KB Ok
29 Correct 36 ms 48876 KB Ok
30 Correct 38 ms 48876 KB Ok
31 Correct 36 ms 48876 KB Ok
32 Correct 37 ms 48876 KB Ok
33 Correct 37 ms 48876 KB Ok
34 Correct 35 ms 48876 KB Ok
35 Correct 37 ms 49004 KB Ok
36 Correct 36 ms 49004 KB Ok
37 Correct 36 ms 48876 KB Ok
38 Correct 35 ms 48876 KB Ok
39 Correct 32 ms 48876 KB Ok
40 Correct 35 ms 48876 KB Ok
41 Correct 39 ms 48876 KB Ok
42 Correct 38 ms 48876 KB Ok
43 Correct 37 ms 48876 KB Ok
44 Correct 47 ms 49132 KB Ok
45 Correct 51 ms 49260 KB Ok
46 Correct 47 ms 49132 KB Ok
47 Correct 46 ms 49132 KB Ok
48 Correct 45 ms 49132 KB Ok
49 Correct 47 ms 49132 KB Ok
50 Correct 47 ms 49132 KB Ok
51 Correct 46 ms 49132 KB Ok
52 Correct 48 ms 49260 KB Ok
53 Correct 47 ms 49132 KB Ok
54 Correct 167 ms 50924 KB Ok
55 Correct 210 ms 51436 KB Ok
56 Correct 194 ms 51308 KB Ok
57 Correct 140 ms 50540 KB Ok
58 Correct 179 ms 50924 KB Ok
59 Correct 170 ms 50796 KB Ok
60 Correct 140 ms 50540 KB Ok
61 Correct 146 ms 50540 KB Ok
62 Correct 228 ms 51308 KB Ok
63 Correct 151 ms 50796 KB Ok
64 Correct 206 ms 51308 KB Ok
65 Correct 193 ms 51180 KB Ok
66 Correct 163 ms 50944 KB Ok
67 Correct 130 ms 50648 KB Ok
68 Correct 177 ms 50796 KB Ok
69 Correct 241 ms 56812 KB Ok
70 Correct 252 ms 57288 KB Ok
71 Correct 245 ms 56940 KB Ok
72 Correct 258 ms 56556 KB Ok
73 Correct 263 ms 56912 KB Ok
74 Correct 259 ms 56812 KB Ok
75 Correct 252 ms 56672 KB Ok
76 Correct 247 ms 56940 KB Ok
77 Correct 255 ms 56708 KB Ok
78 Correct 251 ms 56684 KB Ok
79 Correct 249 ms 57068 KB Ok
80 Correct 246 ms 57196 KB Ok
81 Correct 257 ms 57068 KB Ok
82 Correct 247 ms 56928 KB Ok
83 Correct 256 ms 57068 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47340 KB Ok
2 Correct 27 ms 47340 KB Ok
3 Correct 28 ms 47340 KB Ok
4 Correct 28 ms 47340 KB Ok
5 Correct 27 ms 47356 KB Ok
6 Correct 27 ms 47340 KB Ok
7 Correct 28 ms 47344 KB Ok
8 Correct 28 ms 47340 KB Ok
9 Correct 28 ms 47340 KB Ok
10 Correct 28 ms 47340 KB Ok
11 Correct 28 ms 47340 KB Ok
12 Correct 28 ms 47340 KB Ok
13 Correct 34 ms 48876 KB Ok
14 Correct 34 ms 48876 KB Ok
15 Correct 35 ms 48876 KB Ok
16 Correct 35 ms 48876 KB Ok
17 Correct 34 ms 48876 KB Ok
18 Correct 37 ms 49020 KB Ok
19 Correct 48 ms 49516 KB Ok
20 Correct 40 ms 49132 KB Ok
21 Correct 46 ms 49644 KB Ok
22 Correct 40 ms 49260 KB Ok
23 Correct 29 ms 49004 KB Ok
24 Correct 28 ms 47340 KB Ok
25 Correct 34 ms 48896 KB Ok
26 Correct 36 ms 48876 KB Ok
27 Correct 44 ms 48876 KB Ok
28 Correct 37 ms 48876 KB Ok
29 Correct 36 ms 48876 KB Ok
30 Correct 38 ms 48876 KB Ok
31 Correct 36 ms 48876 KB Ok
32 Correct 37 ms 48876 KB Ok
33 Correct 37 ms 48876 KB Ok
34 Correct 39 ms 48876 KB Ok
35 Correct 41 ms 48876 KB Ok
36 Correct 41 ms 48876 KB Ok
37 Correct 41 ms 48876 KB Ok
38 Correct 45 ms 48876 KB Ok
39 Correct 210 ms 55788 KB Ok
40 Correct 187 ms 54508 KB Ok
41 Correct 346 ms 58476 KB Ok
42 Correct 257 ms 57708 KB Ok
43 Correct 166 ms 53484 KB Ok
44 Correct 260 ms 57196 KB Ok
45 Correct 35 ms 48876 KB Ok
46 Correct 37 ms 49004 KB Ok
47 Correct 36 ms 49004 KB Ok
48 Correct 36 ms 48876 KB Ok
49 Correct 35 ms 48876 KB Ok
50 Correct 32 ms 48876 KB Ok
51 Correct 35 ms 48876 KB Ok
52 Correct 39 ms 48876 KB Ok
53 Correct 38 ms 48876 KB Ok
54 Correct 37 ms 48876 KB Ok
55 Correct 47 ms 49132 KB Ok
56 Correct 51 ms 49260 KB Ok
57 Correct 47 ms 49132 KB Ok
58 Correct 46 ms 49132 KB Ok
59 Correct 45 ms 49132 KB Ok
60 Correct 47 ms 49132 KB Ok
61 Correct 47 ms 49132 KB Ok
62 Correct 46 ms 49132 KB Ok
63 Correct 48 ms 49260 KB Ok
64 Correct 47 ms 49132 KB Ok
65 Correct 167 ms 50924 KB Ok
66 Correct 210 ms 51436 KB Ok
67 Correct 194 ms 51308 KB Ok
68 Correct 140 ms 50540 KB Ok
69 Correct 179 ms 50924 KB Ok
70 Correct 170 ms 50796 KB Ok
71 Correct 140 ms 50540 KB Ok
72 Correct 146 ms 50540 KB Ok
73 Correct 228 ms 51308 KB Ok
74 Correct 151 ms 50796 KB Ok
75 Correct 206 ms 51308 KB Ok
76 Correct 193 ms 51180 KB Ok
77 Correct 163 ms 50944 KB Ok
78 Correct 130 ms 50648 KB Ok
79 Correct 177 ms 50796 KB Ok
80 Correct 241 ms 56812 KB Ok
81 Correct 252 ms 57288 KB Ok
82 Correct 245 ms 56940 KB Ok
83 Correct 258 ms 56556 KB Ok
84 Correct 263 ms 56912 KB Ok
85 Correct 259 ms 56812 KB Ok
86 Correct 252 ms 56672 KB Ok
87 Correct 247 ms 56940 KB Ok
88 Correct 255 ms 56708 KB Ok
89 Correct 251 ms 56684 KB Ok
90 Correct 249 ms 57068 KB Ok
91 Correct 246 ms 57196 KB Ok
92 Correct 257 ms 57068 KB Ok
93 Correct 247 ms 56928 KB Ok
94 Correct 256 ms 57068 KB Ok
95 Correct 249 ms 54092 KB Ok
96 Correct 512 ms 57068 KB Ok
97 Correct 563 ms 55916 KB Ok
98 Correct 306 ms 54252 KB Ok
99 Correct 445 ms 55532 KB Ok
100 Correct 533 ms 56044 KB Ok
101 Correct 505 ms 55404 KB Ok
102 Correct 433 ms 55916 KB Ok
103 Correct 445 ms 55916 KB Ok
104 Correct 567 ms 57068 KB Ok
105 Correct 574 ms 56812 KB Ok
106 Correct 354 ms 55916 KB Ok
107 Correct 490 ms 56004 KB Ok
108 Correct 588 ms 56948 KB Ok
109 Correct 440 ms 56556 KB Ok
110 Correct 1014 ms 83100 KB Ok
111 Correct 982 ms 84588 KB Ok
112 Correct 1016 ms 85868 KB Ok
113 Correct 1004 ms 83692 KB Ok
114 Correct 1018 ms 86124 KB Ok
115 Correct 1014 ms 84588 KB Ok
116 Correct 1044 ms 85740 KB Ok
117 Correct 1002 ms 83624 KB Ok
118 Correct 1033 ms 85480 KB Ok
119 Correct 1024 ms 83308 KB Ok
120 Correct 1022 ms 84028 KB Ok
121 Correct 1022 ms 84204 KB Ok
122 Correct 995 ms 84716 KB Ok
123 Correct 1006 ms 84588 KB Ok
124 Correct 1024 ms 84736 KB Ok
125 Correct 1150 ms 67052 KB Ok