QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#312706 | #4831. Eager Sorting | minhnhatnoe | 0 | 1ms | 3636kb | C++14 | 1000b | 2024-01-24 10:59:22 | 2024-01-24 10:59:22 |
answer
#include <bits/stdc++.h>
using namespace std;
int n;
int inter(int i, int j){
if (i == j) return 0;
if (i > j) swap(i, j);
cout << i+1 << " " << j+1 << endl;
int v; cin >> v;
if (v == -1) exit(0);
return v;
}
void trip(int pos, int c1, int c2){
assert(pos < c1 && c1 < c2);
inter(c1, c2);
inter(pos, c1);
}
void recurse(int begin, int end){
if (begin+1 == end) return;
int mid = (begin + end)>>1;
recurse(begin, mid);
recurse(mid, end);
int ptrl = begin, ptrr = mid;
while (true){
int v = inter(ptrl, ptrr);
ptrl++;
if (v) break;
if (ptrl == mid) return;
}
while (ptrl != mid){
trip(ptrl, ptrr, ptrr+1);
ptrl++;
}
while (ptrr+1 != end){
int v = inter(ptrr, ptrr+1);
if (v == 0) break;
ptrr++;
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
recurse(0, n);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
Interactor to First Run
5 0 1 0 1 0 1 1 0 -1
First Run to Interactor
1 2 4 5 3 4 1 3 3 4 2 3 3 4 4 5
Interactor to Second Run
5 0 0 0 0 0
Second Run to Interactor
1 2 4 5 3 4 1 3 2 3
Manager to Checker
OK good job!
result:
ok OK
Test #2:
score: 0
Instance #1 Memory Limit Exceeded
Interactor to First Run
1
First Run to Interactor
Interactor to Second Run
Second Run to Interactor
Manager to Checker
WA Invalid Operation 798391512 21959