답안 #785722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785722 2023-07-17T13:37:31 Z hariaakas646 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
1 ms 596 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);
    invg = vvi(2 * n);
    frange(i, m)
    {
        int a = edges[i][0];
        int b = edges[i][0];
        if (!graph[2 * a])
        {
            if (!graph[2 * b])
            {
                graph[2 * a] = 2 * b + 1;
                graph[2 * b] = 2 * a + 1;
            }
            else
            {
                graph[2 * a] = 2 * b;
                if (!graph[2 * b + 1])
                    graph[2 * b + 1] = 2 * a;
            }
        }
        else
        {
            if (!graph[2 * b])
            {
                graph[2 * b] = 2 * a;
                if (!graph[2 * a + 1])
                    graph[2 * a + 1] = 2 * b;
            }
            else
            {
                if (!graph[2 * a + 1])
                    graph[2 * a + 1] = 2 * b;
                if (!graph[2 * b + 1])
                    graph[2 * b + 1] = 2 * a;
            }
        }
    }
    frange(i, 2 * n)
    {
        invg[graph[i]].pb(i);
    }
    cnt1 = cnt2 = vi(2 * n);
    dfs(2 * p, 0, cnt1);
    dfs(2 * p + 1, 0, cnt2);
    int v1 = cyc(2 * p, 2 * p, 0);
    int v2 = cyc(2 * p + 1, 2 * p + 1, 0);
    frange(i, q)
    {
        int x = stud[i];
        int c = 0;
        frange(j, n)
        {
            int k1 = x - cnt1[j];
            if (v1 != 0)
            {
                k1 %= v1;
            }
            int k2 = x - cnt2[j];
            if (v2 != 0)
                k2 %= v2;
            if (k1 || k2)
                c++;
        }
        answer(c);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -