QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#147107 | #6503. DFS Order 3 | ClapEcho233 | WA | 35ms | 10040kb | C++14 | 1.5kb | 2023-08-22 19:46:55 | 2023-08-22 19:46:57 |
Judging History
answer
#include <bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define ll long long
#define CI const int
#define RI int
#define W while
#define gc getchar
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Mt(a,x) memset((a),(x),sizeof(a))
using namespace std;
namespace SlowIO {
void Readc (char& c) {W (isspace (c = gc ()));}
Tp void Read (Ty& x) {char c; int f = 1; x = 0; W (! isdigit (c = gc ())) f = c ^ '-' ? 1 : -1; W (x = (x * 10) + (c ^ 48), isdigit (c = gc ())); x *= f;}
Ts void Read (Ty& x, Ar&... y) {Read (x); Read (y...);}
} using namespace SlowIO;
CI N = 1e3; int T, n, a[N + 5][N + 5], nxt[N + 5][N + 5], pre[N + 5][N + 5], id[N + 5][N + 5]; bool is[N + 5], vis[N + 5];
void Del (int y) {RI i, j; for (i = 1; i <= n; ++ i) {int now = id[i][y]; nxt[i][pre[i][now]] = nxt[i][now]; pre[i][nxt[i][now]] = pre[i][now];}}
int main () {
RI i, j; Read (T); W (T --) {
for (Read (n), i = 1; i <= n; ++ i) for (j = 1; j <= n; ++ j) Read (a[i][j]), id[i][a[i][j]] = j, nxt[i][j] = j + 1, pre[i][j] = j - 1;
if (n == 2) {printf ("1 2\n"); continue;} Mt (is, 0); Mt (vis, 0); for (i = 1; i <= n; ++ i) nxt[i][0] = 1, pre[i][n + 1] = n; int num = 0; W (num < n - 1) {
Mt (vis, 0); for (i = 1; i <= n; ++ i) {if (is[i]) continue; vis[a[i][pre[i][n + 1]]] = 1;}
for (i = 1; i <= n; ++ i) {if (! vis[i]) continue; ++ num; is[i] = 1; printf ("%d %d\n", i, a[i][nxt[i][1]]); Del (i);}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10020kb
input:
4 2 1 2 2 1 3 1 2 3 2 1 3 3 2 1 4 1 2 3 4 2 1 3 4 3 2 4 1 4 2 1 3 5 1 2 4 3 5 2 4 1 3 5 3 5 1 2 4 4 2 1 3 5 5 3 1 2 4
output:
1 2 1 2 3 2 1 2 3 2 4 2 4 2 5 3 2 1 3 1
result:
ok correct answer! (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 10040kb
input:
20000 10 1 2 4 5 6 7 3 8 10 9 2 1 4 5 6 7 3 8 10 9 3 8 1 2 4 5 6 7 10 9 4 5 6 7 1 2 3 8 10 9 5 4 6 7 1 2 3 8 10 9 6 7 4 5 1 2 3 8 10 9 7 6 4 5 1 2 3 8 10 9 8 3 1 2 4 5 6 7 10 9 9 10 1 2 4 5 6 7 3 8 10 1 2 4 5 6 7 3 8 9 10 1 4 3 8 2 9 6 5 7 10 2 8 9 6 3 4 1 5 7 10 3 8 2 9 6 4 1 5 7 10 4 1 3 8 2 9 6 5...
output:
8 3 9 10 3 1 10 1 2 1 7 6 1 4 6 4 4 5 5 0 6 9 10 7 7 5 9 8 2 8 5 4 1 4 8 3 3 4 4 0 4 2 7 5 2 8 6 5 5 9 8 10 1 9 3 10 9 10 10 0 4 2 9 6 2 10 3 8 8 7 10 6 1 6 5 7 6 7 7 0 2 10 8 9 9 1 10 3 1 5 6 3 3 7 5 7 4 7 7 0 2 6 7 9 6 10 9 8 4 8 5 10 1 10 3 8 8 10 10 0 1 10 9 2 4 8 10 2 2 3 8 5 3 7 5 7 6 7 7 0 5 ...
result:
wrong answer Integer parameter [name=y_i] equals to 0, violates the range [1, 10] (test case 2)