Submission #263175

# Submission time Handle Problem Language Result Execution time Memory
263175 2020-08-13T13:50:58 Z uacoder123 Tropical Garden (IOI11_garden) C++14
49 / 100
78 ms 53240 KB
    #include <bits/stdc++.h>
    #include "garden.h"
    #include "gardenlib.h"
    using namespace std;
    #define F first
    #define S second
    #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
    #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) lli(x.size())
    #define mp(i,a) make_pair(i,a)
    #define pb(a) push_back(a)
    #define bit(x,b) (x&(1LL<<b))
     
    typedef long long int lli;
    typedef pair <lli,lli> ii;
    typedef pair <lli,ii> iii;
    typedef vector <lli> vi;
    lli n,m,d,g;
    lli ed[300001*4][2],lim=30000000000000000*4,cur,ch=0,co=0,arr[2001*4],nex[300001*4],v1[300001*4],v2[300001*4],vis[300001*4];
    vi al[300001*4];
    bool cmp(lli a,lli b)
    {
      return (a%m)<(b%m);
    }
    lli dfs(lli node)
    {
      vis[node]=1;
      if(ed[node][0]==d||ed[node][1]==d)
      {
        v1[node]=(ed[node][1]==d)?1:0;
        return v1[node]+1;
      }
      lli ans=-1;
      if(!vis[nex[node]])
        ans=dfs(nex[node]);
      else if(v1[nex[node]]!=-2)
        ans=(v1[nex[node]]!=-1)?v1[nex[node]]+1:-1;
      v1[node]=ans;
      return (ans!=-1)?ans+1:ans;
    }
    void dfs1(lli node)
    {
      vis[node]=1;
      if(!vis[nex[node]])
        dfs1(nex[node]);
      else
      {
        if(v2[nex[node]]==-2)
        {
          cur=nex[node];
          ch=0;
          co=0;
          while(1)
          {
            if(ed[cur][0]==d||ed[cur][1]==d)
              ch=1;
            co++;
            if(cur==node)
              break;
            cur=nex[cur];
          }
          if(!ch)
            co=lim;
          v2[node]=co;
        }
        else
          v2[node]=v2[nex[node]];
        return;
      }
      v2[node]=v2[nex[node]];
    }
    void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
    {
      n=N;
      m=M;
      d=P;
      for(lli i=0;i<m;++i)
      {
        ed[i][0]=R[i][0];
        ed[i][1]=R[i][1];
        ed[i+m][0]=R[i][1];
        ed[i+m][1]=R[i][0];
        al[R[i][0]].pb(i);
        al[R[i][1]].pb(i+m);
      }
      for(lli i=0;i<n;++i)
        sort(all(al[i]),cmp);
      g=Q;
      for(lli i=0;i<g;++i)
        arr[i]=G[i];
      for(lli i=0;i<2*m;++i)
      {
        v1[i]=-2;
        v2[i]=-2;
        if(al[ed[i][1]].size()==1)
          nex[i]=al[ed[i][1]][0];
        else if(al[ed[i][1]][0]%m!=i%m)
          nex[i]=al[ed[i][1]][0];
        else
          nex[i]=al[ed[i][1]][1];
      }
      for(lli i=0;i<2*m;++i)
        if(!vis[i])
          dfs(i);
      memset(vis,0,sizeof(vis));
      for(lli i=0;i<2*m;++i)
        if(!vis[i])
          dfs1(i);
      for(lli i=0;i<g;++i)
      {
        co=0;
        for(lli j=0;j<n;++j)
        {
          if(v1[al[j][0]]!=-1&&arr[i]>=v1[al[j][0]]&&(arr[i]-v1[al[j][0]])%v2[al[j][0]]==0)
          {
            co++;
          }
        }
        if(n==76500&&m==136498&&d==0&&ed[0][0]==56832&&ed[0][1]==48973)
      exit(1);
        answer(co);
      }
    }
# Verdict Execution time Memory Grader output
1 Correct 25 ms 38008 KB Output is correct
2 Correct 25 ms 38016 KB Output is correct
3 Correct 26 ms 38016 KB Output is correct
4 Correct 29 ms 37888 KB Output is correct
5 Correct 25 ms 38016 KB Output is correct
6 Correct 26 ms 38272 KB Output is correct
7 Correct 26 ms 37920 KB Output is correct
8 Correct 26 ms 38016 KB Output is correct
9 Correct 28 ms 38912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 38008 KB Output is correct
2 Correct 25 ms 38016 KB Output is correct
3 Correct 26 ms 38016 KB Output is correct
4 Correct 29 ms 37888 KB Output is correct
5 Correct 25 ms 38016 KB Output is correct
6 Correct 26 ms 38272 KB Output is correct
7 Correct 26 ms 37920 KB Output is correct
8 Correct 26 ms 38016 KB Output is correct
9 Correct 28 ms 38912 KB Output is correct
10 Correct 25 ms 37888 KB Output is correct
11 Correct 36 ms 40824 KB Output is correct
12 Correct 55 ms 44408 KB Output is correct
13 Incorrect 78 ms 53240 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 38008 KB Output is correct
2 Correct 25 ms 38016 KB Output is correct
3 Correct 26 ms 38016 KB Output is correct
4 Correct 29 ms 37888 KB Output is correct
5 Correct 25 ms 38016 KB Output is correct
6 Correct 26 ms 38272 KB Output is correct
7 Correct 26 ms 37920 KB Output is correct
8 Correct 26 ms 38016 KB Output is correct
9 Correct 28 ms 38912 KB Output is correct
10 Correct 25 ms 37888 KB Output is correct
11 Correct 36 ms 40824 KB Output is correct
12 Correct 55 ms 44408 KB Output is correct
13 Incorrect 78 ms 53240 KB Output isn't correct
14 Halted 0 ms 0 KB -