QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#109192#6503. DFS Order 3snowy2002TL 1541ms5756kbC++171.9kb2023-05-27 19:18:092023-05-27 19:18:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-27 19:18:13]
  • 评测
  • 测评结果:TL
  • 用时:1541ms
  • 内存:5756kb
  • [2023-05-27 19:18:09]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define time chrono::system_clock::now().time_since_epoch().count()
#include<ext/pb_ds/tree_policy.hpp>
#define clean(x) memset(x,0,sizeof(x))
#define fil(x,n) fill(x,x+1+n,0)
#define inf 2000000009
#define maxn 1000005
// #define int long long
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(time);
cc_hash_table<int,int>mp;

int read() {
    int x=1,res=0;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-') x=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        res=res*10+(c-'0');
        c=getchar();
    }
    return res*x;
}
set<pair<int,int>>s[1005];
int f[1005][1005];

void solve() {
    int n=read();
    vector id(n+1,vector(n+1,0));
    for(int i=1;i<=n;i++) s[i].clear();
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            int x=read();
            id[i][x]=j;
            s[i].insert({j,x});
        }
    }
    vector<pair<int,int>>ans;
    
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=0;
    while(s[1].size()>=2) {
        vector<int>res;
        for(int i=1;i<=n;i++) {
            auto u=*s[i].begin();
            auto ii=s[i].begin();
            ii++;
            auto v=*(ii);
            if(!f[u.second][v.second]) {
                f[u.second][v.second]=f[v.second][u.second]=1;
            }
            auto z=s[i].rbegin()->second;
            res.push_back(z);
        }
        for(int i:res) {
            for(int j=1;j<=n;j++) {
                s[j].erase({id[j][i],i});
            }
        }
    }
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            if(f[i][j]) ans.push_back({i,j});
        }
    }
    for(auto [u,v]:ans) {
        printf("%d %d\n",u,v);
    }
}

signed main()
{
    int t=read();
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3716kb

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
2 3
1 2
2 3
2 4
1 2
1 3
2 4
3 5

result:

ok correct answer! (4 test cases)

Test #2:

score: 0
Accepted
time: 299ms
memory: 5756kb

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:

1 2
1 3
1 4
1 10
3 8
4 5
4 6
6 7
9 10
1 4
2 8
3 4
3 8
4 5
5 7
6 9
7 10
8 9
1 9
2 4
2 8
3 10
5 6
5 7
5 9
8 10
9 10
1 6
2 4
2 10
3 8
5 7
6 7
6 9
6 10
7 8
1 5
1 9
2 10
3 6
3 7
3 10
4 7
5 7
8 9
1 10
2 6
3 8
4 8
5 10
6 10
7 9
8 9
8 10
1 10
2 3
2 9
2 10
3 7
4 8
5 7
5 8
6 7
1 4
1 9
2 3
2 4
4 7
4 8
5 10
6 7...

result:

ok correct answer! (20000 test cases)

Test #3:

score: 0
Accepted
time: 1541ms
memory: 4592kb

input:

200
100
1 51 45 20 15 66 21 71 83 29 77 70 82 46 79 47 17 50 38 85 69 35 14 60 44 11 36 86 28 58 89 61 34 7 92 39 59 94 63 75 12 81 16 6 23 37 74 52 42 13 65 91 57 40 62 93 72 96 68 26 78 84 43 10 9 33 56 87 97 27 22 80 55 24 98 76 3 18 48 90 64 49 67 4 19 53 32 54 73 8 31 88 99 25 100 5 2 41 95 30
...

output:

1 29
1 45
1 51
2 5
3 18
3 68
3 100
4 19
4 53
4 67
5 41
5 95
5 100
6 16
6 23
7 34
8 73
9 10
9 33
10 43
11 44
12 47
12 81
12 91
13 65
13 74
14 60
14 69
15 20
15 66
16 81
17 47
17 50
18 48
18 90
20 21
20 45
21 71
22 26
22 80
23 37
24 80
24 98
25 99
26 68
26 78
26 84
27 97
28 86
29 77
29 82
30 95
31 73
...

result:

ok correct answer! (200 test cases)

Test #4:

score: -100
Time Limit Exceeded

input:

8
500
1 164 494 392 66 328 402 15 156 395 234 78 241 304 4 54 439 387 83 460 220 490 369 343 172 190 108 122 173 384 290 403 231 254 70 29 294 359 153 59 228 474 167 222 491 357 169 383 50 103 447 84 344 237 376 457 238 17 363 131 34 244 472 104 154 322 140 488 193 390 245 147 31 189 191 221 259 456...

output:


result: