답안 #91324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91324 2018-12-27T06:08:30 Z toloraia Nice sequence (IZhO18_sequence) C++14
100 / 100
1224 ms 40108 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;
const int N = 1e6 + 5, NN = 4e5;

int F[N];
int n, m, M;
bool ok;

void dfs (int k, int p){
    //cout<<k<<" "<<p<<" "<<M<<" "<<n<<" "<<m<<" "<<F[k]<<endl;
    if (ok == 0)
        return;
    if (F[k] == p){
        ok = 0;
        return;
    }
    if (F[k])
        return;
    F[k] = p;
    if (k + m <= M)
        dfs (k + m, p);
    if (k - n >= 0)
        dfs (k - n, p);
}

int nn;
int a[N], b[N];

void go (int k){
    if (F[k])
        return;
    F[k] = 1;
    if (k + n <= M)
        go (k + n);
    if (k - m >= 0)
        go (k - m);
    a[++nn] = k;
}

int main()
{
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while (T--){
        cin>>n>>m;
        int l = 0, r = NN;
        while (l < r){
            M = (l + r + 1) / 2;
            ok = 1;
            for (int i = 0; i <= M; i++)
                F[i] = 0;
            for (int i = 0; i <= M && ok == 1; i++)
                if (F[i] == 0)
                    dfs (i, i + 1);
            if (ok)
                l = M;
            else
                r = M - 1;
            //cout<<M<<" "<<ok<<endl;
        }
        M = l;
        nn = -1;
        for (int i = 0; i <= M; i++)
            F[i] = 0;
        for (int i = 0; i <= M; i++)
            if (F[i] == 0)
                go (i);
        for (int i = 0; i <= M; i++)
            b[a[i]] = i;
        cout<<M<<endl;
        for (int i = 1; i <= M; i++)
            cout<<b[i] - b[i - 1]<<" ";
        cout<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 7416 KB Ok
2 Correct 26 ms 7540 KB Ok
3 Correct 6 ms 7540 KB Ok
4 Correct 5 ms 7540 KB Ok
5 Correct 5 ms 7540 KB Ok
6 Correct 6 ms 7540 KB Ok
7 Correct 5 ms 7540 KB Ok
8 Correct 6 ms 7540 KB Ok
9 Correct 5 ms 7540 KB Ok
10 Correct 5 ms 7540 KB Ok
11 Correct 5 ms 7540 KB Ok
12 Correct 5 ms 7540 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 7540 KB Ok
2 Correct 19 ms 7540 KB Ok
3 Correct 14 ms 7540 KB Ok
4 Correct 17 ms 7540 KB Ok
5 Correct 15 ms 7540 KB Ok
6 Correct 16 ms 7540 KB Ok
7 Correct 24 ms 7540 KB Ok
8 Correct 29 ms 7540 KB Ok
9 Correct 35 ms 7540 KB Ok
10 Correct 20 ms 7540 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7708 KB Ok
2 Correct 31 ms 7836 KB Ok
3 Correct 22 ms 7836 KB Ok
4 Correct 20 ms 7836 KB Ok
5 Correct 13 ms 7836 KB Ok
6 Correct 15 ms 7836 KB Ok
7 Correct 12 ms 7836 KB Ok
8 Correct 12 ms 7836 KB Ok
9 Correct 12 ms 7836 KB Ok
10 Correct 19 ms 7836 KB Ok
11 Correct 17 ms 7836 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7836 KB Ok
2 Correct 9 ms 7836 KB Ok
3 Correct 7 ms 7836 KB Ok
4 Correct 6 ms 7836 KB Ok
5 Correct 6 ms 7836 KB Ok
6 Correct 130 ms 8492 KB Ok
7 Correct 111 ms 8492 KB Ok
8 Correct 215 ms 11256 KB Ok
9 Correct 158 ms 11256 KB Ok
10 Correct 92 ms 11256 KB Ok
11 Correct 147 ms 11256 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 7416 KB Ok
2 Correct 26 ms 7540 KB Ok
3 Correct 6 ms 7540 KB Ok
4 Correct 5 ms 7540 KB Ok
5 Correct 5 ms 7540 KB Ok
6 Correct 6 ms 7540 KB Ok
7 Correct 5 ms 7540 KB Ok
8 Correct 6 ms 7540 KB Ok
9 Correct 5 ms 7540 KB Ok
10 Correct 5 ms 7540 KB Ok
11 Correct 5 ms 7540 KB Ok
12 Correct 5 ms 7540 KB Ok
13 Correct 15 ms 7708 KB Ok
14 Correct 31 ms 7836 KB Ok
15 Correct 22 ms 7836 KB Ok
16 Correct 20 ms 7836 KB Ok
17 Correct 13 ms 7836 KB Ok
18 Correct 15 ms 7836 KB Ok
19 Correct 12 ms 7836 KB Ok
20 Correct 12 ms 7836 KB Ok
21 Correct 12 ms 7836 KB Ok
22 Correct 19 ms 7836 KB Ok
23 Correct 17 ms 7836 KB Ok
24 Correct 6 ms 11256 KB Ok
25 Correct 5 ms 11256 KB Ok
26 Correct 6 ms 11256 KB Ok
27 Correct 6 ms 11256 KB Ok
28 Correct 6 ms 11256 KB Ok
29 Correct 6 ms 11256 KB Ok
30 Correct 6 ms 11256 KB Ok
31 Correct 6 ms 11256 KB Ok
32 Correct 6 ms 11256 KB Ok
33 Correct 6 ms 11256 KB Ok
34 Correct 8 ms 11256 KB Ok
35 Correct 9 ms 11256 KB Ok
36 Correct 9 ms 11256 KB Ok
37 Correct 9 ms 11256 KB Ok
38 Correct 9 ms 11256 KB Ok
39 Correct 9 ms 11256 KB Ok
40 Correct 10 ms 11256 KB Ok
41 Correct 9 ms 11256 KB Ok
42 Correct 8 ms 11256 KB Ok
43 Correct 10 ms 11256 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 7416 KB Ok
2 Correct 26 ms 7540 KB Ok
3 Correct 6 ms 7540 KB Ok
4 Correct 5 ms 7540 KB Ok
5 Correct 5 ms 7540 KB Ok
6 Correct 6 ms 7540 KB Ok
7 Correct 5 ms 7540 KB Ok
8 Correct 6 ms 7540 KB Ok
9 Correct 5 ms 7540 KB Ok
10 Correct 5 ms 7540 KB Ok
11 Correct 5 ms 7540 KB Ok
12 Correct 5 ms 7540 KB Ok
13 Correct 18 ms 7540 KB Ok
14 Correct 19 ms 7540 KB Ok
15 Correct 14 ms 7540 KB Ok
16 Correct 17 ms 7540 KB Ok
17 Correct 15 ms 7540 KB Ok
18 Correct 16 ms 7540 KB Ok
19 Correct 24 ms 7540 KB Ok
20 Correct 29 ms 7540 KB Ok
21 Correct 35 ms 7540 KB Ok
22 Correct 20 ms 7540 KB Ok
23 Correct 15 ms 7708 KB Ok
24 Correct 31 ms 7836 KB Ok
25 Correct 22 ms 7836 KB Ok
26 Correct 20 ms 7836 KB Ok
27 Correct 13 ms 7836 KB Ok
28 Correct 15 ms 7836 KB Ok
29 Correct 12 ms 7836 KB Ok
30 Correct 12 ms 7836 KB Ok
31 Correct 12 ms 7836 KB Ok
32 Correct 19 ms 7836 KB Ok
33 Correct 17 ms 7836 KB Ok
34 Correct 6 ms 11256 KB Ok
35 Correct 5 ms 11256 KB Ok
36 Correct 6 ms 11256 KB Ok
37 Correct 6 ms 11256 KB Ok
38 Correct 6 ms 11256 KB Ok
39 Correct 6 ms 11256 KB Ok
40 Correct 6 ms 11256 KB Ok
41 Correct 6 ms 11256 KB Ok
42 Correct 6 ms 11256 KB Ok
43 Correct 6 ms 11256 KB Ok
44 Correct 8 ms 11256 KB Ok
45 Correct 9 ms 11256 KB Ok
46 Correct 9 ms 11256 KB Ok
47 Correct 9 ms 11256 KB Ok
48 Correct 9 ms 11256 KB Ok
49 Correct 9 ms 11256 KB Ok
50 Correct 10 ms 11256 KB Ok
51 Correct 9 ms 11256 KB Ok
52 Correct 8 ms 11256 KB Ok
53 Correct 10 ms 11256 KB Ok
54 Correct 76 ms 11256 KB Ok
55 Correct 92 ms 11256 KB Ok
56 Correct 95 ms 11256 KB Ok
57 Correct 67 ms 11256 KB Ok
58 Correct 81 ms 11256 KB Ok
59 Correct 78 ms 11256 KB Ok
60 Correct 63 ms 11256 KB Ok
61 Correct 64 ms 11256 KB Ok
62 Correct 86 ms 11256 KB Ok
63 Correct 67 ms 11256 KB Ok
64 Correct 84 ms 11256 KB Ok
65 Correct 85 ms 11256 KB Ok
66 Correct 77 ms 11256 KB Ok
67 Correct 70 ms 11256 KB Ok
68 Correct 73 ms 11256 KB Ok
69 Correct 200 ms 11256 KB Ok
70 Correct 198 ms 11256 KB Ok
71 Correct 173 ms 11256 KB Ok
72 Correct 185 ms 11256 KB Ok
73 Correct 179 ms 11256 KB Ok
74 Correct 164 ms 11256 KB Ok
75 Correct 186 ms 11256 KB Ok
76 Correct 204 ms 11256 KB Ok
77 Correct 174 ms 11256 KB Ok
78 Correct 198 ms 11256 KB Ok
79 Correct 187 ms 11256 KB Ok
80 Correct 181 ms 11256 KB Ok
81 Correct 185 ms 11256 KB Ok
82 Correct 186 ms 11256 KB Ok
83 Correct 178 ms 11256 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 7416 KB Ok
2 Correct 26 ms 7540 KB Ok
3 Correct 6 ms 7540 KB Ok
4 Correct 5 ms 7540 KB Ok
5 Correct 5 ms 7540 KB Ok
6 Correct 6 ms 7540 KB Ok
7 Correct 5 ms 7540 KB Ok
8 Correct 6 ms 7540 KB Ok
9 Correct 5 ms 7540 KB Ok
10 Correct 5 ms 7540 KB Ok
11 Correct 5 ms 7540 KB Ok
12 Correct 5 ms 7540 KB Ok
13 Correct 18 ms 7540 KB Ok
14 Correct 19 ms 7540 KB Ok
15 Correct 14 ms 7540 KB Ok
16 Correct 17 ms 7540 KB Ok
17 Correct 15 ms 7540 KB Ok
18 Correct 16 ms 7540 KB Ok
19 Correct 24 ms 7540 KB Ok
20 Correct 29 ms 7540 KB Ok
21 Correct 35 ms 7540 KB Ok
22 Correct 20 ms 7540 KB Ok
23 Correct 15 ms 7708 KB Ok
24 Correct 31 ms 7836 KB Ok
25 Correct 22 ms 7836 KB Ok
26 Correct 20 ms 7836 KB Ok
27 Correct 13 ms 7836 KB Ok
28 Correct 15 ms 7836 KB Ok
29 Correct 12 ms 7836 KB Ok
30 Correct 12 ms 7836 KB Ok
31 Correct 12 ms 7836 KB Ok
32 Correct 19 ms 7836 KB Ok
33 Correct 17 ms 7836 KB Ok
34 Correct 14 ms 7836 KB Ok
35 Correct 9 ms 7836 KB Ok
36 Correct 7 ms 7836 KB Ok
37 Correct 6 ms 7836 KB Ok
38 Correct 6 ms 7836 KB Ok
39 Correct 130 ms 8492 KB Ok
40 Correct 111 ms 8492 KB Ok
41 Correct 215 ms 11256 KB Ok
42 Correct 158 ms 11256 KB Ok
43 Correct 92 ms 11256 KB Ok
44 Correct 147 ms 11256 KB Ok
45 Correct 6 ms 11256 KB Ok
46 Correct 5 ms 11256 KB Ok
47 Correct 6 ms 11256 KB Ok
48 Correct 6 ms 11256 KB Ok
49 Correct 6 ms 11256 KB Ok
50 Correct 6 ms 11256 KB Ok
51 Correct 6 ms 11256 KB Ok
52 Correct 6 ms 11256 KB Ok
53 Correct 6 ms 11256 KB Ok
54 Correct 6 ms 11256 KB Ok
55 Correct 8 ms 11256 KB Ok
56 Correct 9 ms 11256 KB Ok
57 Correct 9 ms 11256 KB Ok
58 Correct 9 ms 11256 KB Ok
59 Correct 9 ms 11256 KB Ok
60 Correct 9 ms 11256 KB Ok
61 Correct 10 ms 11256 KB Ok
62 Correct 9 ms 11256 KB Ok
63 Correct 8 ms 11256 KB Ok
64 Correct 10 ms 11256 KB Ok
65 Correct 76 ms 11256 KB Ok
66 Correct 92 ms 11256 KB Ok
67 Correct 95 ms 11256 KB Ok
68 Correct 67 ms 11256 KB Ok
69 Correct 81 ms 11256 KB Ok
70 Correct 78 ms 11256 KB Ok
71 Correct 63 ms 11256 KB Ok
72 Correct 64 ms 11256 KB Ok
73 Correct 86 ms 11256 KB Ok
74 Correct 67 ms 11256 KB Ok
75 Correct 84 ms 11256 KB Ok
76 Correct 85 ms 11256 KB Ok
77 Correct 77 ms 11256 KB Ok
78 Correct 70 ms 11256 KB Ok
79 Correct 73 ms 11256 KB Ok
80 Correct 200 ms 11256 KB Ok
81 Correct 198 ms 11256 KB Ok
82 Correct 173 ms 11256 KB Ok
83 Correct 185 ms 11256 KB Ok
84 Correct 179 ms 11256 KB Ok
85 Correct 164 ms 11256 KB Ok
86 Correct 186 ms 11256 KB Ok
87 Correct 204 ms 11256 KB Ok
88 Correct 174 ms 11256 KB Ok
89 Correct 198 ms 11256 KB Ok
90 Correct 187 ms 11256 KB Ok
91 Correct 181 ms 11256 KB Ok
92 Correct 185 ms 11256 KB Ok
93 Correct 186 ms 11256 KB Ok
94 Correct 178 ms 11256 KB Ok
95 Correct 195 ms 11256 KB Ok
96 Correct 291 ms 11256 KB Ok
97 Correct 273 ms 11256 KB Ok
98 Correct 202 ms 11256 KB Ok
99 Correct 263 ms 11256 KB Ok
100 Correct 253 ms 11256 KB Ok
101 Correct 269 ms 11256 KB Ok
102 Correct 245 ms 11256 KB Ok
103 Correct 240 ms 11256 KB Ok
104 Correct 289 ms 11256 KB Ok
105 Correct 254 ms 11256 KB Ok
106 Correct 237 ms 11256 KB Ok
107 Correct 277 ms 11256 KB Ok
108 Correct 289 ms 11256 KB Ok
109 Correct 262 ms 11256 KB Ok
110 Correct 845 ms 36492 KB Ok
111 Correct 1133 ms 38784 KB Ok
112 Correct 888 ms 38784 KB Ok
113 Correct 1128 ms 38784 KB Ok
114 Correct 1034 ms 40108 KB Ok
115 Correct 1115 ms 40108 KB Ok
116 Correct 1146 ms 40108 KB Ok
117 Correct 989 ms 40108 KB Ok
118 Correct 916 ms 40108 KB Ok
119 Correct 1148 ms 40108 KB Ok
120 Correct 1068 ms 40108 KB Ok
121 Correct 862 ms 40108 KB Ok
122 Correct 931 ms 40108 KB Ok
123 Correct 1224 ms 40108 KB Ok
124 Correct 738 ms 40108 KB Ok
125 Correct 682 ms 40108 KB Ok