답안 #543444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543444 2022-03-30T15:25:20 Z AmirElarbi 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
2626 ms 28392 KB
#include <bits/stdc++.h>
#include "gardenlib.h"
#define ii pair<int,int>
#define ve vector
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define fi first
#define MAX_N 500000
#define se second
#define eps 1e-7
#define INF 1e9
#define ll long long
#include "garden.h"
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int nax = 3e5+5;
using namespace std;
int n,m,p,q, aff = 0, cur,res,c1 = INF, c2 = INF;
vi rev[nax];
bool vis[nax];
int adj[nax], f1[nax], f2[nax];
void dfs(int u, int d){
    if(vis[u] && u == p){
        c1 = d;
        return;
    } else if(vis[u])
        return;
    f1[u] = d;
    vis[u] = 1;
    for(auto x : rev[u])
        dfs(x,d+1);
}
void dfs2(int u, int d){
    if(vis[u] && u == p+n){
        c2 = d;
        return;
    } else if(vis[u])
        return;
    f2[u] = d, vis[u] = 1;
    for(auto x : rev[u])
        dfs2(x,d+1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
    n = N,m = M, p = P;
    memset(adj,-1,sizeof adj);
    for(int i = 0; i < m; i++){
        int a,b;
        a = R[i][0], b = R[i][1];
        if(adj[a] == -1) {
            if(adj[b] != -1){
                adj[a] = b;
                if(adj[b+n] == -1) adj[b+n] = a+n;
            } else {
                adj[a] = b+n, adj[b] = a+n;
            }
        } else if(adj[a+n] == -1){
            if(adj[b] != -1){
                adj[a+n] = b;
                if(adj[b+n] == -1) adj[b+n] = a;
            } else {
                adj[a+n] = b+n, adj[b] = a;
            }
        } else {
            if(adj[b] != -1){
                if(adj[b+n] == -1)
                    adj[b+n] = a;
            } else {
                adj[b] = a;
            }
        }
    }
    for (int i = 0; i < 2*n; ++i)
    {
        if(i < n && adj[i+n] == -1) adj[i+n] = adj[i];
        f1[i] = INF, f2[i] = INF;
        rev[adj[i]].pb(i);
    }
    dfs(p,0);
    memset(vis,0,sizeof vis);
    dfs2(p+n,0);
    q = Q;
    for(int i = 0; i < q; i++){
        aff = 0;
        cur = G[i];
        for (int j = 0; j < n; ++j)
        {
            if(c1 != INF && cur >= f1[j] && (cur-f1[j])%c1 == 0) aff++;
            else if(c2 != INF && cur >= f2[j]  && (cur-f2[j])%c2 == 0) aff++;
            else if(cur == f1[j]) aff++;
            else if(cur == f2[j]) aff++;
        }
        answer(aff);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8912 KB Output is correct
4 Correct 5 ms 8788 KB Output is correct
5 Correct 5 ms 8788 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8772 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 7 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8912 KB Output is correct
4 Correct 5 ms 8788 KB Output is correct
5 Correct 5 ms 8788 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8772 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 7 ms 8916 KB Output is correct
10 Correct 5 ms 8772 KB Output is correct
11 Correct 12 ms 10576 KB Output is correct
12 Correct 19 ms 11732 KB Output is correct
13 Correct 36 ms 22396 KB Output is correct
14 Correct 69 ms 18168 KB Output is correct
15 Correct 101 ms 18468 KB Output is correct
16 Correct 60 ms 16332 KB Output is correct
17 Correct 54 ms 15460 KB Output is correct
18 Correct 20 ms 11652 KB Output is correct
19 Correct 58 ms 18200 KB Output is correct
20 Correct 114 ms 18376 KB Output is correct
21 Correct 75 ms 16172 KB Output is correct
22 Correct 54 ms 15440 KB Output is correct
23 Correct 63 ms 18992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 5 ms 8912 KB Output is correct
4 Correct 5 ms 8788 KB Output is correct
5 Correct 5 ms 8788 KB Output is correct
6 Correct 5 ms 8916 KB Output is correct
7 Correct 5 ms 8772 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 7 ms 8916 KB Output is correct
10 Correct 5 ms 8772 KB Output is correct
11 Correct 12 ms 10576 KB Output is correct
12 Correct 19 ms 11732 KB Output is correct
13 Correct 36 ms 22396 KB Output is correct
14 Correct 69 ms 18168 KB Output is correct
15 Correct 101 ms 18468 KB Output is correct
16 Correct 60 ms 16332 KB Output is correct
17 Correct 54 ms 15460 KB Output is correct
18 Correct 20 ms 11652 KB Output is correct
19 Correct 58 ms 18200 KB Output is correct
20 Correct 114 ms 18376 KB Output is correct
21 Correct 75 ms 16172 KB Output is correct
22 Correct 54 ms 15440 KB Output is correct
23 Correct 63 ms 18992 KB Output is correct
24 Correct 6 ms 8780 KB Output is correct
25 Correct 97 ms 10568 KB Output is correct
26 Correct 119 ms 11924 KB Output is correct
27 Correct 2323 ms 22496 KB Output is correct
28 Correct 844 ms 18308 KB Output is correct
29 Correct 2626 ms 18644 KB Output is correct
30 Correct 1469 ms 16348 KB Output is correct
31 Correct 1507 ms 15532 KB Output is correct
32 Correct 103 ms 11724 KB Output is correct
33 Correct 807 ms 18436 KB Output is correct
34 Correct 2620 ms 18648 KB Output is correct
35 Correct 1549 ms 16412 KB Output is correct
36 Correct 1491 ms 15564 KB Output is correct
37 Correct 614 ms 19388 KB Output is correct
38 Correct 2045 ms 28392 KB Output is correct