Submission #392456

# Submission time Handle Problem Language Result Execution time Memory
392456 2021-04-21T07:45:39 Z Hazem Tropical Garden (IOI11_garden) C++14
49 / 100
1285 ms 86280 KB
#include <bits/stdc++.h>
#include "gardenlib.h"
//#include "grader.h"
using namespace std;
 
#define S second
#define F first
#define LL long long 
 
const int N1 = 2e5+10;
const LL MOD = 1e9+7;
const LL LINF = 1e18;
const LL INF = 1e9;

map<pair<pair<int,int>,int>,pair<int,int>>nxt;
vector<pair<int,int>>adj[N1];

int get_after(int i,int k){

    int pre = INF;
    for(int j=18;j>=0;j--)
        if((1<<j)>k)continue;
        else {

            if(nxt.find({{i,pre},j})==nxt.end())
              while(1){
                i = nxt[{{i,INF-i},5}].F;
              }

            pair<int,int>p = nxt[{{i,pre},j}];
            i = p.F,pre = p.S;
            k -= 1<<j;
        }
    return i;
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{   

    int n = N;
    for(int i=0;i<M;i++){
        adj[R[i][0]].push_back({i,R[i][1]});
        adj[R[i][1]].push_back({i,R[i][0]});
    }    

    for(int i=0;i<n;i++){

        set<pair<int,int>>st;
        for(auto x:adj[i])
            st.insert(x);
        
        nxt[{{i,INF},0}] = {(*st.begin()).S,(*st.begin()).F};
        //printf("%d %d %d\n",i,nxt[{{i,INF},0}].F,nxt[{{i,INF},0}].S);

        for(auto x:adj[i]){
            st.erase(x);
            if(!st.empty()){
                pair<int,int>p = *st.begin();
                nxt[{{i,x.F},0}] = {p.S,p.F};
            }
            else 
                nxt[{{i,x.F},0}] = {x.S,x.F};
            //printf("%d %d 0 %d %d\n",i,x.F,nxt[{{i,x.F},0}].F,nxt[{{i,x.F},0}].S);
            st.insert(x);
        }
    }  

    for(int j=1;j<=18;j++)
        for(int i=0;i<n;i++){
            
            pair<int,int>p1 = nxt[{{i,INF},j-1}];
            nxt[{{i,INF},j}] = nxt[{p1,j-1}];

            for(auto x:adj[i]){
                pair<int,int>after = nxt[{{i,x.F},j-1}];
                nxt[{{i,x.F},j}] = nxt[{after,j-1}];
                //printf("%d %d %d %d %d\n",i,x.S,j,nxt[{{i,x.S},j}].F,nxt[{{i,x.S},j}].S);
                continue;
            }
        }

    for(int i=0;i<Q;i++){
        int ans1 = 0;
        for(int j=0;j<n;j++){
            if(get_after(j,G[i])==P)ans1++;        
            //printf("%d %d\n",j,get_after(j,G[i]));
        }

        answer(ans1);
    }

}


/*
#define MAX_M  1000000
#define MAX_Q  2000

static int N, M, P, Q;
static int R[MAX_M][2];
static int G[MAX_Q];
static int solutions[MAX_Q];
static int answers[MAX_Q];
static int answer_count;

inline 
void my_assert(int e) {if (!e) abort();}
void read_input()
{
  int i;
  my_assert(3==scanf("%d %d %d",&N,&M,&P));
  for(i=0; i<M; i++)
    my_assert(2==scanf("%d %d",&R[i][0],&R[i][1]));
  my_assert(1==scanf("%d",&Q));
  for(i=0; i<Q; i++)
    my_assert(1==scanf("%d",&G[i]));
  for(i=0; i<Q; i++)
    my_assert(1==scanf("%d",&solutions[i]));
}

void answer(int x)
{
  if(answer_count>=Q) {
    printf("Incorrect.  Too many answers.\n");
    exit(0);
  }
  answers[answer_count] = x;
  answer_count++;
}

int main()
{
  int correct, i;

  read_input();
  answer_count = 0;
  count_routes(N,M,P,R,Q,G);

  if(answer_count!=Q) {
    printf("Incorrect.  Too few answers.\n");
    exit(0);
  }

  correct = 1;
  for(i=0; i<Q; i++)
    if(answers[i]!=solutions[i])
      correct = 0;
  if(correct)
    printf("Correct.\n");
  else {
    printf("Incorrect.\n");
    printf("Expected: ");
    for(i=0; i<Q; i++)
      printf("%d ",solutions[i]);
    printf("\nReturned: ");
    for(i=0; i<Q; i++)
      printf("%d ",answers[i]);
  }
  return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7756 KB Output is correct
2 Correct 27 ms 8428 KB Output is correct
3 Correct 38 ms 8752 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 63 ms 10960 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 27 ms 8604 KB Output is correct
9 Correct 153 ms 25436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7756 KB Output is correct
2 Correct 27 ms 8428 KB Output is correct
3 Correct 38 ms 8752 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 63 ms 10960 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 27 ms 8604 KB Output is correct
9 Correct 153 ms 25436 KB Output is correct
10 Correct 5 ms 5324 KB Output is correct
11 Incorrect 1285 ms 86280 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7756 KB Output is correct
2 Correct 27 ms 8428 KB Output is correct
3 Correct 38 ms 8752 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 63 ms 10960 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 27 ms 8604 KB Output is correct
9 Correct 153 ms 25436 KB Output is correct
10 Correct 5 ms 5324 KB Output is correct
11 Incorrect 1285 ms 86280 KB Output isn't correct
12 Halted 0 ms 0 KB -