답안 #338122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338122 2020-12-22T14:15:13 Z BeanZ Nice sequence (IZhO18_sequence) C++14
100 / 100
1964 ms 45668 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 1e6 + 50;
long long mod = 1e9 + 7;
const int lim = 700;
const int lg = 18;
const int base = 311;
const long double eps = 1e-6;
ll n, m;
vector<ll> topo;
bool vis[N];
ll id[N];
void dfs(ll u, ll mid){
    vis[u] = 1;
    if (u >= m && vis[u - m] == 0) dfs(u - m, mid);
    if ((u + n) <= mid && vis[u + n] == 0) dfs(u + n, mid);
    topo.push_back(u);
}
bool chk(ll mid){
    for (int i = 0; i <= mid; i++) vis[i] = 0;
    topo.clear();
    for (int i = 0; i <= mid; i++){
        if (vis[i]) continue;
        dfs(i, mid);
    }
    for (int i = 0; i < topo.size(); i++){
        id[topo[i]] = i;
    }
    for (int u = 0; u <= mid; u++){
        if (u >= m && id[u] < id[u - m]) return false;
        if ((u + n) <= mid && id[u] < id[u + n]) return false;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll t;
    cin >> t;
    while (t--){
        cin >> n >> m;
        ll l = 1, h = 4e5 + 1;
        while (l <= h){
            ll mid = (l + h) >> 1;
            if (chk(mid)) l = mid + 1;
            else h = mid - 1;
        }
        cout << h << endl;
        chk(h);
        for (int i = 1; i <= h; i++){
            cout << id[i] - id[i - 1] << " ";
        }
        cout << endl;
    }
}
/*
Ans:

Out:
*/

Compilation message

sequence.cpp: In function 'bool chk(int)':
sequence.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = 0; i < topo.size(); i++){
      |                     ~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   43 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 8552 KB Ok
2 Correct 75 ms 8552 KB Ok
3 Correct 53 ms 2664 KB Ok
4 Correct 53 ms 3176 KB Ok
5 Correct 54 ms 2664 KB Ok
6 Correct 60 ms 3816 KB Ok
7 Correct 56 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 54 ms 2664 KB Ok
10 Correct 56 ms 5352 KB Ok
11 Correct 54 ms 2536 KB Ok
12 Correct 51 ms 2408 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 8552 KB Ok
2 Correct 68 ms 8536 KB Ok
3 Correct 68 ms 8552 KB Ok
4 Correct 69 ms 8680 KB Ok
5 Correct 66 ms 8552 KB Ok
6 Correct 68 ms 8552 KB Ok
7 Correct 83 ms 8936 KB Ok
8 Correct 82 ms 8680 KB Ok
9 Correct 92 ms 8936 KB Ok
10 Correct 87 ms 8808 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 8552 KB Ok
2 Correct 69 ms 8552 KB Ok
3 Correct 65 ms 8552 KB Ok
4 Correct 77 ms 8552 KB Ok
5 Correct 78 ms 8552 KB Ok
6 Correct 76 ms 8552 KB Ok
7 Correct 73 ms 8552 KB Ok
8 Correct 80 ms 8552 KB Ok
9 Correct 71 ms 8552 KB Ok
10 Correct 79 ms 8552 KB Ok
11 Correct 74 ms 8552 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 8552 KB Ok
2 Correct 88 ms 8552 KB Ok
3 Correct 83 ms 8552 KB Ok
4 Correct 89 ms 8552 KB Ok
5 Correct 83 ms 8552 KB Ok
6 Correct 401 ms 12008 KB Ok
7 Correct 347 ms 10828 KB Ok
8 Correct 633 ms 14056 KB Ok
9 Correct 442 ms 13032 KB Ok
10 Correct 282 ms 9832 KB Ok
11 Correct 393 ms 12264 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 8552 KB Ok
2 Correct 75 ms 8552 KB Ok
3 Correct 53 ms 2664 KB Ok
4 Correct 53 ms 3176 KB Ok
5 Correct 54 ms 2664 KB Ok
6 Correct 60 ms 3816 KB Ok
7 Correct 56 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 54 ms 2664 KB Ok
10 Correct 56 ms 5352 KB Ok
11 Correct 54 ms 2536 KB Ok
12 Correct 51 ms 2408 KB Ok
13 Correct 26 ms 8552 KB Ok
14 Correct 69 ms 8552 KB Ok
15 Correct 65 ms 8552 KB Ok
16 Correct 77 ms 8552 KB Ok
17 Correct 78 ms 8552 KB Ok
18 Correct 76 ms 8552 KB Ok
19 Correct 73 ms 8552 KB Ok
20 Correct 80 ms 8552 KB Ok
21 Correct 71 ms 8552 KB Ok
22 Correct 79 ms 8552 KB Ok
23 Correct 74 ms 8552 KB Ok
24 Correct 65 ms 2280 KB Ok
25 Correct 64 ms 2408 KB Ok
26 Correct 73 ms 2664 KB Ok
27 Correct 62 ms 2792 KB Ok
28 Correct 64 ms 2408 KB Ok
29 Correct 61 ms 4492 KB Ok
30 Correct 64 ms 2536 KB Ok
31 Correct 67 ms 2408 KB Ok
32 Correct 66 ms 2280 KB Ok
33 Correct 68 ms 2792 KB Ok
34 Correct 85 ms 8680 KB Ok
35 Correct 92 ms 8680 KB Ok
36 Correct 90 ms 8808 KB Ok
37 Correct 99 ms 8680 KB Ok
38 Correct 90 ms 8680 KB Ok
39 Correct 84 ms 8680 KB Ok
40 Correct 99 ms 8600 KB Ok
41 Correct 93 ms 8680 KB Ok
42 Correct 89 ms 8680 KB Ok
43 Correct 90 ms 8680 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 8552 KB Ok
2 Correct 75 ms 8552 KB Ok
3 Correct 53 ms 2664 KB Ok
4 Correct 53 ms 3176 KB Ok
5 Correct 54 ms 2664 KB Ok
6 Correct 60 ms 3816 KB Ok
7 Correct 56 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 54 ms 2664 KB Ok
10 Correct 56 ms 5352 KB Ok
11 Correct 54 ms 2536 KB Ok
12 Correct 51 ms 2408 KB Ok
13 Correct 73 ms 8552 KB Ok
14 Correct 68 ms 8536 KB Ok
15 Correct 68 ms 8552 KB Ok
16 Correct 69 ms 8680 KB Ok
17 Correct 66 ms 8552 KB Ok
18 Correct 68 ms 8552 KB Ok
19 Correct 83 ms 8936 KB Ok
20 Correct 82 ms 8680 KB Ok
21 Correct 92 ms 8936 KB Ok
22 Correct 87 ms 8808 KB Ok
23 Correct 26 ms 8552 KB Ok
24 Correct 69 ms 8552 KB Ok
25 Correct 65 ms 8552 KB Ok
26 Correct 77 ms 8552 KB Ok
27 Correct 78 ms 8552 KB Ok
28 Correct 76 ms 8552 KB Ok
29 Correct 73 ms 8552 KB Ok
30 Correct 80 ms 8552 KB Ok
31 Correct 71 ms 8552 KB Ok
32 Correct 79 ms 8552 KB Ok
33 Correct 74 ms 8552 KB Ok
34 Correct 65 ms 2280 KB Ok
35 Correct 64 ms 2408 KB Ok
36 Correct 73 ms 2664 KB Ok
37 Correct 62 ms 2792 KB Ok
38 Correct 64 ms 2408 KB Ok
39 Correct 61 ms 4492 KB Ok
40 Correct 64 ms 2536 KB Ok
41 Correct 67 ms 2408 KB Ok
42 Correct 66 ms 2280 KB Ok
43 Correct 68 ms 2792 KB Ok
44 Correct 85 ms 8680 KB Ok
45 Correct 92 ms 8680 KB Ok
46 Correct 90 ms 8808 KB Ok
47 Correct 99 ms 8680 KB Ok
48 Correct 90 ms 8680 KB Ok
49 Correct 84 ms 8680 KB Ok
50 Correct 99 ms 8600 KB Ok
51 Correct 93 ms 8680 KB Ok
52 Correct 89 ms 8680 KB Ok
53 Correct 90 ms 8680 KB Ok
54 Correct 244 ms 3944 KB Ok
55 Correct 300 ms 4200 KB Ok
56 Correct 276 ms 4456 KB Ok
57 Correct 201 ms 3560 KB Ok
58 Correct 236 ms 3688 KB Ok
59 Correct 216 ms 3688 KB Ok
60 Correct 199 ms 3492 KB Ok
61 Correct 206 ms 3688 KB Ok
62 Correct 263 ms 4072 KB Ok
63 Correct 223 ms 3848 KB Ok
64 Correct 268 ms 4328 KB Ok
65 Correct 242 ms 4072 KB Ok
66 Correct 224 ms 3856 KB Ok
67 Correct 202 ms 3816 KB Ok
68 Correct 222 ms 3944 KB Ok
69 Correct 439 ms 14568 KB Ok
70 Correct 451 ms 15080 KB Ok
71 Correct 423 ms 14568 KB Ok
72 Correct 438 ms 14440 KB Ok
73 Correct 430 ms 14568 KB Ok
74 Correct 433 ms 14472 KB Ok
75 Correct 461 ms 14056 KB Ok
76 Correct 469 ms 14732 KB Ok
77 Correct 429 ms 13928 KB Ok
78 Correct 450 ms 14696 KB Ok
79 Correct 457 ms 14696 KB Ok
80 Correct 442 ms 14808 KB Ok
81 Correct 457 ms 14696 KB Ok
82 Correct 441 ms 14768 KB Ok
83 Correct 428 ms 14184 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 8552 KB Ok
2 Correct 75 ms 8552 KB Ok
3 Correct 53 ms 2664 KB Ok
4 Correct 53 ms 3176 KB Ok
5 Correct 54 ms 2664 KB Ok
6 Correct 60 ms 3816 KB Ok
7 Correct 56 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 54 ms 2664 KB Ok
10 Correct 56 ms 5352 KB Ok
11 Correct 54 ms 2536 KB Ok
12 Correct 51 ms 2408 KB Ok
13 Correct 73 ms 8552 KB Ok
14 Correct 68 ms 8536 KB Ok
15 Correct 68 ms 8552 KB Ok
16 Correct 69 ms 8680 KB Ok
17 Correct 66 ms 8552 KB Ok
18 Correct 68 ms 8552 KB Ok
19 Correct 83 ms 8936 KB Ok
20 Correct 82 ms 8680 KB Ok
21 Correct 92 ms 8936 KB Ok
22 Correct 87 ms 8808 KB Ok
23 Correct 26 ms 8552 KB Ok
24 Correct 69 ms 8552 KB Ok
25 Correct 65 ms 8552 KB Ok
26 Correct 77 ms 8552 KB Ok
27 Correct 78 ms 8552 KB Ok
28 Correct 76 ms 8552 KB Ok
29 Correct 73 ms 8552 KB Ok
30 Correct 80 ms 8552 KB Ok
31 Correct 71 ms 8552 KB Ok
32 Correct 79 ms 8552 KB Ok
33 Correct 74 ms 8552 KB Ok
34 Correct 77 ms 8552 KB Ok
35 Correct 88 ms 8552 KB Ok
36 Correct 83 ms 8552 KB Ok
37 Correct 89 ms 8552 KB Ok
38 Correct 83 ms 8552 KB Ok
39 Correct 401 ms 12008 KB Ok
40 Correct 347 ms 10828 KB Ok
41 Correct 633 ms 14056 KB Ok
42 Correct 442 ms 13032 KB Ok
43 Correct 282 ms 9832 KB Ok
44 Correct 393 ms 12264 KB Ok
45 Correct 65 ms 2280 KB Ok
46 Correct 64 ms 2408 KB Ok
47 Correct 73 ms 2664 KB Ok
48 Correct 62 ms 2792 KB Ok
49 Correct 64 ms 2408 KB Ok
50 Correct 61 ms 4492 KB Ok
51 Correct 64 ms 2536 KB Ok
52 Correct 67 ms 2408 KB Ok
53 Correct 66 ms 2280 KB Ok
54 Correct 68 ms 2792 KB Ok
55 Correct 85 ms 8680 KB Ok
56 Correct 92 ms 8680 KB Ok
57 Correct 90 ms 8808 KB Ok
58 Correct 99 ms 8680 KB Ok
59 Correct 90 ms 8680 KB Ok
60 Correct 84 ms 8680 KB Ok
61 Correct 99 ms 8600 KB Ok
62 Correct 93 ms 8680 KB Ok
63 Correct 89 ms 8680 KB Ok
64 Correct 90 ms 8680 KB Ok
65 Correct 244 ms 3944 KB Ok
66 Correct 300 ms 4200 KB Ok
67 Correct 276 ms 4456 KB Ok
68 Correct 201 ms 3560 KB Ok
69 Correct 236 ms 3688 KB Ok
70 Correct 216 ms 3688 KB Ok
71 Correct 199 ms 3492 KB Ok
72 Correct 206 ms 3688 KB Ok
73 Correct 263 ms 4072 KB Ok
74 Correct 223 ms 3848 KB Ok
75 Correct 268 ms 4328 KB Ok
76 Correct 242 ms 4072 KB Ok
77 Correct 224 ms 3856 KB Ok
78 Correct 202 ms 3816 KB Ok
79 Correct 222 ms 3944 KB Ok
80 Correct 439 ms 14568 KB Ok
81 Correct 451 ms 15080 KB Ok
82 Correct 423 ms 14568 KB Ok
83 Correct 438 ms 14440 KB Ok
84 Correct 430 ms 14568 KB Ok
85 Correct 433 ms 14472 KB Ok
86 Correct 461 ms 14056 KB Ok
87 Correct 469 ms 14732 KB Ok
88 Correct 429 ms 13928 KB Ok
89 Correct 450 ms 14696 KB Ok
90 Correct 457 ms 14696 KB Ok
91 Correct 442 ms 14808 KB Ok
92 Correct 457 ms 14696 KB Ok
93 Correct 441 ms 14768 KB Ok
94 Correct 428 ms 14184 KB Ok
95 Correct 504 ms 7396 KB Ok
96 Correct 779 ms 9500 KB Ok
97 Correct 712 ms 8292 KB Ok
98 Correct 515 ms 7652 KB Ok
99 Correct 648 ms 8036 KB Ok
100 Correct 686 ms 8164 KB Ok
101 Correct 700 ms 8420 KB Ok
102 Correct 669 ms 8192 KB Ok
103 Correct 656 ms 8676 KB Ok
104 Correct 794 ms 9644 KB Ok
105 Correct 772 ms 9312 KB Ok
106 Correct 654 ms 9060 KB Ok
107 Correct 695 ms 9060 KB Ok
108 Correct 787 ms 9444 KB Ok
109 Correct 740 ms 9600 KB Ok
110 Correct 1964 ms 41532 KB Ok
111 Correct 1963 ms 44348 KB Ok
112 Correct 1894 ms 44188 KB Ok
113 Correct 1901 ms 43748 KB Ok
114 Correct 1864 ms 45668 KB Ok
115 Correct 1896 ms 43344 KB Ok
116 Correct 1902 ms 44728 KB Ok
117 Correct 1907 ms 43364 KB Ok
118 Correct 1771 ms 43364 KB Ok
119 Correct 1941 ms 43268 KB Ok
120 Correct 1846 ms 43108 KB Ok
121 Correct 1825 ms 41828 KB Ok
122 Correct 1890 ms 44388 KB Ok
123 Correct 1891 ms 44324 KB Ok
124 Correct 1848 ms 41868 KB Ok
125 Correct 1757 ms 26704 KB Ok