#include "bits/stdc++.h"
#define int long long
using namespace std;
#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front
#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll
mt19937 rng(uint64_t(new char));
#define rand rng
#define endl '\n'
#define sp ' '
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void solve();
signed main() {
// #ifdef GIAPVU
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
// #endif
fastio;
int tc = 1;
cin >> tc;
fori(test, 1, tc) {
solve();
}
return 0;
}
#define int long long
const int inf = LLONG_MAX / 100ll, mod = 1000000007 ;
const int maxn = 1e6 + 5, itsize = maxn << 1, maxit = maxn << 3, mapping = maxn;
int n, m;
int dep[maxn];
void get_dep(int i, int len) {
if(dep[i] == -1) {
dep[i] = 0;
if(i - m >= 0) {
get_dep(i - m, len);
dep[i] = max(dep[i],dep[i - m] + 1);
}
if(i + n <= len) {
get_dep(i + n, len);
dep[i] = max(dep[i], dep[i + n] + 1);
}
}
}
bool build(int len);
bool build(int len) {
// cout << "len: " << len << endl;
fill(dep, dep + len + 1, -1);
fori(i, 0, len) {
if(dep[i] == -1) get_dep(i, len);
// cout << dep[i] << sp; cout << endl;
}
fori(i, 0, len) {
if(i - m >= 0 and dep[i] <= dep[i - m]) return 0;
if(i + n <= len and dep[i] <= dep[i + n]) return 0;
}
return 1;
}
void solve() {
cin >> n >> m;
int lo = 0, hi = n + m;
while(lo < hi) {
int mi = lo + hi + 1 >> 1;
// cout << "mi:" << mi << endl;
if(build(mi)) lo = mi;
else hi = mi - 1;
}
build(lo);
cout << lo << endl;
fori(i,1,lo) {
cout << dep[i] - dep[i - 1] << sp;
}
cout << endl;
}
Compilation message
sequence.cpp: In function 'void solve()':
sequence.cpp:90:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
90 | int mi = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Incorrect |
0 ms |
324 KB |
All the numbers must be nonzero |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
316 KB |
Ok |
3 |
Incorrect |
0 ms |
332 KB |
All the numbers must be nonzero |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Incorrect |
0 ms |
324 KB |
All the numbers must be nonzero |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Incorrect |
0 ms |
324 KB |
All the numbers must be nonzero |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Incorrect |
0 ms |
324 KB |
All the numbers must be nonzero |
3 |
Halted |
0 ms |
0 KB |
- |