답안 #785748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785748 2023-07-17T14:26:41 Z hariaakas646 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2297 ms 30440 KB
#include <bits/stdc++.h>
#include <gardenlib.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

vi graph;
vvi invg;
vi cnt1, cnt2;
vb vis;

void dfs(int x, int c, vi &cnt)
{
    if (vis[x])
        return;
    vis[x] = true;
    cnt[x] = c;
    for (auto e : invg[x])
    {
        dfs(e, c + 1, cnt);
    }
}

int cyc(int x, int v, int c)
{
    if (x == v && vis[x])
    {
        return c;
    }
    if (vis[x])
        return 0;
    vis[x] = true;
    for (auto e : invg[x])
    {
        int out = cyc(e, v, c + 1);
        if (out)
            return out;
    }
    return 0;
}

void count_routes(int n, int m, int p, int edges[][2], int q, int stud[])
{
    graph = vi(2 * n, -1);
    invg = vvi(2 * n);
    frange(i, m)
    {
        int a = edges[i][0];
        int b = edges[i][1];
        if (graph[2 * a] == -1)
        {
            if (graph[2 * b] == -1)
            {
                graph[2 * a] = 2 * b + 1;
                graph[2 * b] = 2 * a + 1;
            }
            else
            {
                graph[2 * a] = 2 * b;
                if (graph[2 * b + 1] == -1)
                    graph[2 * b + 1] = 2 * a + 1;
            }
        }
        else
        {
            if (graph[2 * b] == -1)
            {
                graph[2 * b] = 2 * a;
                if (graph[2 * a + 1] == -1)
                    graph[2 * a + 1] = 2 * b + 1;
            }
            else
            {
                if (graph[2 * a + 1] == -1)
                    graph[2 * a + 1] = 2 * b;
                if (graph[2 * b + 1] == -1)
                    graph[2 * b + 1] = 2 * a;
            }
        }
    }
    frange(i, n)
    {
        if (graph[2 * i + 1] == -1)
            graph[2 * i + 1] = graph[2 * i];
    }
    // frange(i, 2 * n)
    // {
    //     if (graph[i] == -1)
    //         cout << i << "\n";
    // }
    frange(i, 2 * n)
    {
        invg[graph[i]].pb(i);
    }
    cnt1 = cnt2 = vi(2 * n, 1e9);
    vis = vb(2 * n);
    dfs(2 * p, 0, cnt1);
    vis = vb(2 * n);
    dfs(2 * p + 1, 0, cnt2);
    vis = vb(2 * n);
    int v1 = cyc(2 * p, 2 * p, 0);
    vis = vb(2 * n);
    int v2 = cyc(2 * p + 1, 2 * p + 1, 0);
    frange(i, q)
    {
        int x = stud[i];
        int c = 0;
        for (int j = 0; j < 2 * n; j += 2)
        {
            int k1 = x - cnt1[j];
            if (k1 >= 0 && v1 != 0)
            {
                k1 %= v1;
            }
            int k2 = x - cnt2[j];
            if (k2 >= 0 && v2 != 0)
                k2 %= v2;
            if (k1 == 0 || k2 == 0)
                c++;
        }
        answer(c);
        // cout << c << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 10 ms 3284 KB Output is correct
12 Correct 13 ms 5236 KB Output is correct
13 Correct 38 ms 21220 KB Output is correct
14 Correct 48 ms 17120 KB Output is correct
15 Correct 75 ms 17516 KB Output is correct
16 Correct 53 ms 12936 KB Output is correct
17 Correct 40 ms 11196 KB Output is correct
18 Correct 13 ms 5312 KB Output is correct
19 Correct 59 ms 17108 KB Output is correct
20 Correct 77 ms 17520 KB Output is correct
21 Correct 42 ms 12852 KB Output is correct
22 Correct 64 ms 11260 KB Output is correct
23 Correct 48 ms 18812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 10 ms 3284 KB Output is correct
12 Correct 13 ms 5236 KB Output is correct
13 Correct 38 ms 21220 KB Output is correct
14 Correct 48 ms 17120 KB Output is correct
15 Correct 75 ms 17516 KB Output is correct
16 Correct 53 ms 12936 KB Output is correct
17 Correct 40 ms 11196 KB Output is correct
18 Correct 13 ms 5312 KB Output is correct
19 Correct 59 ms 17108 KB Output is correct
20 Correct 77 ms 17520 KB Output is correct
21 Correct 42 ms 12852 KB Output is correct
22 Correct 64 ms 11260 KB Output is correct
23 Correct 48 ms 18812 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 90 ms 3356 KB Output is correct
26 Correct 145 ms 5344 KB Output is correct
27 Correct 2043 ms 21284 KB Output is correct
28 Correct 883 ms 17256 KB Output is correct
29 Correct 2297 ms 17600 KB Output is correct
30 Correct 1275 ms 12960 KB Output is correct
31 Correct 1302 ms 11268 KB Output is correct
32 Correct 141 ms 5512 KB Output is correct
33 Correct 868 ms 17256 KB Output is correct
34 Correct 2288 ms 17576 KB Output is correct
35 Correct 1371 ms 12984 KB Output is correct
36 Correct 1334 ms 11340 KB Output is correct
37 Correct 678 ms 18964 KB Output is correct
38 Correct 1767 ms 30440 KB Output is correct