답안 #934885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934885 2024-02-28T06:19:12 Z sleepntsheep 통행료 (IOI18_highway) C++17
51 / 100
138 ms 10696 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;

int ban[130000],n,m,a,b;std::vector<int>u,v;std::vector<std::pair<int,int>>g[90001];

int sub12(int src)
{
    vector<int>d(n,1e9),e(n,-1);
    queue<pair<int,int>>q;
    q.emplace(d[src]=src,src);
    while(q.size()){auto[c,u]=q.front();q.pop();for(auto[v,i]:g[u])if(!ban[i]&&d[v]>c+1)q.emplace(d[v]=c+1,v),e[v]=i;}


    long long need; {vector<int>qq(m);for(int i=0;i<n;++i)if(~e[i])qq[e[i]]=1;need=ask(qq);}

    vector<int>c;
    for(int i=0;i<n;++i)if(d[i]<1e9)c.push_back(i);
    sort(c.begin(),c.end(),[&d](int i,int v){return d[i]<d[v];});

    //cout << " SUB12 "<<'\n'; for(auto x:c)cout<<"  "<<x;cout<<'\n';



    int z=0,l=0,r=c.size()-1;
    while(l<=r){
        int y=(l+r)/2;
        vector<int>qq(m,0);
        for(int i=1;i<=y;++i)if(~e[c[i]])qq[e[c[i]]]=1;
        if (ask(qq)==need)z=c[y],r=y-1;
        else l=y+1;
    }
    return z;
}

void sub1234(){
    long long need; {vector<int>qq(m,1); need=ask(qq);}
    auto dt = need / b;
    long long light = dt * a;

    int e1,l=0,r=m-1;
    while(l<=r) {
        int y=(l+r)/2;
        vector<int>qq(m);
        for(int i=0;i<=y;++i)qq[i]=1;
        if(ask(qq)>light)r=y-1,e1=y;
        else l=y+1;
    }


    int p=u[e1],q=v[e1];
    ban[e1]=1;
    int s=sub12(p);
    int t=sub12(q);

    if(0){
    cout<<p<<' ' <<b+(dt-1)*a<<'\n';
    cout<<q<<' ' <<need-(b+(dt-1)*a)<<'\n';
    cout<<s<<' '<<t<<endl;
    }
    answer(s,t);
}

void find_pair(int n_, std::vector<int> u_, std::vector<int> v_, int A_, int B_) {
    n=n_,u=u_,v=v_,a=A_,b=B_;m=u.size();
    for(int i=0;i<m;++i)g[u[i]].push_back({v[i],i}),g[v[i]].push_back({u[i],i});

    sub1234();

}

Compilation message

highway.cpp: In function 'void sub1234()':
highway.cpp:51:15: warning: 'e1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |     int p=u[e1],q=v[e1];
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2676 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2672 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2732 KB Output is correct
2 Correct 10 ms 3632 KB Output is correct
3 Correct 87 ms 10000 KB Output is correct
4 Correct 114 ms 9976 KB Output is correct
5 Correct 86 ms 9776 KB Output is correct
6 Correct 81 ms 9796 KB Output is correct
7 Correct 80 ms 10012 KB Output is correct
8 Correct 88 ms 9788 KB Output is correct
9 Correct 109 ms 9792 KB Output is correct
10 Correct 93 ms 9772 KB Output is correct
11 Correct 104 ms 9372 KB Output is correct
12 Correct 120 ms 9088 KB Output is correct
13 Correct 126 ms 9148 KB Output is correct
14 Correct 115 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3512 KB Output is correct
2 Correct 14 ms 4116 KB Output is correct
3 Correct 22 ms 4700 KB Output is correct
4 Correct 73 ms 9400 KB Output is correct
5 Correct 75 ms 9128 KB Output is correct
6 Correct 67 ms 9656 KB Output is correct
7 Correct 73 ms 9156 KB Output is correct
8 Correct 69 ms 9156 KB Output is correct
9 Correct 67 ms 9148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2732 KB Output is correct
2 Correct 15 ms 3452 KB Output is correct
3 Correct 60 ms 8108 KB Output is correct
4 Correct 92 ms 10020 KB Output is correct
5 Correct 105 ms 9752 KB Output is correct
6 Correct 91 ms 9992 KB Output is correct
7 Correct 75 ms 9776 KB Output is correct
8 Correct 87 ms 10016 KB Output is correct
9 Correct 91 ms 9976 KB Output is correct
10 Correct 126 ms 10264 KB Output is correct
11 Correct 122 ms 9392 KB Output is correct
12 Correct 98 ms 9332 KB Output is correct
13 Correct 138 ms 9388 KB Output is correct
14 Correct 119 ms 9368 KB Output is correct
15 Correct 82 ms 9792 KB Output is correct
16 Correct 113 ms 9792 KB Output is correct
17 Correct 95 ms 9596 KB Output is correct
18 Correct 94 ms 9632 KB Output is correct
19 Correct 75 ms 9784 KB Output is correct
20 Correct 86 ms 9156 KB Output is correct
21 Correct 81 ms 10696 KB Output is correct
22 Correct 77 ms 10108 KB Output is correct
23 Correct 88 ms 9984 KB Output is correct
24 Correct 88 ms 9912 KB Output is correct
25 Correct 87 ms 9260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 3612 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3520 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -