답안 #1106304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106304 2024-10-29T19:42:17 Z Arturgo 나일강 (IOI24_nile) C++17
100 / 100
85 ms 21164 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 2 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 16316 KB Output is correct
2 Correct 37 ms 16340 KB Output is correct
3 Correct 37 ms 16308 KB Output is correct
4 Correct 38 ms 16316 KB Output is correct
5 Correct 37 ms 16308 KB Output is correct
6 Correct 43 ms 16308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 16308 KB Output is correct
2 Correct 44 ms 16564 KB Output is correct
3 Correct 51 ms 16336 KB Output is correct
4 Correct 48 ms 16276 KB Output is correct
5 Correct 42 ms 16316 KB Output is correct
6 Correct 51 ms 16308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 648 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 648 KB Output is correct
7 Correct 37 ms 16316 KB Output is correct
8 Correct 37 ms 16340 KB Output is correct
9 Correct 37 ms 16308 KB Output is correct
10 Correct 38 ms 16316 KB Output is correct
11 Correct 37 ms 16308 KB Output is correct
12 Correct 43 ms 16308 KB Output is correct
13 Correct 38 ms 16308 KB Output is correct
14 Correct 44 ms 16564 KB Output is correct
15 Correct 51 ms 16336 KB Output is correct
16 Correct 48 ms 16276 KB Output is correct
17 Correct 42 ms 16316 KB Output is correct
18 Correct 51 ms 16308 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 48 ms 17312 KB Output is correct
26 Correct 44 ms 16820 KB Output is correct
27 Correct 53 ms 16308 KB Output is correct
28 Correct 58 ms 16308 KB Output is correct
29 Correct 48 ms 16320 KB Output is correct
30 Correct 59 ms 16440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 16308 KB Output is correct
2 Correct 44 ms 16564 KB Output is correct
3 Correct 51 ms 16336 KB Output is correct
4 Correct 48 ms 16276 KB Output is correct
5 Correct 42 ms 16316 KB Output is correct
6 Correct 51 ms 16308 KB Output is correct
7 Correct 59 ms 19892 KB Output is correct
8 Correct 60 ms 19892 KB Output is correct
9 Correct 68 ms 20104 KB Output is correct
10 Correct 68 ms 19888 KB Output is correct
11 Correct 73 ms 20032 KB Output is correct
12 Correct 68 ms 19892 KB Output is correct
13 Correct 68 ms 19892 KB Output is correct
14 Correct 58 ms 19900 KB Output is correct
15 Correct 69 ms 19900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 648 KB Output is correct
8 Correct 37 ms 16316 KB Output is correct
9 Correct 37 ms 16340 KB Output is correct
10 Correct 37 ms 16308 KB Output is correct
11 Correct 38 ms 16316 KB Output is correct
12 Correct 37 ms 16308 KB Output is correct
13 Correct 43 ms 16308 KB Output is correct
14 Correct 38 ms 16308 KB Output is correct
15 Correct 44 ms 16564 KB Output is correct
16 Correct 51 ms 16336 KB Output is correct
17 Correct 48 ms 16276 KB Output is correct
18 Correct 42 ms 16316 KB Output is correct
19 Correct 51 ms 16308 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 48 ms 17312 KB Output is correct
27 Correct 44 ms 16820 KB Output is correct
28 Correct 53 ms 16308 KB Output is correct
29 Correct 58 ms 16308 KB Output is correct
30 Correct 48 ms 16320 KB Output is correct
31 Correct 59 ms 16440 KB Output is correct
32 Correct 59 ms 19892 KB Output is correct
33 Correct 60 ms 19892 KB Output is correct
34 Correct 68 ms 20104 KB Output is correct
35 Correct 68 ms 19888 KB Output is correct
36 Correct 73 ms 20032 KB Output is correct
37 Correct 68 ms 19892 KB Output is correct
38 Correct 68 ms 19892 KB Output is correct
39 Correct 58 ms 19900 KB Output is correct
40 Correct 69 ms 19900 KB Output is correct
41 Correct 67 ms 19896 KB Output is correct
42 Correct 66 ms 21164 KB Output is correct
43 Correct 85 ms 19892 KB Output is correct
44 Correct 75 ms 20012 KB Output is correct
45 Correct 74 ms 20916 KB Output is correct
46 Correct 76 ms 19908 KB Output is correct
47 Correct 74 ms 19892 KB Output is correct
48 Correct 65 ms 19904 KB Output is correct
49 Correct 80 ms 19888 KB Output is correct