답안 #308487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308487 2020-10-01T12:07:17 Z aZvezda Nice sequence (IZhO18_sequence) C++14
100 / 100
1445 ms 56424 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 4e5 + 10;
vector<int> g[MAX_N];
int used[MAX_N];
int n, m;
int arr[MAX_N], pref[MAX_N];

vector<int> top;

bool eval(int x) {
    top.resize(0);
    for(int i = 0; i <= x; i ++) {
        g[i].resize(0);
        used[i] = 0;
    }
    for(int i = 0; i <= x; i ++) {
        if(i + n <= x) {
            g[i + n].push_back(i);
            used[i] ++;
        }
        if(i - m >= 0) {
            g[i - m].push_back(i);
            used[i] ++;
        }
    }
    for(int i = 0; i <= x; i ++) {
        if(used[i] == 0) {
            top.push_back(i);
        }
    }
    int ind = 0;
    while(ind < top.size()) {
        auto curr = top[ind]; ind ++;
        for(auto it : g[curr]) {
            used[it] --;
            if(used[it] == 0) {
                top.push_back(it);
            }
        }
    }
    return top.size() == x + 1;
}

void build(int x) {
    for(int i = 0; i <= x; i ++) {
        pref[top[i]] = i;
    }
    for(int i = 0; i < x; i ++) {
        arr[i] = pref[i + 1] - pref[i];
    }
}

void solve() {
    cin >> n >> m;
    int l = n + m - __gcd(n, m) - 1;
    cout << l << endl;
    eval(l);
    build(l);
    for(int i = 0; i < l; i ++) {
        cout << arr[i] << " ";
    }
    cout << endl;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}

Compilation message

sequence.cpp: In function 'bool eval(int)':
sequence.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while(ind < top.size()) {
      |           ~~~~^~~~~~~~~~~~
sequence.cpp:54:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     return top.size() == x + 1;
      |            ~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 8 ms 9728 KB Ok
6 Correct 7 ms 9728 KB Ok
7 Correct 7 ms 9856 KB Ok
8 Correct 7 ms 9728 KB Ok
9 Correct 9 ms 9728 KB Ok
10 Correct 7 ms 9728 KB Ok
11 Correct 7 ms 9728 KB Ok
12 Correct 7 ms 9728 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 8 ms 9728 KB Ok
6 Correct 9 ms 9856 KB Ok
7 Correct 19 ms 10496 KB Ok
8 Correct 12 ms 10112 KB Ok
9 Correct 18 ms 10624 KB Ok
10 Correct 14 ms 10240 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 7 ms 9728 KB Ok
6 Correct 7 ms 9728 KB Ok
7 Correct 7 ms 9728 KB Ok
8 Correct 7 ms 9728 KB Ok
9 Correct 7 ms 9728 KB Ok
10 Correct 7 ms 9728 KB Ok
11 Correct 7 ms 9728 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 7 ms 9728 KB Ok
6 Correct 102 ms 20460 KB Ok
7 Correct 91 ms 21096 KB Ok
8 Correct 165 ms 23144 KB Ok
9 Correct 131 ms 22380 KB Ok
10 Correct 79 ms 16876 KB Ok
11 Correct 123 ms 22508 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 8 ms 9728 KB Ok
6 Correct 7 ms 9728 KB Ok
7 Correct 7 ms 9856 KB Ok
8 Correct 7 ms 9728 KB Ok
9 Correct 9 ms 9728 KB Ok
10 Correct 7 ms 9728 KB Ok
11 Correct 7 ms 9728 KB Ok
12 Correct 7 ms 9728 KB Ok
13 Correct 7 ms 9728 KB Ok
14 Correct 7 ms 9728 KB Ok
15 Correct 7 ms 9728 KB Ok
16 Correct 7 ms 9728 KB Ok
17 Correct 7 ms 9728 KB Ok
18 Correct 7 ms 9728 KB Ok
19 Correct 7 ms 9728 KB Ok
20 Correct 7 ms 9728 KB Ok
21 Correct 7 ms 9728 KB Ok
22 Correct 7 ms 9728 KB Ok
23 Correct 7 ms 9728 KB Ok
24 Correct 9 ms 9984 KB Ok
25 Correct 9 ms 9984 KB Ok
26 Correct 11 ms 9984 KB Ok
27 Correct 9 ms 9984 KB Ok
28 Correct 8 ms 9856 KB Ok
29 Correct 9 ms 9856 KB Ok
30 Correct 8 ms 9856 KB Ok
31 Correct 9 ms 9984 KB Ok
32 Correct 9 ms 9856 KB Ok
33 Correct 9 ms 9984 KB Ok
34 Correct 11 ms 9984 KB Ok
35 Correct 11 ms 10112 KB Ok
36 Correct 11 ms 10112 KB Ok
37 Correct 11 ms 10240 KB Ok
38 Correct 11 ms 10112 KB Ok
39 Correct 11 ms 10112 KB Ok
40 Correct 11 ms 10112 KB Ok
41 Correct 11 ms 10112 KB Ok
42 Correct 11 ms 10112 KB Ok
43 Correct 11 ms 10112 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 8 ms 9728 KB Ok
6 Correct 7 ms 9728 KB Ok
7 Correct 7 ms 9856 KB Ok
8 Correct 7 ms 9728 KB Ok
9 Correct 9 ms 9728 KB Ok
10 Correct 7 ms 9728 KB Ok
11 Correct 7 ms 9728 KB Ok
12 Correct 7 ms 9728 KB Ok
13 Correct 7 ms 9728 KB Ok
14 Correct 7 ms 9728 KB Ok
15 Correct 7 ms 9728 KB Ok
16 Correct 7 ms 9728 KB Ok
17 Correct 8 ms 9728 KB Ok
18 Correct 9 ms 9856 KB Ok
19 Correct 19 ms 10496 KB Ok
20 Correct 12 ms 10112 KB Ok
21 Correct 18 ms 10624 KB Ok
22 Correct 14 ms 10240 KB Ok
23 Correct 7 ms 9728 KB Ok
24 Correct 7 ms 9728 KB Ok
25 Correct 7 ms 9728 KB Ok
26 Correct 7 ms 9728 KB Ok
27 Correct 7 ms 9728 KB Ok
28 Correct 7 ms 9728 KB Ok
29 Correct 7 ms 9728 KB Ok
30 Correct 7 ms 9728 KB Ok
31 Correct 7 ms 9728 KB Ok
32 Correct 7 ms 9728 KB Ok
33 Correct 7 ms 9728 KB Ok
34 Correct 9 ms 9984 KB Ok
35 Correct 9 ms 9984 KB Ok
36 Correct 11 ms 9984 KB Ok
37 Correct 9 ms 9984 KB Ok
38 Correct 8 ms 9856 KB Ok
39 Correct 9 ms 9856 KB Ok
40 Correct 8 ms 9856 KB Ok
41 Correct 9 ms 9984 KB Ok
42 Correct 9 ms 9856 KB Ok
43 Correct 9 ms 9984 KB Ok
44 Correct 11 ms 9984 KB Ok
45 Correct 11 ms 10112 KB Ok
46 Correct 11 ms 10112 KB Ok
47 Correct 11 ms 10240 KB Ok
48 Correct 11 ms 10112 KB Ok
49 Correct 11 ms 10112 KB Ok
50 Correct 11 ms 10112 KB Ok
51 Correct 11 ms 10112 KB Ok
52 Correct 11 ms 10112 KB Ok
53 Correct 11 ms 10112 KB Ok
54 Correct 78 ms 15468 KB Ok
55 Correct 92 ms 15736 KB Ok
56 Correct 86 ms 15732 KB Ok
57 Correct 68 ms 14964 KB Ok
58 Correct 81 ms 15476 KB Ok
59 Correct 81 ms 15088 KB Ok
60 Correct 69 ms 14700 KB Ok
61 Correct 71 ms 15220 KB Ok
62 Correct 92 ms 15600 KB Ok
63 Correct 78 ms 14960 KB Ok
64 Correct 87 ms 15480 KB Ok
65 Correct 85 ms 15472 KB Ok
66 Correct 76 ms 15348 KB Ok
67 Correct 72 ms 15092 KB Ok
68 Correct 83 ms 15472 KB Ok
69 Correct 214 ms 19948 KB Ok
70 Correct 245 ms 21104 KB Ok
71 Correct 186 ms 19184 KB Ok
72 Correct 228 ms 20208 KB Ok
73 Correct 227 ms 19696 KB Ok
74 Correct 192 ms 18672 KB Ok
75 Correct 180 ms 18672 KB Ok
76 Correct 244 ms 20848 KB Ok
77 Correct 189 ms 18280 KB Ok
78 Correct 229 ms 20592 KB Ok
79 Correct 227 ms 19952 KB Ok
80 Correct 210 ms 19696 KB Ok
81 Correct 227 ms 20208 KB Ok
82 Correct 192 ms 19856 KB Ok
83 Correct 176 ms 18800 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Ok
2 Correct 7 ms 9728 KB Ok
3 Correct 7 ms 9728 KB Ok
4 Correct 7 ms 9728 KB Ok
5 Correct 8 ms 9728 KB Ok
6 Correct 7 ms 9728 KB Ok
7 Correct 7 ms 9856 KB Ok
8 Correct 7 ms 9728 KB Ok
9 Correct 9 ms 9728 KB Ok
10 Correct 7 ms 9728 KB Ok
11 Correct 7 ms 9728 KB Ok
12 Correct 7 ms 9728 KB Ok
13 Correct 7 ms 9728 KB Ok
14 Correct 7 ms 9728 KB Ok
15 Correct 7 ms 9728 KB Ok
16 Correct 7 ms 9728 KB Ok
17 Correct 8 ms 9728 KB Ok
18 Correct 9 ms 9856 KB Ok
19 Correct 19 ms 10496 KB Ok
20 Correct 12 ms 10112 KB Ok
21 Correct 18 ms 10624 KB Ok
22 Correct 14 ms 10240 KB Ok
23 Correct 7 ms 9728 KB Ok
24 Correct 7 ms 9728 KB Ok
25 Correct 7 ms 9728 KB Ok
26 Correct 7 ms 9728 KB Ok
27 Correct 7 ms 9728 KB Ok
28 Correct 7 ms 9728 KB Ok
29 Correct 7 ms 9728 KB Ok
30 Correct 7 ms 9728 KB Ok
31 Correct 7 ms 9728 KB Ok
32 Correct 7 ms 9728 KB Ok
33 Correct 7 ms 9728 KB Ok
34 Correct 7 ms 9728 KB Ok
35 Correct 7 ms 9728 KB Ok
36 Correct 7 ms 9728 KB Ok
37 Correct 7 ms 9728 KB Ok
38 Correct 7 ms 9728 KB Ok
39 Correct 102 ms 20460 KB Ok
40 Correct 91 ms 21096 KB Ok
41 Correct 165 ms 23144 KB Ok
42 Correct 131 ms 22380 KB Ok
43 Correct 79 ms 16876 KB Ok
44 Correct 123 ms 22508 KB Ok
45 Correct 9 ms 9984 KB Ok
46 Correct 9 ms 9984 KB Ok
47 Correct 11 ms 9984 KB Ok
48 Correct 9 ms 9984 KB Ok
49 Correct 8 ms 9856 KB Ok
50 Correct 9 ms 9856 KB Ok
51 Correct 8 ms 9856 KB Ok
52 Correct 9 ms 9984 KB Ok
53 Correct 9 ms 9856 KB Ok
54 Correct 9 ms 9984 KB Ok
55 Correct 11 ms 9984 KB Ok
56 Correct 11 ms 10112 KB Ok
57 Correct 11 ms 10112 KB Ok
58 Correct 11 ms 10240 KB Ok
59 Correct 11 ms 10112 KB Ok
60 Correct 11 ms 10112 KB Ok
61 Correct 11 ms 10112 KB Ok
62 Correct 11 ms 10112 KB Ok
63 Correct 11 ms 10112 KB Ok
64 Correct 11 ms 10112 KB Ok
65 Correct 78 ms 15468 KB Ok
66 Correct 92 ms 15736 KB Ok
67 Correct 86 ms 15732 KB Ok
68 Correct 68 ms 14964 KB Ok
69 Correct 81 ms 15476 KB Ok
70 Correct 81 ms 15088 KB Ok
71 Correct 69 ms 14700 KB Ok
72 Correct 71 ms 15220 KB Ok
73 Correct 92 ms 15600 KB Ok
74 Correct 78 ms 14960 KB Ok
75 Correct 87 ms 15480 KB Ok
76 Correct 85 ms 15472 KB Ok
77 Correct 76 ms 15348 KB Ok
78 Correct 72 ms 15092 KB Ok
79 Correct 83 ms 15472 KB Ok
80 Correct 214 ms 19948 KB Ok
81 Correct 245 ms 21104 KB Ok
82 Correct 186 ms 19184 KB Ok
83 Correct 228 ms 20208 KB Ok
84 Correct 227 ms 19696 KB Ok
85 Correct 192 ms 18672 KB Ok
86 Correct 180 ms 18672 KB Ok
87 Correct 244 ms 20848 KB Ok
88 Correct 189 ms 18280 KB Ok
89 Correct 229 ms 20592 KB Ok
90 Correct 227 ms 19952 KB Ok
91 Correct 210 ms 19696 KB Ok
92 Correct 227 ms 20208 KB Ok
93 Correct 192 ms 19856 KB Ok
94 Correct 176 ms 18800 KB Ok
95 Correct 187 ms 24660 KB Ok
96 Correct 267 ms 31336 KB Ok
97 Correct 256 ms 27664 KB Ok
98 Correct 200 ms 28008 KB Ok
99 Correct 239 ms 27364 KB Ok
100 Correct 241 ms 26600 KB Ok
101 Correct 250 ms 29968 KB Ok
102 Correct 230 ms 27624 KB Ok
103 Correct 229 ms 28772 KB Ok
104 Correct 275 ms 30440 KB Ok
105 Correct 264 ms 30948 KB Ok
106 Correct 216 ms 30952 KB Ok
107 Correct 248 ms 30348 KB Ok
108 Correct 277 ms 30752 KB Ok
109 Correct 255 ms 32100 KB Ok
110 Correct 892 ms 46568 KB Ok
111 Correct 1439 ms 56324 KB Ok
112 Correct 1038 ms 48800 KB Ok
113 Correct 1161 ms 52836 KB Ok
114 Correct 1181 ms 54244 KB Ok
115 Correct 1317 ms 53520 KB Ok
116 Correct 1228 ms 53352 KB Ok
117 Correct 1300 ms 54384 KB Ok
118 Correct 1043 ms 49508 KB Ok
119 Correct 1389 ms 55312 KB Ok
120 Correct 1059 ms 49748 KB Ok
121 Correct 1018 ms 48740 KB Ok
122 Correct 1069 ms 51556 KB Ok
123 Correct 1445 ms 56424 KB Ok
124 Correct 846 ms 45544 KB Ok
125 Correct 429 ms 38888 KB Ok