# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
745589 | lukadupli | Nizovi (COI14_nizovi) | C++14 | 330 ms | 292 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 f first
#define s second
using namespace std;
typedef pair<int, int> pii;
bool cmp(int a, int b){
cout << "cmp " << a << ' ' << b << endl;
int x;
cin >> x;
return x <= 0;
}
void rev(int l, int r){
if(l == r) return;
cout << "reverse " << l << ' ' << r << endl;
}
int A, B;
void solve(int pos, int fall){
//cout << "solving: " << pos << ' ' << fall << '\n';
if(pos >= A + B || fall > A + B || pos >= fall) return;
if(cmp(pos, fall)){
int l = pos + 1, r = fall - 1;
while(r > l){
int m = (l + r) / 2;
if(!cmp(m, fall)) r = m;
else l = m + 1;
}
if(l == fall - 1 && cmp(l, fall)) return;
pos = l;
}
//cout << "adjusted to: " << pos << ' ' << fall << '\n';
if(pos >= A + B || fall > A + B || pos >= fall) return;
int l = fall, r = A + B;
while(r > l){
int m = (l + r + 1) / 2;
if(cmp(m, pos)) l = m;
else r = m - 1;
}
rev(pos, l);
rev(pos, pos + l - fall);
rev(pos + l - fall + 1, l);
solve(pos + l - fall + 1, l + 1);
}
int main()
{
cin >> A >> B;
solve(1, A + 1);
cout << "end" << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |