QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466346#8056. Travel 2ucup-team2307#AC ✓167ms4084kbC++202.4kb2024-07-07 18:39:052024-07-07 18:39:06

Judging History

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

  • [2024-07-07 18:39:06]
  • 评测
  • 测评结果:AC
  • 用时:167ms
  • 内存:4084kb
  • [2024-07-07 18:39:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
//#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

struct IO
{
    pii get()
    {
        int x,d;
        cin>>x>>d;
        return {x-1,d};
    }
    void walk(int i)
    {
        cout<<"> "<<i+1<<endl;
    }
    void answer(const vector<vi>& g)
    {
        cout<<"! ";
        for(int i=0;i<sz(g);i++)
            for(int j:g[i])
                if(i<j)
                    cout<<i+1<<" "<<j+1<<" ";
        cout<<endl;
        string resp;
        cin>>resp;
        if(resp!="Correct")
            exit(0);
    }
} io;

mt19937 rng;

void solve(auto&interactor)
{
    vector<vi> g;
    auto[x,d]=interactor.get();
    while(true)
    {
        if(sz(g)<=x)
            g.resize(x+1);
        g[x].resize(d,-1);
        vector<int> unknown;
        for(int i=0;i<d;i++)
            if(g[x][i]==-1)
                unknown.pb(i);
        if(!unknown.empty())
        {
            int i=unknown[rng()%sz(unknown)];
            interactor.walk(i);
            auto[xx,dd]=interactor.get();
            g[x][i]=xx;
            tie(x,d)=pair(xx,dd);
        }
        else
        {
            queue<int> q;
            vector<int> ind(sz(g),-1);
            ind[x]=-2;
            for(int i=0;i<sz(g[x]);i++)
                q.push(g[x][i]),
                ind[g[x][i]]=i;
            int where=-1;
            while(!q.empty()&&where==-1)
            {
                int v=q.front();
                q.pop();
                for(int to:g[v])
                    if(to==-1)
                    {
                        where=ind[v];
                        break;
                    }
                    else if(ind[to]==-1)
                    {
                        ind[to]=ind[v];
                        q.push(to);
                    }
            }
            if(where==-1)
                break;
            interactor.walk(where);
            tie(x,d)=interactor.get();
        }
    }
    interactor.answer(g);
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int t;
    cin>>t;
    while(t--)
        solve(io);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3832kb

input:

2
1 1
2 1
1 1
Correct
1 3
4 2
2 2
1 3
3 1
1 3
2 2
4 2
1 3
Correct

output:

> 1
> 1
! 1 2 
> 3
> 2
> 1
> 2
> 1
> 1
> 2
> 1
! 1 2 1 3 1 4 2 4 

result:

ok correct! (2 test cases)

Test #2:

score: 0
Accepted
time: 77ms
memory: 3812kb

input:

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

output:

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

result:

ok correct! (1000 test cases)

Test #3:

score: 0
Accepted
time: 111ms
memory: 3616kb

input:

500
1 19
6 7
1 19
4 8
3 7
11 8
2 8
18 7
8 4
15 8
6 7
17 10
10 9
19 7
1 19
8 4
1 19
12 7
13 4
16 7
12 7
18 7
5 7
6 7
7 11
10 9
17 10
9 7
3 7
17 10
14 9
6 7
11 8
3 7
2 8
17 10
20 6
3 7
20 6
9 7
1 19
15 8
16 7
17 10
1 19
20 6
1 19
14 9
5 7
7 11
16 7
7 11
14 9
1 19
11 8
1 19
17 10
6 7
14 9
7 11
12 7
20 ...

output:

> 5
> 1
> 3
> 2
> 3
> 8
> 6
> 6
> 3
> 4
> 3
> 6
> 7
> 1
> 7
> 1
> 11
> 4
> 2
> 6
> 7
> 2
> 3
> 7
> 7
> 3
> 9
> 7
> 6
> 4
> 4
> 4
> 2
> 5
> 2
> 10
> 2
> 2
> 4
> 1
> 14
> 3
> 7
> 1
> 19
> 1
> 13
> 8
> 2
> 3
> 4
> 8
> 1
> 10
> 1
> 16
> 3
> 6
> 7
> 10
> 6
> 3
> 7
> 6
> 1
> 1
> 7
> 2
> 4
> 8
> 5
> 5
> 6
...

result:

ok correct! (500 test cases)

Test #4:

score: 0
Accepted
time: 161ms
memory: 3520kb

input:

100
1 99
85 7
1 99
66 6
13 6
54 8
51 7
34 8
57 5
41 7
57 5
8 8
9 9
36 6
1 99
22 5
1 99
42 5
31 7
58 5
31 7
42 5
96 10
92 13
49 5
99 7
1 99
45 9
37 7
75 10
43 12
1 99
88 8
7 6
79 3
1 99
44 8
61 4
76 9
55 9
1 99
75 10
24 10
4 10
1 99
84 5
6 9
73 6
56 8
94 8
4 10
69 9
38 6
69 9
56 8
75 10
37 7
27 7
77 ...

output:

> 84
> 1
> 65
> 6
> 5
> 8
> 3
> 2
> 4
> 5
> 5
> 6
> 7
> 1
> 21
> 1
> 41
> 5
> 2
> 2
> 7
> 2
> 4
> 13
> 2
> 1
> 44
> 4
> 3
> 2
> 1
> 87
> 2
> 3
> 1
> 43
> 2
> 2
> 8
> 1
> 74
> 5
> 6
> 1
> 83
> 2
> 4
> 5
> 4
> 7
> 3
> 6
> 3
> 8
> 3
> 4
> 6
> 5
> 3
> 8
> 8
> 1
> 51
> 5
> 1
> 92
> 3
> 3
> 2
> 8
> 4
> 11...

result:

ok correct! (100 test cases)

Test #5:

score: 0
Accepted
time: 136ms
memory: 3692kb

input:

10
1 999
328 6
1 999
22 8
989 9
22 8
838 7
611 8
475 13
146 10
831 7
150 7
841 6
1 999
15 8
18 5
1 999
428 13
82 9
773 3
82 9
257 12
878 10
918 6
63 7
684 10
506 6
373 10
887 9
313 8
489 3
1 999
153 9
499 7
579 13
499 7
351 7
1 999
524 2
854 10
523 11
377 3
1 999
730 7
211 9
730 7
1 999
16 9
926 8
1...

output:

> 327
> 1
> 21
> 2
> 2
> 8
> 3
> 2
> 11
> 4
> 7
> 4
> 1
> 14
> 8
> 1
> 427
> 13
> 2
> 2
> 3
> 2
> 4
> 2
> 7
> 7
> 5
> 4
> 8
> 4
> 1
> 152
> 5
> 3
> 2
> 2
> 1
> 523
> 2
> 9
> 10
> 1
> 729
> 5
> 6
> 1
> 15
> 2
> 4
> 3
> 3
> 6
> 3
> 2
> 5
> 7
> 2
> 9
> 5
> 3
> 8
> 6
> 2
> 1
> 745
> 1
> 690
> 1
> 799
> ...

result:

ok correct! (10 test cases)

Test #6:

score: 0
Accepted
time: 167ms
memory: 3784kb

input:

4
1 999
328 25
81 35
609 19
750 21
874 20
555 25
33 15
865 16
479 22
841 15
479 22
173 21
224 11
173 21
576 19
274 19
90 23
92 20
3 20
738 18
821 21
802 18
645 19
522 29
646 20
943 29
630 27
954 20
1 999
350 24
53 18
463 22
658 20
128 20
318 17
511 15
124 27
225 14
288 19
36 18
713 18
71 17
191 15
1...

output:

> 327
> 3
> 30
> 17
> 17
> 12
> 5
> 6
> 11
> 16
> 11
> 19
> 19
> 9
> 21
> 3
> 10
> 13
> 18
> 7
> 18
> 11
> 18
> 18
> 13
> 7
> 26
> 13
> 1
> 349
> 13
> 16
> 14
> 19
> 7
> 13
> 14
> 15
> 10
> 15
> 13
> 13
> 2
> 1
> 468
> 5
> 16
> 10
> 13
> 4
> 14
> 14
> 1
> 55
> 7
> 3
> 14
> 12
> 5
> 13
> 20
> 16
> 11...

result:

ok correct! (4 test cases)

Test #7:

score: 0
Accepted
time: 141ms
memory: 3712kb

input:

4
1 199
191 106
31 89
154 102
198 105
93 96
87 95
142 103
126 107
163 100
66 108
108 94
39 92
49 93
42 109
170 99
114 107
104 111
198 105
97 96
128 99
123 89
71 100
39 92
149 94
41 105
115 96
151 99
63 100
28 100
153 97
111 100
188 101
44 100
193 103
176 85
47 100
192 112
82 107
39 92
151 99
59 94
1...

output:

> 190
> 5
> 6
> 102
> 80
> 32
> 70
> 84
> 24
> 4
> 80
> 64
> 73
> 7
> 74
> 94
> 50
> 80
> 50
> 59
> 18
> 79
> 44
> 52
> 47
> 57
> 89
> 85
> 61
> 72
> 48
> 10
> 73
> 19
> 54
> 81
> 54
> 14
> 4
> 19
> 86
> 21
> 24
> 33
> 72
> 77
> 16
> 11
> 40
> 87
> 75
> 54
> 27
> 32
> 22
> 18
> 68
> 16
> 40
> 42
> 7...

result:

ok correct! (4 test cases)

Test #8:

score: 0
Accepted
time: 85ms
memory: 3720kb

input:

4
1 140
94 140
43 140
136 140
86 140
45 140
113 140
10 140
6 140
100 140
125 140
56 140
46 140
62 140
128 140
141 140
1 140
128 140
88 140
58 140
27 140
31 140
131 140
24 140
81 140
7 140
128 140
102 140
14 140
102 140
59 140
33 140
51 140
30 140
60 140
108 140
56 140
4 140
15 140
109 140
110 140
85...

output:

> 93
> 43
> 135
> 86
> 45
> 112
> 10
> 6
> 99
> 124
> 56
> 46
> 61
> 127
> 140
> 1
> 127
> 88
> 58
> 27
> 30
> 130
> 24
> 80
> 7
> 127
> 102
> 14
> 101
> 59
> 33
> 50
> 30
> 59
> 107
> 56
> 4
> 14
> 108
> 109
> 85
> 87
> 113
> 61
> 98
> 37
> 46
> 15
> 56
> 3
> 79
> 54
> 1
> 49
> 3
> 53
> 19
> 68
> 1...

result:

ok correct! (4 test cases)

Test #9:

score: 0
Accepted
time: 120ms
memory: 4084kb

input:

4
1 2498
724 2
1 2498
761 2
2500 2498
878 2
2500 2498
90 2
2500 2498
2302 2
2500 2498
2380 2
2500 2498
886 2
1 2498
2403 2
1 2498
1923 2
1 2498
2120 2
1 2498
1272 2
2500 2498
1777 2
2500 2498
681 2
1 2498
2404 2
2500 2498
2009 2
2500 2498
2090 2
2500 2498
1537 2
1 2498
1776 2
2500 2498
348 2
2500 24...

output:

> 723
> 1
> 760
> 2
> 877
> 2
> 89
> 2
> 2301
> 2
> 2379
> 2
> 885
> 1
> 2402
> 1
> 1922
> 1
> 2119
> 1
> 1271
> 2
> 1776
> 2
> 680
> 1
> 2403
> 2
> 2008
> 2
> 2089
> 2
> 1536
> 1
> 1775
> 2
> 347
> 2
> 2240
> 1
> 625
> 1
> 852
> 1
> 46
> 1
> 1627
> 1
> 2053
> 1
> 1239
> 2
> 1500
> 1
> 620
> 1
> 927...

result:

ok correct! (4 test cases)

Extra Test:

score: 0
Extra Test Passed