# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
44570 | ssnsarang2023 | Zagonetka (COI18_zagonetka) | C++17 | 328 ms | 496 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define debug
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
#define SZ(x) ((int)x.size())
int n, a[105], b[105], pos[105], deg[105];
bool adj[105][105];
bool ask() {
queue<int> q;
fill(deg + 1, deg + n + 1, 0);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (adj[i][j]) {
++deg[j];
}
}
}
for (int i = 1; i <= n; ++i) {
if (!deg[i]) {
q.push(i);
}
}
int idx = 0;
while (SZ(q)) {
int u = q.front(); q.pop();
b[u] = ++idx;
for (int v = 1; v <= n; ++v) {
if (!adj[u][v]) continue;
--deg[v];
if (!deg[v]) {
q.push(v);
}
}
}
for (int i = 1; i <= n; ++i) {
if (deg[i]) {
return 0;
}
}
printf("query ");
for (int i = 1; i <= n; ++i) {
printf("%d ", b[i]);
}
fflush(stdout);
int re = 0;
scanf("%d", &re);
return re;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
pos[a[i]] = i;
for (int j = 1; j < i; ++j) {
bool re = a[j] < a[i];
if (re) {
adj[j][i] = 1;
} else {
adj[i][j] = 1;
}
}
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= n - i; ++j) {
int x = pos[j], y = pos[j + i];
adj[x][y] = 0, adj[y][x] = 1;
bool re = ask();
adj[y][x] = 0, adj[x][y] = !re;
}
}
set<int> q;
fill(deg + 1, deg + n + 1, 0);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (adj[i][j]) {
++deg[j];
}
}
}
for (int i = 1; i <= n; ++i) {
if (!deg[i]) {
q.insert(i);
}
}
int idx = 1;
while (SZ(q)) {
int u = *q.begin();
q.erase(q.begin());
a[u] = idx++;
for (int v = 1; v <= n; ++v) {
if (!adj[u][v]) continue;
--deg[v];
if (!deg[v]) {
q.insert(v);
}
}
}
fill(deg + 1, deg + n + 1, 0);
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
swap(adj[i][j], adj[j][i]);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (adj[i][j]) {
++deg[j];
}
}
}
for (int i = 1; i <= n; ++i) {
if (!deg[i]) {
q.insert(i);
}
}
idx = n;
while (SZ(q)) {
int u = *q.begin();
q.erase(q.begin());
b[u] = idx--;
for (int v = 1; v <= n; ++v) {
if (!adj[u][v]) continue;
--deg[v];
if (!deg[v]) {
q.insert(v);
}
}
}
printf("end\n");
for (int i = 1; i <= n; ++i) {
printf("%d ", a[i]);
}
printf("\n");
for (int i = 1; i <= n; ++i) {
printf("%d ", b[i]);
}
fflush(stdout);
return 0;
}
컴파일 시 표준 에러 (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... |