QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#295197 | #4831. Eager Sorting | ucup-team191# | 0 | 1ms | 3756kb | C++14 | 2.8kb | 2023-12-30 20:57:02 | 2023-12-30 20:57:02 |
answer
#include <cstdio>
#include <vector>
#include <cstring>
#include <bits/stdc++.h>
#define PB push_back
using namespace std;
const int N = 128;
int n, am_sorted[2 * N];
int p[N];
int cmp(int i, int j) {
if(i > n && j > n) return i > j;
if(i > n) return 1;
if(j > n) return 0;
printf("%d %d\n", i, j);
fflush(stdout);
int ret; scanf("%d", &ret);
if(ret == -1) return -1;
return ret;
}
int _cmp(int i, int j) {
if(i > n && j > n) return i > j;
if(i > n) return 1;
if(j > n) return 0;
printf("? %d %d\n", i, j);
fflush(stdout);
//int ret; scanf("%d", &ret);
if(p[i] > p[j]) {
swap(p[i], p[j]);
return 1;
} else {
return 0;
}
//if(ret == -1) return -1;
//return ret;
}
int slomio_se;
void stanje(){
for(int i = 1;i <= n;i++)
printf("%d ", p[i]);
printf("\n");
}
bool check_sorted(int i, int l, int r){
if(l == r) {
return (am_sorted[i] = true);
}
int mid = (l + r) / 2;
check_sorted(2 * i, l, mid);
if(slomio_se) return false;
if(am_sorted[2 * i]) {
int ret = cmp(mid, mid + 1);
if(ret == -1) {
slomio_se = true;
return false;
} else if(ret == 0) {
check_sorted(2 * i + 1, mid + 1, r);
if(slomio_se) return false;
am_sorted[i] = am_sorted[2 * i + 1];
} else {
return false;
}
}
return false;
}
int gdje_si[N], tko_tu[N];
void sortiraj(int node, int l, int r) {
if(l == r || am_sorted[node]) return;
int mid = (l + r) / 2;
stanje();
sortiraj(2 * node, l, mid);
if(slomio_se) return;
sortiraj(2 * node + 1, mid + 1, r);
if(slomio_se) return;
if(l + 1 == r) {
int ret = cmp(l, r);
if(ret == -1)
slomio_se = true;
return;
}
for(int i = l;i <= r;i++) gdje_si[i] = i, tko_tu[i] = i;
vector < int > poredak;
int i = l, j = mid + 1;
stanje();
while(i <= mid || j <= r) {
if(j > r) { poredak.PB(i++); continue; }
if(i > mid) { poredak.PB(j++); continue; }
int ret = cmp(gdje_si[i], gdje_si[j]);
if(ret == -1) { slomio_se = true; return; }
if(ret == 1) {
swap(gdje_si[i], gdje_si[j]);
poredak.PB(j); j++;
} else {
poredak.PB(i++);
}
}
for(int i = l;i <= r;i++) {
int x = poredak[i - l];
stanje();
if(gdje_si[x] != i) {
int skim = l;
while(gdje_si[skim] != i) skim++;
int ret = cmp(i, gdje_si[x]);
if(ret == -1) { slomio_se = true; return; }
swap(gdje_si[skim], gdje_si[x]);
}
}
stanje();
}
void pokretanje(){
memset(am_sorted, 0, sizeof(am_sorted));
memset(gdje_si, 0, sizeof(gdje_si));
memset(tko_tu, 0, sizeof(tko_tu));
slomio_se = 0;
check_sorted(1, 1, 128);
if(slomio_se) return;
sortiraj(1, 1, 128);
if(slomio_se) return;
printf("-1 -1\n");
fflush(stdout);
exit(0);
}
int main(){
scanf("%d", &n);
//for(int i = 1;i <= n;i++) scanf("%d", p + i);
pokretanje();
pokretanje();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3756kb
Interactor to First Run
5 0 1
First Run to Interactor
1 2 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4
Interactor to Second Run
Second Run to Interactor
Manager to Checker
WA Invalid Operation 0 0
result:
wrong answer WA