# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
633909 | lovrot | Nice sequence (IZhO18_sequence) | C++11 | 1110 ms | 46412 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.
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
using namespace std;
const int N = 4 * 1e5 + 10;
int t, n, m, p[N], ans, pos;
int bio[N], ts[N], cookie;
bool cycp(int u){
if(bio[u] == cookie + 1 || bio[u] == cookie) return bio[u] == cookie;
bio[u] = cookie;
if(u - m >= 0 && cycp(u - m)) return true;
if(u + n <= ans && cycp(u + n)) return true;
bio[u] = cookie + 1;
return false;
}
void topSort(int u){
ts[u] = cookie;
if(u - m >= 0){
if(ts[u - m] != cookie) topSort(u - m);
}
if(u + n <= ans){
if(ts[u + n] != cookie) topSort(u + n);
}
p[u] = ++pos;
}
void output(){
for(int i = 0; i <= ans; i++)
if(ts[i] != cookie) topSort(i);
printf("%d\n", ans);
for(int i = 1; i <= ans; i++)
printf("%d ", (p[i] - p[0]) - (p[i - 1] - p[0]));
printf("\n");
}
bool probaj(){
pos = -1;
cookie += 2;
for(int i = 0; i <= ans; i++){
if(bio[i] != cookie + 1 && cycp(i)) return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &m);
int lo = 0, hi = (n + m) + 1;
while(hi - lo > 1){
int mi = (lo + hi) / 2;
ans = mi;
if(probaj())
lo = mi;
else
hi = mi;
}
ans = lo;
probaj();
output();
}
return 0;
}
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... |