Submission #293177

# Submission time Handle Problem Language Result Execution time Memory
293177 2020-09-07T17:36:25 Z egekabas Highway Tolls (IOI18_highway) C++14
100 / 100
306 ms 14808 KB
#include "highway.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
vector<int> w;
vector<pii> g[100000];
int vis[100000];
vector<int> vec[2];
vector<int> u, v;
ll begval;
int col[100000];
int get(vector<int> &vec){
    int l = 0, r = vec.size()-1;
    while(l < r){
        int m = (l+r)/2;
        for(int i = m+1; i <= r; ++i)
            col[vec[i]] = 1;
        for(int i = 0; i < u.size(); ++i)
            if(col[u[i]] != col[v[i]])
                w[i] = 1;
        if(ask(w) == begval)
            r = m;
        else
            l = m+1;
        for(int i = 0; i < u.size(); ++i)
            w[i] = 0;
        for(int i = m+1; i <= r; ++i)
            col[vec[i]] = 0;
    }
    return vec[l];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    u = U;
    v = V;
    w.resize(U.size());
    for(int i = 0; i < U.size(); ++i){
        g[U[i]].pb({V[i], i});
        g[V[i]].pb({U[i], i});
    }
    begval = ask(w);
    int l = 0, r = U.size()-1;
    while(l < r){
        int m = (l+r)/2;
        for(int i = l; i <= m; ++i)
            w[i] = 1;
        if(ask(w) != begval)
            r = m;
        else
            l = m+1;
        for(int i = l; i <= m; ++i)
            w[i] = 0;
    }
    int e = l;
    queue<pii> q;
    q.push({0, U[e]});
    q.push({1, V[e]});
    vis[U[e]] = vis[V[e]] = 1;
    while(q.size()){
        int type = q.front().ff;
        int v = q.front().ss;
        q.pop();
        vec[type].pb(v);
        for(auto u : g[v])
            if(vis[u.ff] == 0){
                vis[u.ff] = 1;
                q.push({type, u.ff});
            }
    }
    answer(get(vec[0]), get(vec[1]));
}   

Compilation message

highway.cpp: In function 'int get(std::vector<int>&)':
highway.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i = 0; i < u.size(); ++i)
      |                        ~~^~~~~~~~~~
highway.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0; i < u.size(); ++i)
      |                        ~~^~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0; i < U.size(); ++i){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 12 ms 3684 KB Output is correct
3 Correct 215 ms 11196 KB Output is correct
4 Correct 172 ms 11128 KB Output is correct
5 Correct 172 ms 11112 KB Output is correct
6 Correct 200 ms 11188 KB Output is correct
7 Correct 191 ms 11144 KB Output is correct
8 Correct 156 ms 11108 KB Output is correct
9 Correct 177 ms 11128 KB Output is correct
10 Correct 175 ms 11216 KB Output is correct
11 Correct 158 ms 11092 KB Output is correct
12 Correct 160 ms 11016 KB Output is correct
13 Correct 199 ms 11080 KB Output is correct
14 Correct 157 ms 11024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 28 ms 4472 KB Output is correct
3 Correct 43 ms 5436 KB Output is correct
4 Correct 120 ms 10608 KB Output is correct
5 Correct 169 ms 10620 KB Output is correct
6 Correct 164 ms 10608 KB Output is correct
7 Correct 119 ms 10668 KB Output is correct
8 Correct 146 ms 10424 KB Output is correct
9 Correct 125 ms 10740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2816 KB Output is correct
2 Correct 15 ms 3704 KB Output is correct
3 Correct 108 ms 9316 KB Output is correct
4 Correct 141 ms 11084 KB Output is correct
5 Correct 141 ms 11052 KB Output is correct
6 Correct 138 ms 11068 KB Output is correct
7 Correct 189 ms 11168 KB Output is correct
8 Correct 167 ms 11056 KB Output is correct
9 Correct 206 ms 11220 KB Output is correct
10 Correct 205 ms 11248 KB Output is correct
11 Correct 159 ms 11096 KB Output is correct
12 Correct 183 ms 11108 KB Output is correct
13 Correct 198 ms 11156 KB Output is correct
14 Correct 202 ms 11152 KB Output is correct
15 Correct 168 ms 11108 KB Output is correct
16 Correct 194 ms 11124 KB Output is correct
17 Correct 202 ms 11092 KB Output is correct
18 Correct 160 ms 11128 KB Output is correct
19 Correct 142 ms 11224 KB Output is correct
20 Correct 153 ms 11024 KB Output is correct
21 Correct 168 ms 11756 KB Output is correct
22 Correct 126 ms 11796 KB Output is correct
23 Correct 192 ms 11368 KB Output is correct
24 Correct 141 ms 11376 KB Output is correct
25 Correct 153 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3704 KB Output is correct
2 Correct 18 ms 3864 KB Output is correct
3 Correct 178 ms 12032 KB Output is correct
4 Correct 254 ms 12920 KB Output is correct
5 Correct 242 ms 14780 KB Output is correct
6 Correct 272 ms 14808 KB Output is correct
7 Correct 233 ms 14668 KB Output is correct
8 Correct 304 ms 14736 KB Output is correct
9 Correct 167 ms 12228 KB Output is correct
10 Correct 184 ms 13364 KB Output is correct
11 Correct 252 ms 13436 KB Output is correct
12 Correct 284 ms 14600 KB Output is correct
13 Correct 238 ms 14652 KB Output is correct
14 Correct 281 ms 14760 KB Output is correct
15 Correct 282 ms 14572 KB Output is correct
16 Correct 222 ms 13996 KB Output is correct
17 Correct 149 ms 12128 KB Output is correct
18 Correct 157 ms 12208 KB Output is correct
19 Correct 140 ms 12200 KB Output is correct
20 Correct 146 ms 12060 KB Output is correct
21 Correct 214 ms 14376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3712 KB Output is correct
2 Correct 18 ms 3912 KB Output is correct
3 Correct 180 ms 12204 KB Output is correct
4 Correct 187 ms 12580 KB Output is correct
5 Correct 191 ms 13080 KB Output is correct
6 Correct 234 ms 14804 KB Output is correct
7 Correct 166 ms 12228 KB Output is correct
8 Correct 185 ms 12564 KB Output is correct
9 Correct 198 ms 12988 KB Output is correct
10 Correct 228 ms 14748 KB Output is correct
11 Correct 227 ms 14680 KB Output is correct
12 Correct 231 ms 14724 KB Output is correct
13 Correct 176 ms 13344 KB Output is correct
14 Correct 176 ms 13376 KB Output is correct
15 Correct 185 ms 13332 KB Output is correct
16 Correct 181 ms 13256 KB Output is correct
17 Correct 191 ms 13428 KB Output is correct
18 Correct 170 ms 13336 KB Output is correct
19 Correct 224 ms 14604 KB Output is correct
20 Correct 246 ms 14492 KB Output is correct
21 Correct 306 ms 14764 KB Output is correct
22 Correct 225 ms 14656 KB Output is correct
23 Correct 231 ms 14604 KB Output is correct
24 Correct 280 ms 14656 KB Output is correct
25 Correct 289 ms 14568 KB Output is correct
26 Correct 230 ms 14708 KB Output is correct
27 Correct 145 ms 12020 KB Output is correct
28 Correct 141 ms 11772 KB Output is correct
29 Correct 130 ms 12524 KB Output is correct
30 Correct 134 ms 11964 KB Output is correct
31 Correct 155 ms 11964 KB Output is correct
32 Correct 199 ms 12104 KB Output is correct
33 Correct 202 ms 12392 KB Output is correct
34 Correct 144 ms 11948 KB Output is correct
35 Correct 141 ms 11872 KB Output is correct
36 Correct 141 ms 12064 KB Output is correct
37 Correct 196 ms 12216 KB Output is correct
38 Correct 138 ms 12308 KB Output is correct
39 Correct 226 ms 14280 KB Output is correct
40 Correct 248 ms 14292 KB Output is correct
41 Correct 236 ms 14340 KB Output is correct
42 Correct 263 ms 14252 KB Output is correct