답안 #881543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881543 2023-12-01T12:25:04 Z andrei_boaca 통행료 (IOI18_highway) C++17
100 / 100
140 ms 16136 KB
#include "highway.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int n,m,niv[100005],roots[5];
ll dist,AA,BB,d[3][100005];
int where[100005];
vector<pii> muchii[100005];
vector<pii> g;
vector<int> w;
ll memo[100005],calls;
bool inarb[300005],inx[300005];
int IND;
void bfs(int ind)
{
    for(int i=0;i<n;i++)
        d[ind][i]=1e9;
    d[ind][roots[ind]]=0;
    queue<int> coada;
    coada.push(roots[ind]);
    while(!coada.empty())
    {
        int nod=coada.front();
        coada.pop();
        for(auto i:muchii[nod])
            if(d[ind][i.first]>d[ind][nod]+1)
            {
                d[ind][i.first]=d[ind][nod]+1;
                coada.push(i.first);
            }
    }
}
ll buildniv(ll nivmax,ll ind)
{
    for(int i=0;i<m;i++)
    {
        if(inarb[i]==0)
        {
            w[i]=1;
            continue;
        }
        int a=g[i].first,b=g[i].second;
        if(max(d[ind][a],d[ind][b])<=nivmax)
            w[i]=0;
        else
            w[i]=1;
    }
    return ask(w);
}
ll buildx(int ind)
{
    for(int i=0;i<m;i++)
    {
        if(inarb[i]==0)
        {
            w[i]=1;
            continue;
        }
        int a=g[i].first,b=g[i].second;
        if(d[ind][a]<d[ind][b])
            swap(a,b);
        if(inx[a])
            w[i]=0;
        else
            w[i]=1;
    }
    return ask(w);
}
bool byniv(int i,int j)
{
    int a=max(d[IND][g[i].first],d[IND][g[i].second]);
    int b=max(d[IND][g[j].first],d[IND][g[j].second]);
    return a<b;
}
int plsfind(int ind)
{
    IND=ind;
    for(int i=0;i<m;i++)
    {
        inarb[i]=0;
        w[i]=0;
    }
    for(int i=0;i<n;i++)
        d[ind][i]=1e9;
    ll nivmax=0;
    d[ind][roots[ind]]=0;
    queue<int> coada;
    coada.push(roots[ind]);
    vector<int> edges;
    while(!coada.empty())
    {
        int nod=coada.front();
        nivmax=max(nivmax,d[ind][nod]);
        coada.pop();
        for(auto i:muchii[nod])
        {
            if(where[i.first]==ind)
            {
                if(d[ind][i.first]>d[ind][nod]+1)
                {
                    d[ind][i.first]=d[ind][nod]+1;
                    inarb[i.second]=1;
                    edges.push_back(i.second);
                    w[i.second]=1;
                    coada.push(i.first);
                }
                else if(d[ind][i.first]==d[ind][nod]+1)
                    w[i.second]=1;
            }
            else if(i.first!=roots[3-ind])
                w[i.second]=1;
        }
    }
    //sort(edges.begin(),edges.end(),byniv);
    /*ll val=ask(w);
    if(val==dist*AA)
        return roots[ind];*/
    ll st=-1;
    ll dr=edges.size();
    dr--;
    ll ans=-1;
    int poz=0;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        for(int i:edges)
            w[i]=1;
        for(int j=0;j<=mij;j++)
            w[edges[j]]=0;
        ll x=ask(w);
        if(x!=dist*AA)
            st=mij+1;
        else
        {
            if(mij==-1)
            {
                ans=-1;
                break;
            }
            int p=edges[mij];
            int a=g[p].first;
            int b=g[p].second;
            if(d[ind][a]<d[ind][b])
                swap(a,b);
            ans=a;
            dr=mij-1;
        }
    }
    if(ans==-1)
        return roots[ind];
    return ans;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
    AA=A;
    BB=B;
    n=N;
    m=U.size();
    for(int i=0;i<m;i++)
    {
        int a=U[i],b=V[i];
        g.push_back({a,b});
        muchii[a].push_back({b,i});
        muchii[b].push_back({a,i});
    }
    w.resize(m);
    dist=ask(w)/A;
    ll st=0;
    ll dr=m-1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        for(int i=0;i<m;i++)
        {
            if(i<=mij)
                w[i]=1;
            else
                w[i]=0;
        }
        ll val=ask(w);
        if(val>dist*A)
        {
            roots[1]=g[mij].first;
            roots[2]=g[mij].second;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    bfs(1);
    bfs(2);
    for(int i=0;i<n;i++)
    {
        if(d[1][i]<d[2][i])
            where[i]=1;
        if(d[2][i]<d[1][i])
            where[i]=2;
    }
    int S=plsfind(1);
    int T=plsfind(2);
    answer(S,T);
}

Compilation message

highway.cpp: In function 'int plsfind(int)':
highway.cpp:125:9: warning: unused variable 'poz' [-Wunused-variable]
  125 |     int poz=0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6620 KB Output is correct
2 Correct 1 ms 6608 KB Output is correct
3 Correct 1 ms 6616 KB Output is correct
4 Correct 1 ms 6624 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6612 KB Output is correct
7 Correct 2 ms 6616 KB Output is correct
8 Correct 1 ms 6612 KB Output is correct
9 Correct 1 ms 6612 KB Output is correct
10 Correct 1 ms 6624 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6676 KB Output is correct
2 Correct 10 ms 7464 KB Output is correct
3 Correct 81 ms 13604 KB Output is correct
4 Correct 89 ms 13624 KB Output is correct
5 Correct 115 ms 13640 KB Output is correct
6 Correct 85 ms 13400 KB Output is correct
7 Correct 97 ms 14064 KB Output is correct
8 Correct 81 ms 13568 KB Output is correct
9 Correct 83 ms 13676 KB Output is correct
10 Correct 87 ms 13564 KB Output is correct
11 Correct 90 ms 12876 KB Output is correct
12 Correct 90 ms 12968 KB Output is correct
13 Correct 80 ms 13184 KB Output is correct
14 Correct 86 ms 12784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7312 KB Output is correct
2 Correct 17 ms 7932 KB Output is correct
3 Correct 23 ms 8612 KB Output is correct
4 Correct 67 ms 12428 KB Output is correct
5 Correct 66 ms 12588 KB Output is correct
6 Correct 71 ms 12748 KB Output is correct
7 Correct 65 ms 12792 KB Output is correct
8 Correct 71 ms 12700 KB Output is correct
9 Correct 78 ms 12868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6672 KB Output is correct
2 Correct 11 ms 7408 KB Output is correct
3 Correct 62 ms 12228 KB Output is correct
4 Correct 86 ms 13392 KB Output is correct
5 Correct 77 ms 13396 KB Output is correct
6 Correct 68 ms 13536 KB Output is correct
7 Correct 83 ms 13448 KB Output is correct
8 Correct 80 ms 13620 KB Output is correct
9 Correct 83 ms 13596 KB Output is correct
10 Correct 84 ms 13388 KB Output is correct
11 Correct 85 ms 13044 KB Output is correct
12 Correct 87 ms 12788 KB Output is correct
13 Correct 87 ms 12760 KB Output is correct
14 Correct 99 ms 12648 KB Output is correct
15 Correct 77 ms 13404 KB Output is correct
16 Correct 78 ms 13564 KB Output is correct
17 Correct 85 ms 13440 KB Output is correct
18 Correct 82 ms 12804 KB Output is correct
19 Correct 80 ms 13404 KB Output is correct
20 Correct 78 ms 12788 KB Output is correct
21 Correct 79 ms 13588 KB Output is correct
22 Correct 64 ms 13548 KB Output is correct
23 Correct 77 ms 13156 KB Output is correct
24 Correct 79 ms 13064 KB Output is correct
25 Correct 86 ms 13288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 7404 KB Output is correct
2 Correct 11 ms 7528 KB Output is correct
3 Correct 96 ms 13816 KB Output is correct
4 Correct 116 ms 14424 KB Output is correct
5 Correct 123 ms 15612 KB Output is correct
6 Correct 130 ms 15296 KB Output is correct
7 Correct 126 ms 15472 KB Output is correct
8 Correct 131 ms 15324 KB Output is correct
9 Correct 91 ms 13452 KB Output is correct
10 Correct 88 ms 14120 KB Output is correct
11 Correct 99 ms 14180 KB Output is correct
12 Correct 124 ms 14960 KB Output is correct
13 Correct 127 ms 15476 KB Output is correct
14 Correct 129 ms 15464 KB Output is correct
15 Correct 126 ms 15328 KB Output is correct
16 Correct 112 ms 14800 KB Output is correct
17 Correct 82 ms 14300 KB Output is correct
18 Correct 80 ms 14016 KB Output is correct
19 Correct 77 ms 13804 KB Output is correct
20 Correct 84 ms 14048 KB Output is correct
21 Correct 126 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 7380 KB Output is correct
2 Correct 12 ms 7472 KB Output is correct
3 Correct 104 ms 13900 KB Output is correct
4 Correct 103 ms 13924 KB Output is correct
5 Correct 112 ms 14440 KB Output is correct
6 Correct 126 ms 15216 KB Output is correct
7 Correct 91 ms 14172 KB Output is correct
8 Correct 103 ms 14480 KB Output is correct
9 Correct 115 ms 14112 KB Output is correct
10 Correct 134 ms 15308 KB Output is correct
11 Correct 136 ms 15424 KB Output is correct
12 Correct 129 ms 15468 KB Output is correct
13 Correct 101 ms 14180 KB Output is correct
14 Correct 96 ms 14152 KB Output is correct
15 Correct 95 ms 14164 KB Output is correct
16 Correct 95 ms 13900 KB Output is correct
17 Correct 104 ms 14172 KB Output is correct
18 Correct 100 ms 14328 KB Output is correct
19 Correct 115 ms 15216 KB Output is correct
20 Correct 136 ms 15120 KB Output is correct
21 Correct 123 ms 15476 KB Output is correct
22 Correct 127 ms 15216 KB Output is correct
23 Correct 135 ms 15436 KB Output is correct
24 Correct 130 ms 15464 KB Output is correct
25 Correct 139 ms 15656 KB Output is correct
26 Correct 140 ms 15284 KB Output is correct
27 Correct 83 ms 13816 KB Output is correct
28 Correct 85 ms 13868 KB Output is correct
29 Correct 85 ms 14268 KB Output is correct
30 Correct 77 ms 13776 KB Output is correct
31 Correct 74 ms 13932 KB Output is correct
32 Correct 77 ms 14040 KB Output is correct
33 Correct 82 ms 13904 KB Output is correct
34 Correct 83 ms 13680 KB Output is correct
35 Correct 75 ms 13712 KB Output is correct
36 Correct 85 ms 13992 KB Output is correct
37 Correct 81 ms 14032 KB Output is correct
38 Correct 86 ms 14052 KB Output is correct
39 Correct 119 ms 15636 KB Output is correct
40 Correct 134 ms 16136 KB Output is correct
41 Correct 120 ms 15900 KB Output is correct
42 Correct 137 ms 15332 KB Output is correct