답안 #1106309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106309 2024-10-29T21:56:16 Z inesfi 나일강 (IOI24_nile) C++17
100 / 100
80 ms 23732 KB
#include "nile.h"
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
struct relique{
    int p,cout1,pere;
 
    bool operator< (relique other){
        return p<other.p;
    }
};
 
struct quest{
    int q,numquest;
 
    bool operator< (quest other){
        return q<other.q;
    }
};
 
struct compo{
    int pere,premier,dernier,minpair,minimpair,minponts,prix;
};
 
struct dist{
    int d,premier;
 
    bool operator< (dist other){
        return d<other.d;
    }
};
 
const int INFINI=1000ll*1000*1000*1000*1000*1000ll+2,QUESTMAXI=100*1000+2;
vector<relique> reliques;
vector<quest> questions;
vector<compo> composantes;
int nbreliques,ajout;
vector<dist> aretes;
vector<dist> ponts2;
int reponse[QUESTMAXI];
vector<int> r;
 
int trouver(int numc){
    if (composantes[numc].pere!=numc){
        return composantes[numc].pere=trouver(composantes[numc].pere);
    }
    return numc;
}
 
void unir(int compo1,int compo2){
    compo1=trouver(compo1);
    compo2=trouver(compo2);
    ajout-=composantes[compo1].prix+composantes[compo2].prix;
    
    composantes[compo2].pere=compo1;
    compo nouv;
    nouv.pere=compo1;
    nouv.premier=min(composantes[compo1].premier,composantes[compo2].premier);
    nouv.dernier=max(composantes[compo1].dernier,composantes[compo2].dernier);
    nouv.minpair=min(composantes[compo1].minpair,composantes[compo2].minpair);
    nouv.minimpair=min(composantes[compo1].minimpair,composantes[compo2].minimpair);
    nouv.minponts=min(composantes[compo1].minponts,composantes[compo2].minponts);
    if ((nouv.dernier-nouv.premier)%2==1){
        nouv.prix=0;
    }
    else {
        if (nouv.premier%2==0){
            nouv.prix=min(nouv.minpair,nouv.minponts);
        }
        else {
            nouv.prix=min(nouv.minimpair,nouv.minponts);
        }
    }
    composantes[compo1]=nouv;
    ajout+=nouv.prix;
}
#undef int
 
vector<long long> calculate_costs(vector<int> poids, vector<int> seul, vector<int> deux, vector<int> requetes) {
    #define int long long
    nbreliques=(int)poids.size();
    for (int irelique=0;irelique<nbreliques;irelique++){
        relique rel;
        ajout+=deux[irelique];
        rel.p=poids[irelique];
        rel.cout1=seul[irelique]-deux[irelique];
        rel.pere=0;
        reliques.push_back(rel);
    }
    sort(reliques.begin(),reliques.end());
    for (int irelique=0;irelique<nbreliques;irelique++){
        reliques[irelique].pere=irelique;
    }
    for (int iquest=0;iquest<(int)requetes.size();iquest++){
        quest qu;
        qu.q=requetes[iquest];
        qu.numquest=iquest;
        questions.push_back(qu);
    }
    sort(questions.begin(),questions.end());
    for (int irelique=0;irelique<nbreliques;irelique++){
        compo c;
        if (irelique%2==0){
            c={irelique,irelique,irelique,reliques[irelique].cout1,INFINI,INFINI,reliques[irelique].cout1};
        }
        else {
            c={irelique,irelique,irelique,INFINI,reliques[irelique].cout1,INFINI,reliques[irelique].cout1};
        }
        ajout+=reliques[irelique].cout1;
        composantes.push_back(c);
    }
    for (int irelique=0;irelique<nbreliques-1;irelique++){
        dist ar;
        ar={reliques[irelique+1].p-reliques[irelique].p,irelique};
        aretes.push_back(ar);
    }
    sort(aretes.begin(),aretes.end());
    for (int irelique=0;irelique<nbreliques-2;irelique++){
        dist ar;
        ar={reliques[irelique+2].p-reliques[irelique].p,irelique};
        ponts2.push_back(ar);
    }
    sort(ponts2.begin(),ponts2.end());
    int arec=0,pontec=0;
    for (auto qec:questions){
        while (arec<nbreliques-1 and aretes[arec].d<=qec.q){
            unir(aretes[arec].premier,aretes[arec].premier+1);
            arec++;
        }
        while (pontec<nbreliques-2 and ponts2[pontec].d<=qec.q){
            composantes[trouver(ponts2[pontec].premier+1)].minponts=min(composantes[trouver(ponts2[pontec].premier+1)].minponts,
            reliques[ponts2[pontec].premier+1].cout1);
            ajout-=composantes[trouver(ponts2[pontec].premier+1)].prix;
            composantes[trouver(ponts2[pontec].premier+1)].prix=min(composantes[trouver(ponts2[pontec].premier+1)].prix,
            composantes[trouver(ponts2[pontec].premier+1)].minponts);
            ajout+=composantes[trouver(ponts2[pontec].premier+1)].prix;
            pontec++;
        }
        reponse[qec.numquest]=ajout;
    }
    for (int irep=0;irep<(int)requetes.size();irep++){
        r.push_back(reponse[irep]);
    }
    return r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18100 KB Output is correct
2 Correct 38 ms 16400 KB Output is correct
3 Correct 39 ms 16576 KB Output is correct
4 Correct 40 ms 16396 KB Output is correct
5 Correct 40 ms 18868 KB Output is correct
6 Correct 38 ms 19892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 16404 KB Output is correct
2 Correct 39 ms 17564 KB Output is correct
3 Correct 48 ms 17780 KB Output is correct
4 Correct 48 ms 17616 KB Output is correct
5 Correct 43 ms 17412 KB Output is correct
6 Correct 49 ms 16308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 864 KB Output is correct
8 Correct 2 ms 848 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 2 ms 780 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 41 ms 18100 KB Output is correct
8 Correct 38 ms 16400 KB Output is correct
9 Correct 39 ms 16576 KB Output is correct
10 Correct 40 ms 16396 KB Output is correct
11 Correct 40 ms 18868 KB Output is correct
12 Correct 38 ms 19892 KB Output is correct
13 Correct 39 ms 16404 KB Output is correct
14 Correct 39 ms 17564 KB Output is correct
15 Correct 48 ms 17780 KB Output is correct
16 Correct 48 ms 17616 KB Output is correct
17 Correct 43 ms 17412 KB Output is correct
18 Correct 49 ms 16308 KB Output is correct
19 Correct 2 ms 864 KB Output is correct
20 Correct 2 ms 848 KB Output is correct
21 Correct 2 ms 768 KB Output is correct
22 Correct 2 ms 780 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 45 ms 19080 KB Output is correct
26 Correct 46 ms 18612 KB Output is correct
27 Correct 55 ms 18232 KB Output is correct
28 Correct 53 ms 20268 KB Output is correct
29 Correct 48 ms 20148 KB Output is correct
30 Correct 62 ms 19388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 16404 KB Output is correct
2 Correct 39 ms 17564 KB Output is correct
3 Correct 48 ms 17780 KB Output is correct
4 Correct 48 ms 17616 KB Output is correct
5 Correct 43 ms 17412 KB Output is correct
6 Correct 49 ms 16308 KB Output is correct
7 Correct 63 ms 20916 KB Output is correct
8 Correct 62 ms 21948 KB Output is correct
9 Correct 69 ms 21148 KB Output is correct
10 Correct 75 ms 21316 KB Output is correct
11 Correct 69 ms 21172 KB Output is correct
12 Correct 77 ms 21936 KB Output is correct
13 Correct 70 ms 21940 KB Output is correct
14 Correct 58 ms 22772 KB Output is correct
15 Correct 69 ms 19904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 41 ms 18100 KB Output is correct
9 Correct 38 ms 16400 KB Output is correct
10 Correct 39 ms 16576 KB Output is correct
11 Correct 40 ms 16396 KB Output is correct
12 Correct 40 ms 18868 KB Output is correct
13 Correct 38 ms 19892 KB Output is correct
14 Correct 39 ms 16404 KB Output is correct
15 Correct 39 ms 17564 KB Output is correct
16 Correct 48 ms 17780 KB Output is correct
17 Correct 48 ms 17616 KB Output is correct
18 Correct 43 ms 17412 KB Output is correct
19 Correct 49 ms 16308 KB Output is correct
20 Correct 2 ms 864 KB Output is correct
21 Correct 2 ms 848 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 2 ms 780 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 45 ms 19080 KB Output is correct
27 Correct 46 ms 18612 KB Output is correct
28 Correct 55 ms 18232 KB Output is correct
29 Correct 53 ms 20268 KB Output is correct
30 Correct 48 ms 20148 KB Output is correct
31 Correct 62 ms 19388 KB Output is correct
32 Correct 63 ms 20916 KB Output is correct
33 Correct 62 ms 21948 KB Output is correct
34 Correct 69 ms 21148 KB Output is correct
35 Correct 75 ms 21316 KB Output is correct
36 Correct 69 ms 21172 KB Output is correct
37 Correct 77 ms 21936 KB Output is correct
38 Correct 70 ms 21940 KB Output is correct
39 Correct 58 ms 22772 KB Output is correct
40 Correct 69 ms 19904 KB Output is correct
41 Correct 68 ms 21684 KB Output is correct
42 Correct 70 ms 23476 KB Output is correct
43 Correct 79 ms 23732 KB Output is correct
44 Correct 80 ms 23336 KB Output is correct
45 Correct 80 ms 23476 KB Output is correct
46 Correct 78 ms 21940 KB Output is correct
47 Correct 78 ms 21940 KB Output is correct
48 Correct 71 ms 23088 KB Output is correct
49 Correct 77 ms 20088 KB Output is correct