Submission #133604

# Submission time Handle Problem Language Result Execution time Memory
133604 2019-07-21T06:12:41 Z tinjyu Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
736 ms 72184 KB
#include "crocodile.h"
#include <iostream>
using namespace std;
long long int headnow[1000005],e=0,tag[1000005],head[1000005],ans[1000005][4],n,m,map[2000005][3],road[1000005];
int travel_plan(int N, int M, int r[][2], int l[], int k, int p[])
{
    n=N;
    m=M;
    for(int i=0;i<n;i++)road[i]=-1;
    for(int i=0;i<m;i++)
    {
        int x=r[i][0],y=r[i][1];
        map[i*2][0]=y;
        map[i*2][1]=road[x];
        map[i*2][2]=l[i];
        road[x]=i*2;
        map[i*2+1][0]=x;
        map[i*2+1][1]=road[y];
        map[i*2+1][2]=l[i];
        road[y]=i*2+1;
    }
    for(int i=0;i<n;i++)
    {
        ans[i][0]=999999999999999;
        ans[i][1]=999999999999999;
    }
    e=k;
    for(int i=0;i<k;i++)
    {
        ans[p[i]][0]=0;
        ans[p[i]][1]=0;
        tag[p[i]]=1;
        head[i+1]=p[i];
        headnow[p[i]]=i;
    }
    while(e>0)
    {
    	
        int x=head[1];
		swap(head[1],head[e]);
        e--;
        headnow[head[e]]=1;
        int pe=1;
        while(pe*2<=e)
        {
            if(ans[head[pe]][1]>ans[head[pe*2]][1] || ans[head[pe]][1]>ans[head[pe*2+1]][1])
            {
                if(ans[head[pe*2+1]][1]<ans[head[pe*2]][1] && pe*2+1<=e)
                {
                	
                	headnow[head[pe]]=pe*2+1;
                	headnow[head[pe*2+1]]=pe;
                    swap(head[pe],head[pe*2+1]);
                    pe=pe*2+1;
                }
                else
                {
                	headnow[head[pe]]=pe*2;
                	headnow[head[pe*2]]=pe;
                    swap(head[pe],head[pe*2]);
                    pe=pe*2;
                }
            }
            else break;
        }
        int g=road[x];
        while(g!=-1)
        {
            	int now=map[g][0];
                long long int tmp=ans[x][1]+map[g][2];
                long long int t=ans[now][1];
                if(tmp<ans[now][0])
                {
                	if(x==ans[now][2])ans[now][0]=tmp;
                	else
                	{
                		ans[now][1]=ans[now][0];
                		ans[now][0]=tmp;
                		ans[now][3]=ans[now][2];
                		ans[now][2]=x;
					}
				}
				else if(tmp<ans[now][1])
				{
					ans[now][1]=tmp;
					ans[now][3]=x;
				}
                if(ans[now][1]<t && tag[now]==0)
                {
                    tag[now]=1;
                    e++;
                    head[e]=now;
                    int pe=e;
                    while(pe>1)
                    {
                        if(ans[head[pe]][1]<ans[head[pe/2]][1])
                        {
                        	headnow[head[pe]]=pe/2;
                        	headnow[head[pe/2]]=pe;
                            swap(head[pe],head[pe/2]);
                            pe/=2;
                        }
                        else break;
                    }
                }
                else if(ans[now][1]<t)
                {
                	int pe=headnow[now];
                    while(pe>1)
                    {
                        if(ans[head[pe]][1]<ans[head[pe/2]][1])
                        {
                        	headnow[head[pe]]=pe/2;
                        	headnow[head[pe/2]]=pe;
                            swap(head[pe],head[pe/2]);
                            pe/=2;
                        }
                        else break;
                    }
				}
            g=map[g][1];
        }
        tag[x]=0;
    }
    return ans[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 6 ms 1148 KB Output is correct
13 Correct 5 ms 1144 KB Output is correct
14 Correct 2 ms 548 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 6 ms 1148 KB Output is correct
13 Correct 5 ms 1144 KB Output is correct
14 Correct 2 ms 548 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 732 ms 63844 KB Output is correct
17 Correct 91 ms 20600 KB Output is correct
18 Correct 112 ms 21184 KB Output is correct
19 Correct 736 ms 67920 KB Output is correct
20 Correct 369 ms 72184 KB Output is correct
21 Correct 41 ms 8700 KB Output is correct
22 Correct 404 ms 68936 KB Output is correct