Submission #650055

# Submission time Handle Problem Language Result Execution time Memory
650055 2022-10-12T07:21:50 Z ToroTN Toll (BOI17_toll) C++14
100 / 100
196 ms 125896 KB
#include<bits/stdc++.h>
using namespace std;
int num,n,m,t,u_i,v_i,w_i,x,y,dp[5][5][50005][25],mx,pow_2[25],st,ed,val[5],nxt[5],ans;
void listdp()
{
    for(int i=0;i<=20;i++)
    {
        printf("%d\n",i);
        for(int j=0;j<=mx;j++)
        {
            for(int k=0;k<num;k++)
            {
                for(int l=0;l<num;l++)
                {
                    printf("%d %d %d %d\n",j,k,l,dp[k][l][j][i]);
                }
            }
        }
        printf("\n");
    }
}
int main()
{
    pow_2[0]=1;
    for(int i=1;i<=20;i++)pow_2[i]=pow_2[i-1]*2;
    for(int i=0;i<=4;i++)
    {
        for(int j=0;j<=4;j++)
        {
            for(int k=0;k<=50000;k++)
            {
                for(int l=0;l<=20;l++)
                {
                    dp[i][j][k][l]=1e9;
                }
            }
        }
    }
    scanf("%d%d%d%d",&num,&n,&m,&t);
    mx=(n-1)/num;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u_i,&v_i,&w_i);
        dp[u_i%num][v_i%num][u_i/num][0]=w_i;
    }
    for(int i=1;i<=20;i++)
    {
        for(int j=0;j<=mx;j++)
        {
            for(int k=0;k<num;k++)
            {
                for(int l=0;l<num;l++)
                {
                    for(int c=0;c<num;c++)
                    {
                        if(j+pow_2[i-1]<=mx)
                        {
                            dp[k][l][j][i]=min(dp[k][l][j][i],dp[k][c][j][i-1]+dp[c][l][j+pow_2[i-1]][i-1]);
                        }
                    }
                }
            }
        }
    }
    //listdp();
    while(t--)
    {
        scanf("%d%d",&x,&y);
        st=x/num;
        ed=y/num;
        x%=num;
        y%=num;
        if(st==ed)
        {
            if(x==y)
            {
                printf("0\n");
            }else
            {
                printf("-1\n");
            }
            continue;
        }
        for(int i=0;i<num;i++)val[i]=1e9;
        val[x]=0;
        for(int i=20;i>=0;i--)
        {
            if(st+pow_2[i]<ed)
            {
                for(int j=0;j<num;j++)
                {
                    nxt[j]=1e9;
                }
                for(int j=0;j<num;j++)
                {
                    for(int k=0;k<num;k++)
                    {
                        nxt[j]=min(nxt[j],val[k]+dp[k][j][st][i]);
                    }
                }
                st+=pow_2[i];
                for(int j=0;j<num;j++)
                {
                    val[j]=nxt[j];
                }
            }
        }
        ans=1e9;
        for(int i=0;i<num;i++)
        {
            ans=min(ans,val[i]+dp[i][y][ed-1][0]);
        }
        if(ans==1e9)
        {
            printf("-1\n");
        }else
        {
            printf("%d\n",ans);
        }
    }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d%d%d",&num,&n,&m,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d%d%d",&u_i,&v_i,&w_i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 122576 KB Output is correct
2 Correct 63 ms 122600 KB Output is correct
3 Correct 63 ms 122516 KB Output is correct
4 Correct 63 ms 122568 KB Output is correct
5 Correct 66 ms 122584 KB Output is correct
6 Correct 63 ms 122512 KB Output is correct
7 Correct 64 ms 122500 KB Output is correct
8 Correct 88 ms 122592 KB Output is correct
9 Correct 88 ms 122620 KB Output is correct
10 Correct 72 ms 122560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 122600 KB Output is correct
2 Correct 65 ms 122584 KB Output is correct
3 Correct 62 ms 122532 KB Output is correct
4 Correct 67 ms 122604 KB Output is correct
5 Correct 64 ms 122492 KB Output is correct
6 Correct 63 ms 122704 KB Output is correct
7 Correct 72 ms 122628 KB Output is correct
8 Correct 66 ms 122700 KB Output is correct
9 Correct 86 ms 123476 KB Output is correct
10 Correct 141 ms 124904 KB Output is correct
11 Correct 117 ms 124376 KB Output is correct
12 Correct 123 ms 123900 KB Output is correct
13 Correct 171 ms 125004 KB Output is correct
14 Correct 112 ms 123968 KB Output is correct
15 Correct 145 ms 123900 KB Output is correct
16 Correct 142 ms 123816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 122572 KB Output is correct
2 Correct 67 ms 122600 KB Output is correct
3 Correct 62 ms 122500 KB Output is correct
4 Correct 63 ms 122568 KB Output is correct
5 Correct 62 ms 122572 KB Output is correct
6 Correct 67 ms 122620 KB Output is correct
7 Correct 63 ms 122612 KB Output is correct
8 Correct 65 ms 122632 KB Output is correct
9 Correct 66 ms 122620 KB Output is correct
10 Correct 87 ms 123344 KB Output is correct
11 Correct 109 ms 124032 KB Output is correct
12 Correct 143 ms 124764 KB Output is correct
13 Correct 147 ms 125008 KB Output is correct
14 Correct 132 ms 124404 KB Output is correct
15 Correct 138 ms 123740 KB Output is correct
16 Correct 142 ms 123688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 122572 KB Output is correct
2 Correct 67 ms 122600 KB Output is correct
3 Correct 62 ms 122500 KB Output is correct
4 Correct 63 ms 122568 KB Output is correct
5 Correct 62 ms 122572 KB Output is correct
6 Correct 67 ms 122620 KB Output is correct
7 Correct 63 ms 122612 KB Output is correct
8 Correct 65 ms 122632 KB Output is correct
9 Correct 66 ms 122620 KB Output is correct
10 Correct 87 ms 123344 KB Output is correct
11 Correct 109 ms 124032 KB Output is correct
12 Correct 143 ms 124764 KB Output is correct
13 Correct 147 ms 125008 KB Output is correct
14 Correct 132 ms 124404 KB Output is correct
15 Correct 138 ms 123740 KB Output is correct
16 Correct 142 ms 123688 KB Output is correct
17 Correct 112 ms 124216 KB Output is correct
18 Correct 64 ms 122552 KB Output is correct
19 Correct 63 ms 122480 KB Output is correct
20 Correct 63 ms 122568 KB Output is correct
21 Correct 64 ms 122512 KB Output is correct
22 Correct 67 ms 122580 KB Output is correct
23 Correct 64 ms 122596 KB Output is correct
24 Correct 65 ms 122652 KB Output is correct
25 Correct 67 ms 122696 KB Output is correct
26 Correct 66 ms 122560 KB Output is correct
27 Correct 87 ms 123344 KB Output is correct
28 Correct 142 ms 124824 KB Output is correct
29 Correct 147 ms 125052 KB Output is correct
30 Correct 132 ms 124360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 122576 KB Output is correct
2 Correct 63 ms 122600 KB Output is correct
3 Correct 63 ms 122516 KB Output is correct
4 Correct 63 ms 122568 KB Output is correct
5 Correct 66 ms 122584 KB Output is correct
6 Correct 63 ms 122512 KB Output is correct
7 Correct 64 ms 122500 KB Output is correct
8 Correct 88 ms 122592 KB Output is correct
9 Correct 88 ms 122620 KB Output is correct
10 Correct 72 ms 122560 KB Output is correct
11 Correct 112 ms 122600 KB Output is correct
12 Correct 65 ms 122584 KB Output is correct
13 Correct 62 ms 122532 KB Output is correct
14 Correct 67 ms 122604 KB Output is correct
15 Correct 64 ms 122492 KB Output is correct
16 Correct 63 ms 122704 KB Output is correct
17 Correct 72 ms 122628 KB Output is correct
18 Correct 66 ms 122700 KB Output is correct
19 Correct 86 ms 123476 KB Output is correct
20 Correct 141 ms 124904 KB Output is correct
21 Correct 117 ms 124376 KB Output is correct
22 Correct 123 ms 123900 KB Output is correct
23 Correct 171 ms 125004 KB Output is correct
24 Correct 112 ms 123968 KB Output is correct
25 Correct 145 ms 123900 KB Output is correct
26 Correct 142 ms 123816 KB Output is correct
27 Correct 62 ms 122572 KB Output is correct
28 Correct 67 ms 122600 KB Output is correct
29 Correct 62 ms 122500 KB Output is correct
30 Correct 63 ms 122568 KB Output is correct
31 Correct 62 ms 122572 KB Output is correct
32 Correct 67 ms 122620 KB Output is correct
33 Correct 63 ms 122612 KB Output is correct
34 Correct 65 ms 122632 KB Output is correct
35 Correct 66 ms 122620 KB Output is correct
36 Correct 87 ms 123344 KB Output is correct
37 Correct 109 ms 124032 KB Output is correct
38 Correct 143 ms 124764 KB Output is correct
39 Correct 147 ms 125008 KB Output is correct
40 Correct 132 ms 124404 KB Output is correct
41 Correct 138 ms 123740 KB Output is correct
42 Correct 142 ms 123688 KB Output is correct
43 Correct 112 ms 124216 KB Output is correct
44 Correct 64 ms 122552 KB Output is correct
45 Correct 63 ms 122480 KB Output is correct
46 Correct 63 ms 122568 KB Output is correct
47 Correct 64 ms 122512 KB Output is correct
48 Correct 67 ms 122580 KB Output is correct
49 Correct 64 ms 122596 KB Output is correct
50 Correct 65 ms 122652 KB Output is correct
51 Correct 67 ms 122696 KB Output is correct
52 Correct 66 ms 122560 KB Output is correct
53 Correct 87 ms 123344 KB Output is correct
54 Correct 142 ms 124824 KB Output is correct
55 Correct 147 ms 125052 KB Output is correct
56 Correct 132 ms 124360 KB Output is correct
57 Correct 196 ms 125896 KB Output is correct
58 Correct 93 ms 123552 KB Output is correct
59 Correct 120 ms 124384 KB Output is correct