# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338122 | BeanZ | Nice sequence (IZhO18_sequence) | C++14 | 1964 ms | 45668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |