Submission #965531

# Submission time Handle Problem Language Result Execution time Memory
965531 2024-04-18T19:39:12 Z FEDIKUS Highway Tolls (IOI18_highway) C++17
100 / 100
191 ms 11964 KB
#include "highway.h"
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int maxn=90010;

vector<pair<int,int> > g[maxn];
int intime[maxn];
bool posetio[maxn];
vector<int> nisu;
bool jesu[2*maxn];
vector<int> red1;
vector<int> red2;

void bfs(int n,int m,int prva,int poc1,int poc2){
  queue<pair<int,int> > bfs;
  bfs.push({poc1,poc1});
  bfs.push({poc2,poc2});
  posetio[poc1]=true;
  posetio[poc2]=true;
  red1.push_back(prva);
  red2.push_back(prva);
  jesu[prva]=true;

  int t=0;

  while(!bfs.empty()){
    auto [node,odakle]=bfs.front();
    intime[node]=t++;
    bfs.pop();

    for(auto [u,ind]:g[node]){
      if(posetio[u]) continue;
      posetio[u]=true;
      bfs.push({u,odakle});

      if(odakle==poc1) red1.push_back(ind);
      else red2.push_back(ind);

      jesu[ind]=true;
    }
  }
  for(int i=0;i<m;i++) if(!jesu[i]) nisu.push_back(i);
}

bool bio[maxn];
set<int> tren;
vector<int> red;

int uradi(int n,int m,ll bez,int prva,int poc1,int poc2,vector<int> &u,vector<int> &v){
  int l=0;
  int r=int(red.size())-1; // ?
  int ret=-1;
  while(l<=r){
    int mid=l+(r-l)/2;

    vector<int> w(m,0);
    for(int i:nisu) w[i]=1;
    for(int i=mid;i<int(red.size());i++){
      w[red[i]]=1;
    }
    if(ask(w)>bez){
      ret=mid;
      l=mid+1;
    }else r=mid-1;
  }

  if(ret==0) return poc2;

  if(intime[u[red[ret]]]>intime[v[red[ret]]]){
    return u[red[ret]];
  }else return v[red[ret]];
}

void find_pair(int n,vector<int> u,vector<int> v,int a,int b) {
  int m=u.size();
  int prva=0;
  int l=1,r=m;
  ll bez=ask(vector<int>(m,0));
  while(l<=r){
    int mid=l+(r-l)/2;
    vector<int> w(m,0);
    fill(w.begin(),w.begin()+mid,1);
    if(ask(w)>bez){
      prva=mid;
      r=mid-1;
    }else l=mid+1;
  }

  prva--;

  for(int i=0;i<m;i++){
    g[u[i]].push_back({v[i],i});
    g[v[i]].push_back({u[i],i});
  }

  bfs(n,m,prva,u[prva],v[prva]);

  swap(red1,red2);

  red=red1;
  int lik1=uradi(n,m,bez,prva,u[prva],v[prva],u,v);
  red=red2;
  int lik2=uradi(n,m,bez,prva,v[prva],u[prva],u,v);

  answer(lik1,lik2);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3092 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 1 ms 3344 KB Output is correct
4 Correct 1 ms 3092 KB Output is correct
5 Correct 1 ms 3092 KB Output is correct
6 Correct 1 ms 3088 KB Output is correct
7 Correct 2 ms 3088 KB Output is correct
8 Correct 1 ms 3092 KB Output is correct
9 Correct 1 ms 3088 KB Output is correct
10 Correct 1 ms 3088 KB Output is correct
11 Correct 1 ms 3088 KB Output is correct
12 Correct 1 ms 3092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3116 KB Output is correct
2 Correct 15 ms 3768 KB Output is correct
3 Correct 77 ms 9092 KB Output is correct
4 Correct 111 ms 9176 KB Output is correct
5 Correct 106 ms 9576 KB Output is correct
6 Correct 107 ms 9040 KB Output is correct
7 Correct 94 ms 9080 KB Output is correct
8 Correct 81 ms 9064 KB Output is correct
9 Correct 112 ms 9096 KB Output is correct
10 Correct 75 ms 9308 KB Output is correct
11 Correct 82 ms 8840 KB Output is correct
12 Correct 93 ms 8964 KB Output is correct
13 Correct 109 ms 8940 KB Output is correct
14 Correct 131 ms 8720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3716 KB Output is correct
2 Correct 17 ms 4344 KB Output is correct
3 Correct 22 ms 5264 KB Output is correct
4 Correct 88 ms 8700 KB Output is correct
5 Correct 75 ms 8704 KB Output is correct
6 Correct 105 ms 8604 KB Output is correct
7 Correct 67 ms 8700 KB Output is correct
8 Correct 65 ms 8564 KB Output is correct
9 Correct 76 ms 8488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3112 KB Output is correct
2 Correct 11 ms 3804 KB Output is correct
3 Correct 83 ms 7788 KB Output is correct
4 Correct 86 ms 9304 KB Output is correct
5 Correct 96 ms 9080 KB Output is correct
6 Correct 82 ms 9080 KB Output is correct
7 Correct 79 ms 9316 KB Output is correct
8 Correct 97 ms 9068 KB Output is correct
9 Correct 87 ms 9624 KB Output is correct
10 Correct 102 ms 9104 KB Output is correct
11 Correct 130 ms 8680 KB Output is correct
12 Correct 84 ms 8496 KB Output is correct
13 Correct 91 ms 8824 KB Output is correct
14 Correct 87 ms 8808 KB Output is correct
15 Correct 70 ms 9096 KB Output is correct
16 Correct 83 ms 9096 KB Output is correct
17 Correct 81 ms 8744 KB Output is correct
18 Correct 125 ms 8904 KB Output is correct
19 Correct 75 ms 9360 KB Output is correct
20 Correct 98 ms 8684 KB Output is correct
21 Correct 67 ms 9264 KB Output is correct
22 Correct 69 ms 9256 KB Output is correct
23 Correct 74 ms 9708 KB Output is correct
24 Correct 98 ms 9308 KB Output is correct
25 Correct 88 ms 8624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3812 KB Output is correct
2 Correct 13 ms 4104 KB Output is correct
3 Correct 107 ms 9560 KB Output is correct
4 Correct 125 ms 10804 KB Output is correct
5 Correct 139 ms 11964 KB Output is correct
6 Correct 151 ms 11632 KB Output is correct
7 Correct 129 ms 11528 KB Output is correct
8 Correct 162 ms 11516 KB Output is correct
9 Correct 95 ms 9724 KB Output is correct
10 Correct 107 ms 10204 KB Output is correct
11 Correct 93 ms 10424 KB Output is correct
12 Correct 161 ms 11176 KB Output is correct
13 Correct 145 ms 11804 KB Output is correct
14 Correct 154 ms 11540 KB Output is correct
15 Correct 139 ms 11924 KB Output is correct
16 Correct 112 ms 10340 KB Output is correct
17 Correct 85 ms 9456 KB Output is correct
18 Correct 100 ms 9928 KB Output is correct
19 Correct 74 ms 9380 KB Output is correct
20 Correct 96 ms 9848 KB Output is correct
21 Correct 170 ms 11904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3816 KB Output is correct
2 Correct 17 ms 3888 KB Output is correct
3 Correct 132 ms 9796 KB Output is correct
4 Correct 148 ms 10188 KB Output is correct
5 Correct 144 ms 10272 KB Output is correct
6 Correct 133 ms 11420 KB Output is correct
7 Correct 87 ms 10036 KB Output is correct
8 Correct 86 ms 10136 KB Output is correct
9 Correct 103 ms 10864 KB Output is correct
10 Correct 153 ms 11756 KB Output is correct
11 Correct 171 ms 11520 KB Output is correct
12 Correct 138 ms 11652 KB Output is correct
13 Correct 168 ms 10196 KB Output is correct
14 Correct 112 ms 10128 KB Output is correct
15 Correct 121 ms 10188 KB Output is correct
16 Correct 94 ms 9952 KB Output is correct
17 Correct 158 ms 10632 KB Output is correct
18 Correct 94 ms 10364 KB Output is correct
19 Correct 116 ms 11564 KB Output is correct
20 Correct 126 ms 11580 KB Output is correct
21 Correct 191 ms 11764 KB Output is correct
22 Correct 116 ms 11712 KB Output is correct
23 Correct 126 ms 11776 KB Output is correct
24 Correct 160 ms 11424 KB Output is correct
25 Correct 176 ms 11836 KB Output is correct
26 Correct 179 ms 11856 KB Output is correct
27 Correct 80 ms 9804 KB Output is correct
28 Correct 78 ms 9932 KB Output is correct
29 Correct 73 ms 9760 KB Output is correct
30 Correct 115 ms 9560 KB Output is correct
31 Correct 80 ms 9792 KB Output is correct
32 Correct 84 ms 9508 KB Output is correct
33 Correct 69 ms 9528 KB Output is correct
34 Correct 114 ms 9620 KB Output is correct
35 Correct 73 ms 9568 KB Output is correct
36 Correct 90 ms 9464 KB Output is correct
37 Correct 106 ms 9488 KB Output is correct
38 Correct 77 ms 10276 KB Output is correct
39 Correct 131 ms 11516 KB Output is correct
40 Correct 142 ms 11904 KB Output is correct
41 Correct 126 ms 11744 KB Output is correct
42 Correct 132 ms 11404 KB Output is correct