답안 #1061841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061841 2024-08-16T14:10:19 Z oscar1f Meetings (JOI19_meetings) C++17
100 / 100
366 ms 1564 KB
#include<bits/stdc++.h>
#include "meetings.h"
using namespace std;

void afficher(vector<int> v) {
    for (int i:v) {
        cout<<i<<" ";
    }
    cout<<endl;
}

void construire(int a,int b) {
    Bridge(min(a,b),max(a,b));
}

void calc(vector<int> v) {
    int nbSom=v.size();
    //afficher(v);
    if (nbSom<2) {
        return;
    }
    if (nbSom==2) {
        construire(v[0],v[1]);
        return;
    }
    int rand1=rand()%nbSom,rand2=rand()%(nbSom-1);
    int somDeb=v[rand1],somFin=v[(rand1+rand2+1)%nbSom];
    unordered_map<int,int> dv,corres;
    dv[somDeb]=1;
    dv[somFin]=1;
    corres[somDeb]=1;
    corres[somFin]=2;
    int tailleChaine=2,ans;
    vector<vector<int>> suiv;
    suiv={{},{somDeb},{somFin}};
    //cout<<"?"<<somDeb<<" "<<somFin<<endl;
    for (int i:v) {
        if (dv[i]==0) {
            dv[i]=1;
            ans=Query(i,somDeb,somFin);
            if (ans==i) {
                tailleChaine++;
                suiv.push_back({i});
                corres[i]=tailleChaine;
            }
            else if (dv[ans]==0) {
                dv[ans]=1;
                tailleChaine++;
                suiv.push_back({ans,i});
                corres[ans]=tailleChaine;
            }
            else {
                suiv[corres[ans]].push_back(i);
            }
        }
    }
    for (auto w:suiv) {
        //cout<<"!";
        //afficher(w);
        calc(w);
    } 
    int nouv,deb,fin,mid;
    vector<int> ordre={somDeb,somFin},nouvOrdre;
    for (int i=3;i<=tailleChaine;i++) {
        nouv=suiv[i][0];
        deb=0;
        fin=i-3;
        while (deb!=fin) {
            mid=(deb+fin)/2;
            ans=Query(ordre[mid],ordre[mid+1],nouv);
            if (ans==nouv) {
                deb=mid;
                fin=mid;
            }
            else if (ans==ordre[mid]) {
                fin=mid-1;
            }
            else {
                deb=mid+1;
            }
        }
        nouvOrdre.clear();
        for (int j=0;j<i-1;j++) {
            nouvOrdre.push_back(ordre[j]);
            if (j==deb) {
                nouvOrdre.push_back(nouv);
            }
        }
        ordre=nouvOrdre;
    }
    //cout<<"#";
    //afficher(ordre);
    for (int i=0;i<tailleChaine-1;i++) {
        construire(ordre[i],ordre[i+1]);
    }
}

void Solve(int N) {
    srand(time(NULL));
    //int x = Query(0, 1, 2);
    vector<int> v;
    for (int i=0;i<N;i++) {
        v.push_back(i);
    }
    calc(v);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 520 KB Output is correct
30 Correct 3 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 4 ms 556 KB Output is correct
33 Correct 4 ms 344 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 5 ms 600 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 5 ms 480 KB Output is correct
39 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 792 KB Output is correct
2 Correct 175 ms 872 KB Output is correct
3 Correct 157 ms 960 KB Output is correct
4 Correct 167 ms 848 KB Output is correct
5 Correct 125 ms 684 KB Output is correct
6 Correct 140 ms 740 KB Output is correct
7 Correct 257 ms 1252 KB Output is correct
8 Correct 242 ms 900 KB Output is correct
9 Correct 225 ms 860 KB Output is correct
10 Correct 221 ms 940 KB Output is correct
11 Correct 241 ms 952 KB Output is correct
12 Correct 145 ms 848 KB Output is correct
13 Correct 102 ms 848 KB Output is correct
14 Correct 145 ms 780 KB Output is correct
15 Correct 133 ms 848 KB Output is correct
16 Correct 140 ms 780 KB Output is correct
17 Correct 229 ms 1000 KB Output is correct
18 Correct 155 ms 856 KB Output is correct
19 Correct 183 ms 740 KB Output is correct
20 Correct 176 ms 968 KB Output is correct
21 Correct 146 ms 848 KB Output is correct
22 Correct 148 ms 852 KB Output is correct
23 Correct 135 ms 856 KB Output is correct
24 Correct 113 ms 820 KB Output is correct
25 Correct 173 ms 848 KB Output is correct
26 Correct 145 ms 932 KB Output is correct
27 Correct 150 ms 744 KB Output is correct
28 Correct 261 ms 848 KB Output is correct
29 Correct 252 ms 1564 KB Output is correct
30 Correct 337 ms 1104 KB Output is correct
31 Correct 221 ms 1104 KB Output is correct
32 Correct 366 ms 1040 KB Output is correct
33 Correct 246 ms 1104 KB Output is correct
34 Correct 3 ms 344 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 2 ms 344 KB Output is correct
38 Correct 2 ms 344 KB Output is correct
39 Correct 4 ms 344 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 5 ms 600 KB Output is correct
42 Correct 5 ms 600 KB Output is correct
43 Correct 2 ms 548 KB Output is correct
44 Correct 4 ms 344 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 5 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 472 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct