답안 #790892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790892 2023-07-23T09:16:54 Z That_Salamander 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
49 / 100
105 ms 34304 KB
#include <bits/stdc++.h>
#define int long long

#define FOR(var,bound) for(int var = 0; var < bound; var++)
#define FORB(var,lb,ub) for (int var = lb; var < ub; var++)
#define FORR(var,bound) for(int var = bound-1; var >= 0; var--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void answer(int32_t x);

int n, m, p;
vector<pii> conn[150000];
int jump[300000];
vi back[300000];

int visitedA[300000], visitedB[300000];

void count_routes(int32_t N, int32_t M, int32_t P, int32_t R[][2], int32_t Q, int32_t G[]) {
    n = N;
    m = M;
    p = P;

    FOR(i, m) {
        conn[R[i][0]].push_back({i, R[i][1]});
        conn[R[i][1]].push_back({i, R[i][0]});
    }

    FOR(i, n) {
        sort(conn[i].begin(), conn[i].end());
    }

    FOR(i, n) {
        sort(conn[i].begin(), conn[i].end());

        jump[i*2] = conn[i][0].second * 2;
        if (conn[jump[i*2]/2][0].first == conn[i][0].first) {
            jump[i*2]++;
        }

        if (conn[i].size() == 1) {
            jump[i*2+1] = jump[i*2];
        } else {
            jump[i*2+1] = conn[i][1].second * 2;

            if (conn[jump[i*2+1]/2][0].first == conn[i][1].first) {
                jump[i*2+1]++;
            }
        }
    }

    FOR(i, n * 2) {
        back[jump[i]].push_back(i);
    }


    memset(visitedA, -1, sizeof(visitedA));
    memset(visitedB, -1, sizeof(visitedB));
    int period = 0;

    queue<pii> q;

    q.push({p*2, 0});
    while (!q.empty()) {
        auto [x, dist] = q.front(); q.pop();

        if (visitedA[x] == -1) {
            visitedA[x] = dist;
        } else {
            if (period == 0) {
                period = dist - visitedA[x];
            }

            continue;
        }

        for (int c: back[x]) {
            q.push({c, dist + 1});
        }
    }

    q.push({p*2+1, 0});
    while (!q.empty()) {
        auto [x, dist] = q.front(); q.pop();

        if (visitedB[x] == -1) {
            visitedB[x] = dist;
        } else {
            if (period == 0) {
                period = dist - visitedB[x];
            }

            continue;
        }

        for (int c: back[x]) {
            q.push({c, dist + 1});
        }
    }

    vi m(period);

    vi times;

    FOR(i, n) {
        if (visitedA[i*2] != -1) times.push_back(visitedA[i*2]);
        if (visitedB[i*2] != -1) times.push_back(visitedB[i*2]);
    }

    sort(times.begin(), times.end());
    int ti = 0;

    vi gc(Q);
    FOR(i, Q) {
        gc[i] = G[i];
    }

    sort(gc.begin(), gc.end());
    map<int, int> res;

    for (int x: gc) {
        while (ti < times.size() && times[ti] <= x) {
            m[times[ti++] % period]++;
        }

        res[x] = m[x%period];
    }

    FOR(i, Q) {
        //cout << res[g[i]] << " ";
        answer(res[G[i]]);
    }
}


#ifdef LOCAL_TEST
void answer(int x) {
    cout << "ANSWER: " << x << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, p;
    cin >> n >> m >> p;

    vector<int32_t[2]> R(m);

    FOR(i, m) {
        cin >> R[i][0] >> R[i][1];
    }

    int q;
    cin >> q;

    vector<int32_t> G(q);

    FOR(i, q) {
        cin >> G[i];
    }

    count_routes(n, m, p, R.data(), q, G.data());
}
#endif

Compilation message

garden.cpp: In function 'void count_routes(int32_t, int32_t, int32_t, int32_t (*)[2], int32_t, int32_t*)':
garden.cpp:127:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         while (ti < times.size() && times[ti] <= x) {
      |                ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15700 KB Output is correct
2 Correct 9 ms 15640 KB Output is correct
3 Correct 8 ms 15700 KB Output is correct
4 Correct 10 ms 15572 KB Output is correct
5 Correct 10 ms 15576 KB Output is correct
6 Correct 7 ms 15812 KB Output is correct
7 Correct 7 ms 15504 KB Output is correct
8 Correct 8 ms 15700 KB Output is correct
9 Correct 9 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15700 KB Output is correct
2 Correct 9 ms 15640 KB Output is correct
3 Correct 8 ms 15700 KB Output is correct
4 Correct 10 ms 15572 KB Output is correct
5 Correct 10 ms 15576 KB Output is correct
6 Correct 7 ms 15812 KB Output is correct
7 Correct 7 ms 15504 KB Output is correct
8 Correct 8 ms 15700 KB Output is correct
9 Correct 9 ms 16084 KB Output is correct
10 Correct 9 ms 15572 KB Output is correct
11 Correct 14 ms 18644 KB Output is correct
12 Correct 36 ms 20932 KB Output is correct
13 Correct 43 ms 30700 KB Output is correct
14 Correct 82 ms 31900 KB Output is correct
15 Correct 103 ms 34304 KB Output is correct
16 Correct 105 ms 30016 KB Output is correct
17 Incorrect 80 ms 29184 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15700 KB Output is correct
2 Correct 9 ms 15640 KB Output is correct
3 Correct 8 ms 15700 KB Output is correct
4 Correct 10 ms 15572 KB Output is correct
5 Correct 10 ms 15576 KB Output is correct
6 Correct 7 ms 15812 KB Output is correct
7 Correct 7 ms 15504 KB Output is correct
8 Correct 8 ms 15700 KB Output is correct
9 Correct 9 ms 16084 KB Output is correct
10 Correct 9 ms 15572 KB Output is correct
11 Correct 14 ms 18644 KB Output is correct
12 Correct 36 ms 20932 KB Output is correct
13 Correct 43 ms 30700 KB Output is correct
14 Correct 82 ms 31900 KB Output is correct
15 Correct 103 ms 34304 KB Output is correct
16 Correct 105 ms 30016 KB Output is correct
17 Incorrect 80 ms 29184 KB Output isn't correct
18 Halted 0 ms 0 KB -