답안 #1116256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116256 2024-11-21T11:41:21 Z KK_1729 Nice sequence (IZhO18_sequence) C++17
100 / 100
1328 ms 56708 KB
#include <bits/stdc++.h>
using namespace std;

// #define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"

void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}

vector<int> possible(int x, int n, int m){
    vector<vector<int>> graph(x+1); // edge from i to j iff pref[i] < pref[j]
    vector<int> indeg(x+1);
    for (int i = m; i <= x; ++i){
        graph[i-m].pb(i);
        indeg[i] = 1;
    }

    for (int i = n; i <= x; ++i){
        graph[i].pb(i-n);
        indeg[i-n] = 1;
    }

    int val = 1;
    vector<int> visited(x+1);
    vector<int> prefix(x+1);
    stack<int> s;
    FOR(i,0,x+1){
        if (indeg[i] == 0){
            s.push(i);
        }
    }
    if (s.empty()){
        return {};
    }
        while (!s.empty()){
            int current = s.top();
            s.pop();
            if (visited[current]){
                return {};
            }
            prefix[current] = val;
            val++;
            for (auto item: graph[current]){
                s.push(item);
            }
            visited[current] = 1;
        }

    FOR(i,0,x+1){
        if (!visited[i]) return {};
    }
    
    return prefix;
}
void solve(){
    int n, m; cin >> n >> m;

    int l = 0; int r = 500000;
    vector<int> best = possible(n+m-__gcd(n, m)-1, n, m);
    

    cout << best.size()-1 << endl;
    FOR(i,1,best.size()) cout << best[i]-best[i-1] << " ";
    cout << endl;
}
int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t = 1; cin >> t;
    while (t--) solve();
}

Compilation message

sequence.cpp: In function 'void solve()':
sequence.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
sequence.cpp:68:5: note: in expansion of macro 'FOR'
   68 |     FOR(i,1,best.size()) cout << best[i]-best[i-1] << " ";
      |     ^~~
sequence.cpp:63:9: warning: unused variable 'l' [-Wunused-variable]
   63 |     int l = 0; int r = 500000;
      |         ^
sequence.cpp:63:20: warning: unused variable 'r' [-Wunused-variable]
   63 |     int l = 0; int r = 500000;
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 508 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 508 KB Ok
12 Correct 1 ms 336 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 2 ms 592 KB Ok
7 Correct 8 ms 1428 KB Ok
8 Correct 5 ms 848 KB Ok
9 Correct 10 ms 1636 KB Ok
10 Correct 7 ms 1136 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 504 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 336 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 336 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 504 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 108 ms 14568 KB Ok
7 Correct 76 ms 13760 KB Ok
8 Correct 129 ms 19300 KB Ok
9 Correct 109 ms 17176 KB Ok
10 Correct 66 ms 9768 KB Ok
11 Correct 111 ms 17152 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 508 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 508 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 336 KB Ok
14 Correct 1 ms 504 KB Ok
15 Correct 1 ms 336 KB Ok
16 Correct 1 ms 336 KB Ok
17 Correct 1 ms 336 KB Ok
18 Correct 1 ms 336 KB Ok
19 Correct 1 ms 336 KB Ok
20 Correct 1 ms 336 KB Ok
21 Correct 1 ms 336 KB Ok
22 Correct 1 ms 336 KB Ok
23 Correct 1 ms 336 KB Ok
24 Correct 3 ms 592 KB Ok
25 Correct 2 ms 592 KB Ok
26 Correct 3 ms 592 KB Ok
27 Correct 2 ms 592 KB Ok
28 Correct 2 ms 592 KB Ok
29 Correct 3 ms 592 KB Ok
30 Correct 2 ms 592 KB Ok
31 Correct 3 ms 592 KB Ok
32 Correct 3 ms 592 KB Ok
33 Correct 2 ms 592 KB Ok
34 Correct 5 ms 848 KB Ok
35 Correct 5 ms 848 KB Ok
36 Correct 4 ms 848 KB Ok
37 Correct 4 ms 848 KB Ok
38 Correct 4 ms 848 KB Ok
39 Correct 4 ms 848 KB Ok
40 Correct 5 ms 848 KB Ok
41 Correct 5 ms 848 KB Ok
42 Correct 4 ms 848 KB Ok
43 Correct 4 ms 848 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 508 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 508 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 504 KB Ok
14 Correct 1 ms 336 KB Ok
15 Correct 1 ms 336 KB Ok
16 Correct 1 ms 336 KB Ok
17 Correct 1 ms 336 KB Ok
18 Correct 2 ms 592 KB Ok
19 Correct 8 ms 1428 KB Ok
20 Correct 5 ms 848 KB Ok
21 Correct 10 ms 1636 KB Ok
22 Correct 7 ms 1136 KB Ok
23 Correct 1 ms 336 KB Ok
24 Correct 1 ms 504 KB Ok
25 Correct 1 ms 336 KB Ok
26 Correct 1 ms 336 KB Ok
27 Correct 1 ms 336 KB Ok
28 Correct 1 ms 336 KB Ok
29 Correct 1 ms 336 KB Ok
30 Correct 1 ms 336 KB Ok
31 Correct 1 ms 336 KB Ok
32 Correct 1 ms 336 KB Ok
33 Correct 1 ms 336 KB Ok
34 Correct 3 ms 592 KB Ok
35 Correct 2 ms 592 KB Ok
36 Correct 3 ms 592 KB Ok
37 Correct 2 ms 592 KB Ok
38 Correct 2 ms 592 KB Ok
39 Correct 3 ms 592 KB Ok
40 Correct 2 ms 592 KB Ok
41 Correct 3 ms 592 KB Ok
42 Correct 3 ms 592 KB Ok
43 Correct 2 ms 592 KB Ok
44 Correct 5 ms 848 KB Ok
45 Correct 5 ms 848 KB Ok
46 Correct 4 ms 848 KB Ok
47 Correct 4 ms 848 KB Ok
48 Correct 4 ms 848 KB Ok
49 Correct 4 ms 848 KB Ok
50 Correct 5 ms 848 KB Ok
51 Correct 5 ms 848 KB Ok
52 Correct 4 ms 848 KB Ok
53 Correct 4 ms 848 KB Ok
54 Correct 63 ms 8928 KB Ok
55 Correct 83 ms 9484 KB Ok
56 Correct 77 ms 9600 KB Ok
57 Correct 54 ms 7168 KB Ok
58 Correct 64 ms 8784 KB Ok
59 Correct 65 ms 7548 KB Ok
60 Correct 57 ms 7812 KB Ok
61 Correct 59 ms 8476 KB Ok
62 Correct 82 ms 8640 KB Ok
63 Correct 63 ms 8156 KB Ok
64 Correct 85 ms 9660 KB Ok
65 Correct 71 ms 10544 KB Ok
66 Correct 61 ms 8040 KB Ok
67 Correct 52 ms 8420 KB Ok
68 Correct 69 ms 9412 KB Ok
69 Correct 129 ms 13192 KB Ok
70 Correct 131 ms 13640 KB Ok
71 Correct 130 ms 13704 KB Ok
72 Correct 126 ms 12940 KB Ok
73 Correct 143 ms 13460 KB Ok
74 Correct 132 ms 13624 KB Ok
75 Correct 134 ms 13188 KB Ok
76 Correct 140 ms 13200 KB Ok
77 Correct 134 ms 13476 KB Ok
78 Correct 124 ms 12960 KB Ok
79 Correct 137 ms 13448 KB Ok
80 Correct 136 ms 13548 KB Ok
81 Correct 137 ms 13476 KB Ok
82 Correct 135 ms 13600 KB Ok
83 Correct 135 ms 13624 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Ok
2 Correct 1 ms 336 KB Ok
3 Correct 1 ms 336 KB Ok
4 Correct 1 ms 336 KB Ok
5 Correct 1 ms 336 KB Ok
6 Correct 1 ms 508 KB Ok
7 Correct 1 ms 336 KB Ok
8 Correct 1 ms 336 KB Ok
9 Correct 1 ms 336 KB Ok
10 Correct 1 ms 336 KB Ok
11 Correct 1 ms 508 KB Ok
12 Correct 1 ms 336 KB Ok
13 Correct 1 ms 504 KB Ok
14 Correct 1 ms 336 KB Ok
15 Correct 1 ms 336 KB Ok
16 Correct 1 ms 336 KB Ok
17 Correct 1 ms 336 KB Ok
18 Correct 2 ms 592 KB Ok
19 Correct 8 ms 1428 KB Ok
20 Correct 5 ms 848 KB Ok
21 Correct 10 ms 1636 KB Ok
22 Correct 7 ms 1136 KB Ok
23 Correct 1 ms 336 KB Ok
24 Correct 1 ms 504 KB Ok
25 Correct 1 ms 336 KB Ok
26 Correct 1 ms 336 KB Ok
27 Correct 1 ms 336 KB Ok
28 Correct 1 ms 336 KB Ok
29 Correct 1 ms 336 KB Ok
30 Correct 1 ms 336 KB Ok
31 Correct 1 ms 336 KB Ok
32 Correct 1 ms 336 KB Ok
33 Correct 1 ms 336 KB Ok
34 Correct 1 ms 336 KB Ok
35 Correct 1 ms 336 KB Ok
36 Correct 1 ms 504 KB Ok
37 Correct 1 ms 336 KB Ok
38 Correct 1 ms 336 KB Ok
39 Correct 108 ms 14568 KB Ok
40 Correct 76 ms 13760 KB Ok
41 Correct 129 ms 19300 KB Ok
42 Correct 109 ms 17176 KB Ok
43 Correct 66 ms 9768 KB Ok
44 Correct 111 ms 17152 KB Ok
45 Correct 3 ms 592 KB Ok
46 Correct 2 ms 592 KB Ok
47 Correct 3 ms 592 KB Ok
48 Correct 2 ms 592 KB Ok
49 Correct 2 ms 592 KB Ok
50 Correct 3 ms 592 KB Ok
51 Correct 2 ms 592 KB Ok
52 Correct 3 ms 592 KB Ok
53 Correct 3 ms 592 KB Ok
54 Correct 2 ms 592 KB Ok
55 Correct 5 ms 848 KB Ok
56 Correct 5 ms 848 KB Ok
57 Correct 4 ms 848 KB Ok
58 Correct 4 ms 848 KB Ok
59 Correct 4 ms 848 KB Ok
60 Correct 4 ms 848 KB Ok
61 Correct 5 ms 848 KB Ok
62 Correct 5 ms 848 KB Ok
63 Correct 4 ms 848 KB Ok
64 Correct 4 ms 848 KB Ok
65 Correct 63 ms 8928 KB Ok
66 Correct 83 ms 9484 KB Ok
67 Correct 77 ms 9600 KB Ok
68 Correct 54 ms 7168 KB Ok
69 Correct 64 ms 8784 KB Ok
70 Correct 65 ms 7548 KB Ok
71 Correct 57 ms 7812 KB Ok
72 Correct 59 ms 8476 KB Ok
73 Correct 82 ms 8640 KB Ok
74 Correct 63 ms 8156 KB Ok
75 Correct 85 ms 9660 KB Ok
76 Correct 71 ms 10544 KB Ok
77 Correct 61 ms 8040 KB Ok
78 Correct 52 ms 8420 KB Ok
79 Correct 69 ms 9412 KB Ok
80 Correct 129 ms 13192 KB Ok
81 Correct 131 ms 13640 KB Ok
82 Correct 130 ms 13704 KB Ok
83 Correct 126 ms 12940 KB Ok
84 Correct 143 ms 13460 KB Ok
85 Correct 132 ms 13624 KB Ok
86 Correct 134 ms 13188 KB Ok
87 Correct 140 ms 13200 KB Ok
88 Correct 134 ms 13476 KB Ok
89 Correct 124 ms 12960 KB Ok
90 Correct 137 ms 13448 KB Ok
91 Correct 136 ms 13548 KB Ok
92 Correct 137 ms 13476 KB Ok
93 Correct 135 ms 13600 KB Ok
94 Correct 135 ms 13624 KB Ok
95 Correct 158 ms 22152 KB Ok
96 Correct 213 ms 31652 KB Ok
97 Correct 222 ms 26276 KB Ok
98 Correct 154 ms 22252 KB Ok
99 Correct 189 ms 24552 KB Ok
100 Correct 201 ms 25012 KB Ok
101 Correct 201 ms 27508 KB Ok
102 Correct 200 ms 27452 KB Ok
103 Correct 207 ms 29028 KB Ok
104 Correct 244 ms 31252 KB Ok
105 Correct 253 ms 32576 KB Ok
106 Correct 246 ms 28872 KB Ok
107 Correct 213 ms 31732 KB Ok
108 Correct 281 ms 32432 KB Ok
109 Correct 241 ms 31140 KB Ok
110 Correct 1064 ms 54500 KB Ok
111 Correct 964 ms 54700 KB Ok
112 Correct 936 ms 56584 KB Ok
113 Correct 987 ms 54316 KB Ok
114 Correct 933 ms 56536 KB Ok
115 Correct 846 ms 55144 KB Ok
116 Correct 1116 ms 56216 KB Ok
117 Correct 1251 ms 53820 KB Ok
118 Correct 1328 ms 56708 KB Ok
119 Correct 1045 ms 53444 KB Ok
120 Correct 1208 ms 54824 KB Ok
121 Correct 1006 ms 55160 KB Ok
122 Correct 775 ms 55228 KB Ok
123 Correct 1000 ms 54840 KB Ok
124 Correct 1012 ms 56420 KB Ok
125 Correct 359 ms 36936 KB Ok