답안 #421848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421848 2021-06-09T12:58:45 Z arayi 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2815 ms 64424 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define ad push_back
#define MP make_pair
#define fr first
#define sc second
using namespace std;

const int N = 1e6 + 20;


vector <pair<int, int> > g1[N][2];
int mx[N][2], c[2];
int n, m, p, q;
int d[2][N][2], col[N][2];
void dfs(int v, int x, int lil)
{
    col[v][x] = 1;
    int x1, v1;
    v1 = mx[v][x];
    if(mx[v1][0] == v) x1 = 1;
    else x1 = 0;
    if(!col[v1][x1]) dfs(v1,x1,lil + 1);
    else
    {
        if(v1 == p && x1 == m) c[m] = lil;
        else return;
    }
}
void bfs(int v, int xx)
{
    queue <pair<int, int> > q;
    d[xx][v][xx] = 1;
    q.push(MP(v, xx));
    while(!q.empty())
    {
        int v = q.front().fr, x = q.front().sc;
        q.pop();
        for(auto p : g1[v][x])
            if(!d[xx][p.fr][p.sc]) d[xx][p.fr][p.sc] = d[xx][v][x] + 1, q.push(p);
    }
}
int s(int d, int c, int g)
{
    d--;
    if(g < d || d < 0) return 0;
    if(g == d) return 1;
    if(c == 0) return 0;
    if((g - d) % c == 0) return 1;
    return 0;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    n=N,m=M,p=P,q=Q;
    for (int i = 0; i < n; i++) mx[i][0] = -1;
    for(int i = m - 1; i >= 0; i--)
    {
        int a = R[i][0], b = R[i][1];
        mx[a][1] = mx[a][0], mx[b][1] = mx[b][0];
        mx[a][0] = b, mx[b][0] = a;
        if(mx[a][1] == -1) mx[a][1] = b;
        if(mx[b][1] == -1) mx[b][1] = a;
    }
    for (int i = 0; i < n; i++)
    {
        //cout << mx[i][0] << " " << mx[i][1] << endl;
        int v = mx[i][0];
        if(mx[v][0] == i) g1[v][1].ad(MP(i, 0));
        else g1[mx[i][0]][0].ad(MP(i, 0));
        if(mx[mx[i][1]][0] == i) g1[mx[i][1]][1].ad(MP(i, 1));
        else g1[mx[i][1]][0].ad(MP(i, 1));
    }
    /*
    for (int i = 0; i < n; i++)
    {
        for(auto p : g1[i][0]) cout << p.fr << p.sc << " ";
        cout << "    ";
        for(auto p : g1[i][1]) cout << p.fr << p.sc << " ";
        cout << endl;
    }*/
    m=0; dfs(p, 0, 1);
    for (int i = 0; i < n; i++) col[i][0] = col[i][1] = 0;
    m=1; dfs(p, 1, 1);
    bfs(p, 0); bfs(p, 1);
    //for (int i = 0; i < n; i++) cout << d[0][i][0] << " " << d[1][i][0] << endl;
    for (int i = 0; i < q; i++)
    {
        int ret = 0;
        for(int j = 0; j < n; j++)
            ret += s(d[0][j][0], c[0], G[i]) + s(d[1][j][0], c[1], G[i]);
        answer(ret);
    }
    //for (int i = 0; i < n; i++) cout << d[1][i][0] << " " << d[1][i][1] << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47308 KB Output is correct
2 Correct 26 ms 47420 KB Output is correct
3 Correct 26 ms 47424 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 27 ms 47392 KB Output is correct
7 Correct 27 ms 47232 KB Output is correct
8 Correct 27 ms 47404 KB Output is correct
9 Correct 28 ms 47580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47308 KB Output is correct
2 Correct 26 ms 47420 KB Output is correct
3 Correct 26 ms 47424 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 27 ms 47392 KB Output is correct
7 Correct 27 ms 47232 KB Output is correct
8 Correct 27 ms 47404 KB Output is correct
9 Correct 28 ms 47580 KB Output is correct
10 Correct 25 ms 47276 KB Output is correct
11 Correct 36 ms 49104 KB Output is correct
12 Correct 46 ms 50644 KB Output is correct
13 Correct 65 ms 56872 KB Output is correct
14 Correct 98 ms 58712 KB Output is correct
15 Correct 140 ms 59844 KB Output is correct
16 Correct 113 ms 55872 KB Output is correct
17 Correct 87 ms 55652 KB Output is correct
18 Correct 46 ms 50616 KB Output is correct
19 Correct 98 ms 59288 KB Output is correct
20 Correct 123 ms 59976 KB Output is correct
21 Correct 93 ms 55872 KB Output is correct
22 Correct 87 ms 55620 KB Output is correct
23 Correct 121 ms 59472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47308 KB Output is correct
2 Correct 26 ms 47420 KB Output is correct
3 Correct 26 ms 47424 KB Output is correct
4 Correct 26 ms 47236 KB Output is correct
5 Correct 26 ms 47180 KB Output is correct
6 Correct 27 ms 47392 KB Output is correct
7 Correct 27 ms 47232 KB Output is correct
8 Correct 27 ms 47404 KB Output is correct
9 Correct 28 ms 47580 KB Output is correct
10 Correct 25 ms 47276 KB Output is correct
11 Correct 36 ms 49104 KB Output is correct
12 Correct 46 ms 50644 KB Output is correct
13 Correct 65 ms 56872 KB Output is correct
14 Correct 98 ms 58712 KB Output is correct
15 Correct 140 ms 59844 KB Output is correct
16 Correct 113 ms 55872 KB Output is correct
17 Correct 87 ms 55652 KB Output is correct
18 Correct 46 ms 50616 KB Output is correct
19 Correct 98 ms 59288 KB Output is correct
20 Correct 123 ms 59976 KB Output is correct
21 Correct 93 ms 55872 KB Output is correct
22 Correct 87 ms 55620 KB Output is correct
23 Correct 121 ms 59472 KB Output is correct
24 Correct 26 ms 47308 KB Output is correct
25 Correct 174 ms 49328 KB Output is correct
26 Correct 256 ms 50728 KB Output is correct
27 Correct 2558 ms 56972 KB Output is correct
28 Correct 1345 ms 59620 KB Output is correct
29 Correct 2759 ms 59980 KB Output is correct
30 Correct 1616 ms 56096 KB Output is correct
31 Correct 1652 ms 55620 KB Output is correct
32 Correct 271 ms 50704 KB Output is correct
33 Correct 1429 ms 59192 KB Output is correct
34 Correct 2815 ms 59972 KB Output is correct
35 Correct 1735 ms 56132 KB Output is correct
36 Correct 1587 ms 55664 KB Output is correct
37 Correct 1142 ms 59496 KB Output is correct
38 Correct 2241 ms 64424 KB Output is correct