답안 #651755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651755 2022-10-20T01:32:55 Z ghostwriter 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 18692 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#else
#define debug(...)
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) x.bg(), x.ed()
#define sz(x) (int)x.size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int i = l; i <= r; ++i)
#define FOS(i, r, l) for (int i = r; i >= l; --i)
#define FRN(i, n) for (int i = 0; i < n; ++i)
#define FSN(i, n) for (int i = n - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : x)
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Tran The Bao - ghostwriter
    Training for VOI23 gold medal
----------------------------------------------------------------
    GOAT
----------------------------------------------------------------
*/
const int MAXN = 15e4 + 5;
int ind[MAXN][2], c[MAXN][2], c1[MAXN][2], s[MAXN][2], d[MAXN][2];
vi adj[MAXN];
vpi e;
pi nxt(pi x) {
    int u = x.st;
    bool stt = x.nd;
    int id = (!stt? 0 : sz(adj[u]) == 1? 0 : 1);
    int nxtv = e[adj[u][id]].st == u? e[adj[u][id]].nd : e[adj[u][id]].st;
    return {nxtv, adj[u][id] == adj[nxtv][0]? 1 : 0};
}
int cal(int N, int P, int x) {
    memset(c, 0, sizeof c);
    int ans = 0;
    FRN(i, N)
    FRN(j, 2) {
        if (ind[i][j]) continue;
        int x1 = x;
        if (x1 > d[i][j]) {
            x1 -= d[i][j];
            x1 %= s[i][j];
            x1 += d[i][j];
        }
        pi cur = {i, j};
        FOR(z, 1, x1) cur = nxt(cur);
        if (cur.st == P && !j) ++ans;
        c[i][j] = 1;
        pi cur1 = nxt({i, j});
        WHILE(!c[cur1.st][cur1.nd]) {
            cur = nxt(cur);
            if (cur.st == P && !cur1.nd) ++ans;
            c[cur1.st][cur1.nd] = 1;
            cur1 = nxt(cur1);
        }
    }
    FRN(i, N)
    FRN(j, 2) {
        if (c[i][j]) continue;
        int x1 = x % s[i][j];
        pi cur = {i, j};
        FOR(z, 1, x1) cur = nxt(cur);
        if (cur.st == P && !j) ++ans;
        c[i][j] = 1;
        pi cur1 = nxt({i, j});
        WHILE(!c[cur1.st][cur1.nd]) {
            cur = nxt(cur);
            if (cur.st == P && !cur1.nd) ++ans;
            c[cur1.st][cur1.nd] = 1;
            cur1 = nxt(cur1);
        }   
    }
    return ans;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    FRN(i, M) {
        int u = R[i][0], v = R[i][1];
        e.pb({u, v});
        adj[u].pb(i);
        adj[v].pb(i);
    }
    // cerr << '\n';
    FRN(i, N)
    FRN(j, 2) {
        pi tmp1 = nxt({i, j});
        ind[tmp1.st][tmp1.nd] = 1;
        // cerr << i << ' ' << j << ' ' << tmp1.st << ' ' << tmp1.nd << '\n';
        if (c1[i][j]) continue;
        vpi ver;
        pi cur = {i, j};
        WHILE(1) {
            if (!c[cur.st][cur.nd]) ver.pb(cur);
            ++c[cur.st][cur.nd];
            cur = nxt(cur);
            if (c1[cur.st][cur.nd] || c[cur.st][cur.nd] == 2) break;
        }
        reverse(all(ver));
        if (c[ver.ft().st][ver.ft().nd] == 2) {
            int cnt = 0, h = 0;
            EACH(z, ver) if (c[z.st][z.nd] == 2) ++cnt;
            EACH(z, ver) {
                if (c[z.st][z.nd] == 1) ++h;
                s[z.st][z.nd] = cnt;
                d[z.st][z.nd] = h;
            }
        }
        else {
            pi tmp = nxt(ver.ft());
            int cnt = s[tmp.st][tmp.nd], h = d[tmp.st][tmp.nd];
            EACH(z, ver) {
                ++h;
                s[z.st][z.nd] = cnt;
                d[z.st][z.nd] = h;
            }
        }
        EACH(z, ver) c1[z.st][z.nd] = 1;
    }
    // cerr << '\n';
    // FRN(i, N)
    // FRN(j, 2) {
        // debug(i, j, s[i][j], d[i][j]);
    // }
    // debug(cal(N, P, G[0]));
    // return;
    FRN(q, Q) {
        // debug(G[q], cal(N, P, G[q]));
        answer(cal(N, P, G[q]));
    }
}
/*
5 5 2
1 0
1 2
3 2
1 3
4 2
2
3 1
1 2

0 0 1 1
0 1 1 1
1 0 0 1
1 1 2 1
2 0 1 0
2 1 3 1
3 0 2 0
3 1 1 0
4 0 2 0
4 1 2 0
----------------------------------------------------------------
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
----------------------------------------------------------------
*/


# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 5 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 5 ms 5328 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 673 ms 7048 KB Output is correct
12 Correct 1151 ms 9040 KB Output is correct
13 Correct 48 ms 12904 KB Output is correct
14 Correct 268 ms 17572 KB Output is correct
15 Correct 275 ms 18008 KB Output is correct
16 Correct 4658 ms 14992 KB Output is correct
17 Correct 175 ms 14196 KB Output is correct
18 Correct 203 ms 8832 KB Output is correct
19 Correct 269 ms 17452 KB Output is correct
20 Correct 239 ms 17860 KB Output is correct
21 Correct 1543 ms 14908 KB Output is correct
22 Correct 174 ms 14124 KB Output is correct
23 Correct 1791 ms 18692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 5 ms 5328 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 673 ms 7048 KB Output is correct
12 Correct 1151 ms 9040 KB Output is correct
13 Correct 48 ms 12904 KB Output is correct
14 Correct 268 ms 17572 KB Output is correct
15 Correct 275 ms 18008 KB Output is correct
16 Correct 4658 ms 14992 KB Output is correct
17 Correct 175 ms 14196 KB Output is correct
18 Correct 203 ms 8832 KB Output is correct
19 Correct 269 ms 17452 KB Output is correct
20 Correct 239 ms 17860 KB Output is correct
21 Correct 1543 ms 14908 KB Output is correct
22 Correct 174 ms 14124 KB Output is correct
23 Correct 1791 ms 18692 KB Output is correct
24 Correct 82 ms 5056 KB Output is correct
25 Execution timed out 5077 ms 7120 KB Time limit exceeded
26 Halted 0 ms 0 KB -