#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
for (auto a : x) cout << a << ' ';\
cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
vector <int> pre_ans;
bool ask(int n, int m, int N) {
vector <int> g[N + 1];
vector <int> in(N + 1, 0);
for (int i = 0; i + n <= N; ++i) {
g[i + n].pb(i);
in[i]++;
}
for (int i = 0; i + m <= N; ++i) {
g[i].pb(i + m);
in[i + m]++;
}
queue <int> q;
pre_ans.clear();
for (int i = 0; i <= N; ++i) if (!in[i]) q.push(i);
while (!q.empty()) {
int v = q.front(); q.pop();
pre_ans.pb(v);
for (int u : g[v]) {
--in[u];
if (!in[u]) q.push(u);
}
}
return pre_ans.size() == N + 1;
}
void solve() {
int n, m;
cin >> n >> m;
int l = min(n, m) - 1, r = min(n, m) * 2 + 1;
while (r - l > 1) {
int mid = l + r >> 1;
if (ask(n, m, mid)) l = mid;
else r = mid;
}
ask(n, m, l);
cout << l << endl;
vector <int> pre(l + 1, 0);
int t = 0;
for (int i : pre_ans) pre[i] = t++;
for (int i = 1; i <= l; ++i) cout << pre[i] - pre[i - 1] << ' ';
if (l) cout << endl;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) solve();
}
Compilation message
sequence.cpp: In function 'bool ask(int, int, int)':
sequence.cpp:43:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | return pre_ans.size() == N + 1;
| ~~~~~~~~~~~~~~~^~~~~~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:51:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 6, pans = 2 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1072 ms |
12124 KB |
Ok |
7 |
Correct |
891 ms |
15008 KB |
Ok |
8 |
Correct |
1790 ms |
17048 KB |
Ok |
9 |
Correct |
1311 ms |
15548 KB |
Ok |
10 |
Correct |
746 ms |
9100 KB |
Ok |
11 |
Correct |
1245 ms |
16052 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |