Submission #1104578

# Submission time Handle Problem Language Result Execution time Memory
1104578 2024-10-24T05:01:12 Z tammaidai Tropical Garden (IOI11_garden) C++17
69 / 100
5000 ms 78516 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
pair<int,int> adj[150010][2];
// vector<pair<int,int>> rev[150010][2];
pair<int,int> jump[150010][31][2];
int dg[150010];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
  memset(adj,-1,sizeof(adj));
  for(int i = 0;i<M;i++){
    int u = R[i][0];
    int v = R[i][1];
    // cout << u << ' ';
    // cout << v << '\n';
    dg[u]++;
    dg[v]++;
    if(dg[u]==1){
      // adj[u][0] = adj[u][1] = {v,dg[v]==1};
      jump[u][0][0] = jump[u][0][1] = {v,dg[v]==1};
    }
    else if(dg[u]==2){
      // adj[u][1] = {v,dg[v]==1};
      jump[u][0][1] = {v,dg[v]==1};
    }
    if(dg[v]==1){
      jump[v][0][0] = jump[v][0][1] = {u,dg[u]==1};
      // adj[v][0] = adj[u][1] = {u,dg[u]==1};
    }
    else if(dg[v]==2){
      jump[v][0][1] = {u,dg[u]==1};
      // adj[v][1] = {u,dg[u]==1};
    }
  }
  // for(int i = 0;i<N;i++){
  //   cout << jump[i][0][0].first<<' '<< jump[i][0][0].second<<' ' << jump[i][0][1].first<<' '<< jump[i][0][1].second<<'\n';
  // }
  // for(int i = 0;i<N;i++){
  //   rev[adj[i][0].first][adj[i][0].second].push_back({i,0});
  //   rev[adj[i][1].first][adj[i][1].second].push_back({i,1});
  // }
  for(int i = 1;i<30;i++){
    for(int j=0;j<N;j++){
      jump[j][i][0]=jump[jump[j][i-1][0].first][i-1][jump[j][i-1][0].second];
      jump[j][i][1]=jump[jump[j][i-1][1].first][i-1][jump[j][i-1][1].second];
    }
  }
  // cout << jump[0][0][0].first << ' ' << jump[0][0][0].second<<'\n';
  for(int i = 0;i<Q;i++){
    int ans = 0;
    for(int j = 0;j<N;j++){
      pair<int,int> a = {j,0};
      for(int k = 0;k<30;k++){
        if((1<<k)&G[i]){
          a = jump[a.first][k][a.second];
        }
      }
      if(a.first == P){
        ans++;
      }
    }
    answer(ans);
  }

}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 20 ms 27272 KB Output is correct
13 Correct 94 ms 49744 KB Output is correct
14 Correct 79 ms 74424 KB Output is correct
15 Correct 77 ms 75336 KB Output is correct
16 Correct 54 ms 51784 KB Output is correct
17 Correct 43 ms 46664 KB Output is correct
18 Correct 18 ms 27216 KB Output is correct
19 Correct 80 ms 74480 KB Output is correct
20 Correct 82 ms 73312 KB Output is correct
21 Correct 47 ms 51792 KB Output is correct
22 Correct 51 ms 45640 KB Output is correct
23 Correct 125 ms 78516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 9 ms 16720 KB Output is correct
12 Correct 20 ms 27272 KB Output is correct
13 Correct 94 ms 49744 KB Output is correct
14 Correct 79 ms 74424 KB Output is correct
15 Correct 77 ms 75336 KB Output is correct
16 Correct 54 ms 51784 KB Output is correct
17 Correct 43 ms 46664 KB Output is correct
18 Correct 18 ms 27216 KB Output is correct
19 Correct 80 ms 74480 KB Output is correct
20 Correct 82 ms 73312 KB Output is correct
21 Correct 47 ms 51792 KB Output is correct
22 Correct 51 ms 45640 KB Output is correct
23 Correct 125 ms 78516 KB Output is correct
24 Correct 6 ms 6480 KB Output is correct
25 Correct 3962 ms 16936 KB Output is correct
26 Execution timed out 5070 ms 27216 KB Time limit exceeded
27 Halted 0 ms 0 KB -