QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#294455 | #4831. Eager Sorting | ucup-team866# | 0 | 1ms | 3872kb | C++14 | 877b | 2023-12-30 13:51:49 | 2023-12-30 13:51:49 |
answer
#include <bits/stdc++.h>
using namespace std;
int n, pos[105], tmp[105];
void solve(int l, int r) {
if (l == r) return void (pos[l] = l);
int mid = l + r >> 1;
solve(l, mid), solve(mid+1, r);
int p = l, q = mid + 1, t = 0;
while (p <= mid && q <= r) {
printf ("%d %d\n", pos[p], pos[q]), fflush (stdout);
int v; scanf ("%d", &v);
if (~ v) { if (v) swap(pos[p], pos[q]); } else exit (0);
tmp[++t] = pos[p] < pos[q] ? pos[p++] : pos[q++];
}
while (p <= mid) tmp[++t] = pos[p++];
while (q <= r) tmp[++t] = pos[q++];
for (int i=l; i<=r; i++) pos[i] = tmp[i-l+1];
}
int main() {
cin >> n;
solve(1, n);
for (int i=1; i<n; i++)
if (pos[i] ^ i) {
int j;
for (j=i+1; pos[j]^i; j++) ;
printf ("%d %d\n", pos[i], i), fflush (stdout);
int v; scanf ("%d", &v);
if (~ v) assert (v), swap(pos[i], pos[j]); else exit (0);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3872kb
Interactor to First Run
5 0 1 1 0 0 1 0 1 -1
First Run to Interactor
1 2 1 3 4 5 1 4 3 4 2 4 4 5 3 2
Interactor to Second Run
5 0 0 0 0 0 0 0
Second Run to Interactor
1 2 1 3 2 3 4 5 1 4 2 4 3 4
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 -942195496 21850