Submission #881541

# Submission time Handle Problem Language Result Execution time Memory
881541 2023-12-01T12:21:53 Z andrei_boaca Highway Tolls (IOI18_highway) C++17
90 / 100
200 ms 15908 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=0;
    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);
        int p=edges[mij];
        int a=g[p].first;
        int b=g[p].second;
        if(x!=dist*AA)
            st=mij+1;
        else
        {
            poz=mij;
            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: variable 'poz' set but not used [-Wunused-but-set-variable]
  125 |     int poz=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6620 KB Output is correct
2 Correct 2 ms 6616 KB Output is correct
3 Correct 1 ms 6612 KB Output is correct
4 Correct 1 ms 6616 KB Output is correct
5 Correct 1 ms 6616 KB Output is correct
6 Correct 2 ms 6616 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6616 KB Output is correct
9 Correct 1 ms 6616 KB Output is correct
10 Correct 1 ms 6620 KB Output is correct
11 Correct 1 ms 6608 KB Output is correct
12 Correct 1 ms 6616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6676 KB Output is correct
2 Correct 10 ms 7460 KB Output is correct
3 Correct 104 ms 13848 KB Output is correct
4 Correct 88 ms 13848 KB Output is correct
5 Correct 134 ms 13632 KB Output is correct
6 Correct 112 ms 13396 KB Output is correct
7 Correct 97 ms 13844 KB Output is correct
8 Correct 93 ms 13392 KB Output is correct
9 Correct 126 ms 13380 KB Output is correct
10 Correct 91 ms 13936 KB Output is correct
11 Correct 116 ms 13104 KB Output is correct
12 Correct 98 ms 12740 KB Output is correct
13 Correct 87 ms 12808 KB Output is correct
14 Correct 99 ms 13020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7392 KB Output is correct
2 Correct 17 ms 7924 KB Output is correct
3 Correct 25 ms 8784 KB Output is correct
4 Correct 61 ms 12672 KB Output is correct
5 Correct 64 ms 12676 KB Output is correct
6 Correct 65 ms 13008 KB Output is correct
7 Correct 70 ms 12804 KB Output is correct
8 Correct 75 ms 12676 KB Output is correct
9 Correct 61 ms 12904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6676 KB Output is correct
2 Correct 11 ms 7336 KB Output is correct
3 Correct 66 ms 11980 KB Output is correct
4 Correct 134 ms 13392 KB Output is correct
5 Correct 115 ms 13380 KB Output is correct
6 Correct 88 ms 13872 KB Output is correct
7 Correct 69 ms 13404 KB Output is correct
8 Correct 79 ms 13864 KB Output is correct
9 Correct 120 ms 13836 KB Output is correct
10 Correct 94 ms 13396 KB Output is correct
11 Correct 87 ms 13044 KB Output is correct
12 Correct 82 ms 12768 KB Output is correct
13 Correct 92 ms 12976 KB Output is correct
14 Correct 113 ms 13140 KB Output is correct
15 Correct 87 ms 13560 KB Output is correct
16 Correct 90 ms 13540 KB Output is correct
17 Correct 92 ms 12788 KB Output is correct
18 Correct 89 ms 13260 KB Output is correct
19 Correct 103 ms 13636 KB Output is correct
20 Correct 84 ms 12804 KB Output is correct
21 Correct 98 ms 13544 KB Output is correct
22 Correct 104 ms 13544 KB Output is correct
23 Correct 89 ms 13396 KB Output is correct
24 Correct 97 ms 13304 KB Output is correct
25 Correct 91 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 7404 KB Output is correct
2 Correct 12 ms 7484 KB Output is correct
3 Correct 101 ms 14144 KB Output is correct
4 Correct 143 ms 14380 KB Output is correct
5 Correct 130 ms 15592 KB Output is correct
6 Correct 143 ms 15280 KB Output is correct
7 Correct 182 ms 15656 KB Output is correct
8 Correct 166 ms 15204 KB Output is correct
9 Correct 96 ms 13756 KB Output is correct
10 Correct 85 ms 14092 KB Output is correct
11 Correct 104 ms 14628 KB Output is correct
12 Correct 115 ms 14756 KB Output is correct
13 Correct 142 ms 15724 KB Output is correct
14 Correct 180 ms 15504 KB Output is correct
15 Correct 184 ms 15548 KB Output is correct
16 Correct 109 ms 14352 KB Output is correct
17 Correct 86 ms 13828 KB Output is correct
18 Correct 109 ms 14004 KB Output is correct
19 Correct 85 ms 13936 KB Output is correct
20 Correct 92 ms 13988 KB Output is correct
21 Correct 125 ms 15636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7376 KB Output is correct
2 Correct 12 ms 7532 KB Output is correct
3 Correct 117 ms 13936 KB Output is correct
4 Correct 153 ms 14144 KB Output is correct
5 Correct 115 ms 14196 KB Output is correct
6 Correct 163 ms 15212 KB Output is correct
7 Correct 128 ms 14304 KB Output is correct
8 Correct 141 ms 14040 KB Output is correct
9 Correct 171 ms 14332 KB Output is correct
10 Partially correct 200 ms 15672 KB Output is partially correct
11 Correct 142 ms 15452 KB Output is correct
12 Correct 166 ms 15684 KB Output is correct
13 Correct 120 ms 14168 KB Output is correct
14 Correct 98 ms 14140 KB Output is correct
15 Correct 158 ms 14216 KB Output is correct
16 Correct 92 ms 13896 KB Output is correct
17 Correct 135 ms 14392 KB Output is correct
18 Correct 159 ms 14336 KB Output is correct
19 Correct 156 ms 15000 KB Output is correct
20 Correct 183 ms 15568 KB Output is correct
21 Correct 132 ms 15372 KB Output is correct
22 Correct 142 ms 15220 KB Output is correct
23 Correct 160 ms 15420 KB Output is correct
24 Correct 142 ms 15472 KB Output is correct
25 Correct 160 ms 15500 KB Output is correct
26 Correct 139 ms 15664 KB Output is correct
27 Correct 80 ms 13964 KB Output is correct
28 Correct 116 ms 13868 KB Output is correct
29 Correct 72 ms 14208 KB Output is correct
30 Correct 69 ms 13776 KB Output is correct
31 Correct 89 ms 14160 KB Output is correct
32 Correct 88 ms 13616 KB Output is correct
33 Correct 81 ms 14344 KB Output is correct
34 Correct 105 ms 13984 KB Output is correct
35 Correct 79 ms 13704 KB Output is correct
36 Correct 87 ms 13844 KB Output is correct
37 Correct 77 ms 13812 KB Output is correct
38 Correct 110 ms 13812 KB Output is correct
39 Correct 126 ms 15860 KB Output is correct
40 Partially correct 128 ms 15720 KB Output is partially correct
41 Correct 117 ms 15908 KB Output is correct
42 Partially correct 180 ms 15544 KB Output is partially correct