Submission #299228

# Submission time Handle Problem Language Result Execution time Memory
299228 2020-09-14T15:12:23 Z erd1 Tropical Garden (IOI11_garden) C++14
100 / 100
2826 ms 12920 KB
#include "garden.h"
#include "gardenlib.h"

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back

vector<int> arr;
vector<int> ans1, ans2, gone;

void dfs(int i, int P, vector<int>& ans){
  if(arr[i] == P)
    return ans[i] = 1, void(0);
  if(!gone[arr[i]])
    gone[arr[i]] = true, dfs(arr[i], P, ans);
  if(ans[arr[i]] != INT_MAX)ans[i] = ans[arr[i]]+1;
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  arr.resize(2*N, -1);
  for(int i = 0; i < M; i++){
    bool b1 = arr[R[i][0]*2] == -1, b2 = arr[R[i][1]*2] == -1;
    if(b1)arr[R[i][0]*2] = R[i][1]*2 + b2;
    else if(arr[R[i][0]*2+1] == -1)arr[R[i][0]*2+1] = R[i][1]*2 + b2;
    if(b2)arr[R[i][1]*2] = R[i][0]*2 + b1;
    else if(arr[R[i][1]*2+1] == -1)arr[R[i][1]*2+1] = R[i][0]*2 + b1;
  }
  for(int i = 0; i < 2*N; i++)if(arr[i] == -1)arr[i] = arr[i-1];
  ans1.resize(2*N, INT_MAX); ans2.resize(2*N, INT_MAX); gone.resize(2*N, 0);
  for(int i = 0; i < 2*N; i++) if(!gone[i]) dfs(i, 2*P, ans1);
  fill(all(gone), 0);
  for(int i = 0; i < 2*N; i++) if(!gone[i]) dfs(i, 2*P+1, ans2);
  int d1 = 0, d2 = 0; swap(ans1[2*P], d1); swap(ans2[2*P+1], d2);
  for(int j=0; j<Q; j++){
    int ans = 0;
    for(int i = 0; i < N; i++)
      if(ans1[2*i] <= G[j] && (G[j] - ans1[2*i])%d1 == 0 || ans2[2*i] <= G[j] && (G[j] - ans2[2*i])%d2 == 0)
        ans++;
    answer(ans);
  }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:40:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   40 |       if(ans1[2*i] <= G[j] && (G[j] - ans1[2*i])%d1 == 0 || ans2[2*i] <= G[j] && (G[j] - ans2[2*i])%d2 == 0)
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 8 ms 1408 KB Output is correct
12 Correct 19 ms 2048 KB Output is correct
13 Correct 37 ms 8960 KB Output is correct
14 Correct 60 ms 5660 KB Output is correct
15 Correct 63 ms 5752 KB Output is correct
16 Correct 53 ms 4600 KB Output is correct
17 Correct 50 ms 3864 KB Output is correct
18 Correct 20 ms 1920 KB Output is correct
19 Correct 57 ms 5624 KB Output is correct
20 Correct 62 ms 5752 KB Output is correct
21 Correct 54 ms 4344 KB Output is correct
22 Correct 52 ms 3832 KB Output is correct
23 Correct 59 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 8 ms 1408 KB Output is correct
12 Correct 19 ms 2048 KB Output is correct
13 Correct 37 ms 8960 KB Output is correct
14 Correct 60 ms 5660 KB Output is correct
15 Correct 63 ms 5752 KB Output is correct
16 Correct 53 ms 4600 KB Output is correct
17 Correct 50 ms 3864 KB Output is correct
18 Correct 20 ms 1920 KB Output is correct
19 Correct 57 ms 5624 KB Output is correct
20 Correct 62 ms 5752 KB Output is correct
21 Correct 54 ms 4344 KB Output is correct
22 Correct 52 ms 3832 KB Output is correct
23 Correct 59 ms 6392 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 92 ms 1440 KB Output is correct
26 Correct 125 ms 2048 KB Output is correct
27 Correct 2509 ms 9080 KB Output is correct
28 Correct 966 ms 7544 KB Output is correct
29 Correct 2826 ms 7800 KB Output is correct
30 Correct 1573 ms 6008 KB Output is correct
31 Correct 1652 ms 5564 KB Output is correct
32 Correct 133 ms 2680 KB Output is correct
33 Correct 921 ms 7548 KB Output is correct
34 Correct 2818 ms 7728 KB Output is correct
35 Correct 1698 ms 6008 KB Output is correct
36 Correct 1945 ms 5496 KB Output is correct
37 Correct 662 ms 8312 KB Output is correct
38 Correct 2202 ms 12920 KB Output is correct