답안 #108800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108800 2019-05-02T07:24:52 Z tri 통행료 (IOI18_highway) C++14
100 / 100
381 ms 13056 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = false;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"); }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;

ll ask(const vi &w);

void answer(int s, int t);

int N, M;
vi e1, e2;
ll A, B;
vector<vector<pi>> aList;
ll base;

vi query;

int searchE() {
    int low = 0;
    int high = M - 1;

    while (low != high) {
        int mid = (low + high) / 2;
        for (int i = 0; i < M; i++) {
            query[i] = i <= mid;
        }
        ll res = ask(query);
        if (res == base) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    return low;
}

vi dist[3];
int cT;

void fDist(int r) {
    queue<int> q;
    q.push(r);

    dist[cT][r] = 0;

    while (q.size()) {
        int cV = q.front();
        q.pop();
        for (pi aE : aList[cV]) {
            if (dist[cT][aE.f] == -1) {
                dist[cT][aE.f] = dist[cT][cV] + 1;
                q.push(aE.f);
            }
        }
    }
}

vi t, pE;

void bTree(int r, vi &mbr) {
    queue<int> q;
    q.push(r);

    for (int j = 0; j < N; j++) {
        dist[cT][j] = -1;
    }
    dist[cT][r] = 0;
    mbr.pb(r);

    while (q.size()) {
        int cV = q.front();
        q.pop();
        for (pi aE : aList[cV]) {
            if (t[aE.f] == cT && dist[cT][aE.f] == -1) {
                dist[cT][aE.f] = dist[cT][cV] + 1;
                mbr.pb(aE.f);
                query[aE.s] = 0;
                pE[aE.f] = aE.s;

                q.push(aE.f);
            }
        }
    }
}

bool cmp(int a, int b) {
    return dist[cT][a] < dist[cT][b];
}

int find(vi &mbr) {
    sort(mbr.begin(), mbr.end(), cmp);
    reverse(mbr.begin(), mbr.end());

    if (cT == 0) {
        ps("srtd");
        ps(mbr);
    }

    //decreasing dist
    int low = 0;
    int high = mbr.size() - 1;

    while (low != high) {
        int mid = (low + high) / 2;
        for (int i = 0; i < mbr.size(); i++) {
            int cE = pE[mbr[i]];
            if(cE >= 0){
                query[cE] = i <= mid;
            }
        }
        ll res = ask(query);
        if (res == base) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }

    for (int i = 0; i < mbr.size(); i++) {
        int cE = pE[mbr[i]];
        if(cE >= 0){
            query[cE] = 0;
        }
    }
    return mbr[low];
}

void find_pair(int iN, vi ie1, vi ie2, int iA, int iB) {
    ps("start");
    N = iN;
    e1 = ie1, e2 = ie2;
    A = iA, B = iB;

    aList.resize(N);
    M = e1.size();
    for (int i = 0; i < M; i++) {
        aList[e1[i]].pb({e2[i], i});
        aList[e2[i]].pb({e1[i], i});
    }

    vi empty(M);
    for(int i = 0; i < M; i++){
        empty[i] = 0;
    }
    base = ask(empty);
    ps(base);

    query.resize(M);
    int split = searchE();
    ps("split", split, e1[split], e2[split]);

    dist[0].resize(N);
    dist[1].resize(N);
    for (int j = 0; j < N; j++) {
        dist[0][j] = -1;
        dist[1][j] = -1;
    }

    cT = 0;
    fDist(e1[split]);
    cT = 1;
    fDist(e2[split]);

    ps("dist");
    ps(dist[0]);
    ps(dist[1]);

    t.resize(N);
    pE.resize(N);
    for (int i = 0; i < N; i++) {
        pE[i] = -1;
    }
    for (int i = 0; i < N; i++) {
        t[i] = dist[0][i] > dist[1][i];
    }

    for (int i = 0; i < M; i++) {
        query[i] = 1;
    }
    query[split] = 0;

    vi mbrS, mbrT;
    cT = 0;
    bTree(ie1[split], mbrS);
    cT = 1;
    bTree(ie2[split], mbrT);

    ps("mbr");
    ps(mbrS);
    ps(mbrT);
    ps("query");
    ps(query);

    ps("pE");
    ps(pE);

    cT = 0;
    int s = find(mbrS);
    cT = 1;
    int t = find(mbrT);
    ps(s, t);
    answer(s, t);
}

Compilation message

highway.cpp: In function 'int find(vi&)':
highway.cpp:175:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < mbr.size(); i++) {
                         ~~^~~~~~~~~~~~
highway.cpp:189:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < mbr.size(); i++) {
                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 296 KB Output is correct
6 Correct 2 ms 324 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 2 ms 324 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 248 KB Output is correct
12 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 404 KB Output is correct
2 Correct 46 ms 1596 KB Output is correct
3 Correct 271 ms 10660 KB Output is correct
4 Correct 248 ms 10708 KB Output is correct
5 Correct 258 ms 10740 KB Output is correct
6 Correct 243 ms 10720 KB Output is correct
7 Correct 282 ms 10716 KB Output is correct
8 Correct 255 ms 10716 KB Output is correct
9 Correct 250 ms 10724 KB Output is correct
10 Correct 264 ms 10724 KB Output is correct
11 Correct 292 ms 10000 KB Output is correct
12 Correct 298 ms 10120 KB Output is correct
13 Correct 254 ms 10144 KB Output is correct
14 Correct 288 ms 10132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 1456 KB Output is correct
2 Correct 42 ms 2512 KB Output is correct
3 Correct 58 ms 3556 KB Output is correct
4 Correct 186 ms 10004 KB Output is correct
5 Correct 193 ms 9992 KB Output is correct
6 Correct 196 ms 10100 KB Output is correct
7 Correct 192 ms 10108 KB Output is correct
8 Correct 178 ms 10104 KB Output is correct
9 Correct 192 ms 10108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 404 KB Output is correct
2 Correct 25 ms 1412 KB Output is correct
3 Correct 170 ms 8504 KB Output is correct
4 Correct 234 ms 10708 KB Output is correct
5 Correct 234 ms 10612 KB Output is correct
6 Correct 206 ms 10640 KB Output is correct
7 Correct 232 ms 10724 KB Output is correct
8 Correct 239 ms 10628 KB Output is correct
9 Correct 256 ms 10720 KB Output is correct
10 Correct 302 ms 10724 KB Output is correct
11 Correct 291 ms 10132 KB Output is correct
12 Correct 281 ms 10136 KB Output is correct
13 Correct 300 ms 10064 KB Output is correct
14 Correct 294 ms 10008 KB Output is correct
15 Correct 236 ms 10728 KB Output is correct
16 Correct 278 ms 10756 KB Output is correct
17 Correct 321 ms 10124 KB Output is correct
18 Correct 279 ms 10096 KB Output is correct
19 Correct 240 ms 10720 KB Output is correct
20 Correct 280 ms 10164 KB Output is correct
21 Correct 201 ms 11100 KB Output is correct
22 Correct 223 ms 11100 KB Output is correct
23 Correct 204 ms 10820 KB Output is correct
24 Correct 256 ms 10780 KB Output is correct
25 Correct 291 ms 10176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1420 KB Output is correct
2 Correct 16 ms 1624 KB Output is correct
3 Correct 297 ms 11216 KB Output is correct
4 Correct 313 ms 11604 KB Output is correct
5 Correct 360 ms 13056 KB Output is correct
6 Correct 350 ms 12832 KB Output is correct
7 Correct 351 ms 12764 KB Output is correct
8 Correct 381 ms 12800 KB Output is correct
9 Correct 235 ms 8780 KB Output is correct
10 Correct 222 ms 9064 KB Output is correct
11 Correct 223 ms 10056 KB Output is correct
12 Correct 348 ms 11692 KB Output is correct
13 Correct 365 ms 12356 KB Output is correct
14 Correct 347 ms 12844 KB Output is correct
15 Correct 361 ms 12860 KB Output is correct
16 Correct 275 ms 10124 KB Output is correct
17 Correct 203 ms 10976 KB Output is correct
18 Correct 250 ms 11284 KB Output is correct
19 Correct 243 ms 11168 KB Output is correct
20 Correct 220 ms 11140 KB Output is correct
21 Correct 322 ms 12988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1428 KB Output is correct
2 Correct 56 ms 1612 KB Output is correct
3 Correct 304 ms 11084 KB Output is correct
4 Correct 306 ms 11292 KB Output is correct
5 Correct 312 ms 11572 KB Output is correct
6 Correct 369 ms 12744 KB Output is correct
7 Correct 259 ms 11244 KB Output is correct
8 Correct 305 ms 11408 KB Output is correct
9 Correct 321 ms 11580 KB Output is correct
10 Correct 341 ms 12800 KB Output is correct
11 Correct 345 ms 12880 KB Output is correct
12 Correct 345 ms 12832 KB Output is correct
13 Correct 259 ms 10020 KB Output is correct
14 Correct 255 ms 9068 KB Output is correct
15 Correct 258 ms 9936 KB Output is correct
16 Correct 235 ms 9068 KB Output is correct
17 Correct 280 ms 9916 KB Output is correct
18 Correct 246 ms 9100 KB Output is correct
19 Correct 353 ms 11700 KB Output is correct
20 Correct 334 ms 12312 KB Output is correct
21 Correct 364 ms 12816 KB Output is correct
22 Correct 344 ms 12800 KB Output is correct
23 Correct 352 ms 12820 KB Output is correct
24 Correct 343 ms 12880 KB Output is correct
25 Correct 341 ms 12880 KB Output is correct
26 Correct 367 ms 12852 KB Output is correct
27 Correct 249 ms 11120 KB Output is correct
28 Correct 267 ms 11144 KB Output is correct
29 Correct 253 ms 11416 KB Output is correct
30 Correct 271 ms 11192 KB Output is correct
31 Correct 202 ms 11144 KB Output is correct
32 Correct 250 ms 11012 KB Output is correct
33 Correct 225 ms 11428 KB Output is correct
34 Correct 234 ms 11076 KB Output is correct
35 Correct 212 ms 11160 KB Output is correct
36 Correct 224 ms 10984 KB Output is correct
37 Correct 253 ms 11340 KB Output is correct
38 Correct 221 ms 11192 KB Output is correct
39 Correct 351 ms 12968 KB Output is correct
40 Correct 366 ms 12952 KB Output is correct
41 Correct 308 ms 12940 KB Output is correct
42 Correct 363 ms 12844 KB Output is correct