Submission #753723

# Submission time Handle Problem Language Result Execution time Memory
753723 2023-06-05T18:28:27 Z amin Toll (BOI17_toll) C++14
100 / 100
140 ms 35516 KB

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int p[17][100000][5],mi[17][100000][5];
int k;

int get(int x,int y)
{
    int di=y/k-x/k;
    if(di<=0)
        return -1;
    int o=0;

    int j=1;
    vector<int>b(5),c(5),d(5),bb(5);
    for(int i=0;i<5;i++)
    {
        b[i]=-1;
        c[i]=-1;
        d[i]=1000000000;
    }
    b[x%k]=x;
    d[x%k]=0;
    while(o<17)
    {

        if((di&j)==j)
        {
            c=d;
            d[0]=1e9;
            d[1]=d[0];
            d[2]=d[0];
            d[3]=d[0];
            d[4]=d[0];
            for(int h=0;h<5;h++)
                bb[h]=-1;
            for(int i=0;i<k;i++)
            {
                for(int u=0;u<k;u++)
                {
                 if(b[u]==-1||p[o][b[u]][i]==-1)
                    continue;
                    //cout<<"whatever"<<endl;
                    bb[i]=p[o][b[u]][i];
                 d[i]=min(d[i],c[u]+mi[o][b[u]][i]);
                }
            }
            b=bb;
            c=d;
           /*for(int i=0;i<k;i++)
            {
               cout<<b[i]<<' ';
           }
            cout<<endl;*/
        }

        j*=2;
        o++;
    }
    return c[y%k];


}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  //  freopen("balancing.in","r",stdin);
   // freopen("balancing.out","w",stdout);
int n,m,o;
cin>>k>>n>>m>>o;
vector<int>v[n+1];
for(int i=0;i<17;i++)
{
    for(int y=0;y<n;y++)
    {
        for(int h=0;h<k;h++)
        {
            p[i][y][h]=-1;
        }
    }
}
for(int i=0;i<m;i++)
{
    int x,y,t;
    cin>>x>>y>>t;
    v[x].push_back(y);
    p[0][x][y%k]=y;
    mi[0][x][y%k]=t;
}

for(int i=0;i<17;i++)
{
    for(int y=0;y<n;y++)
    {
        for(int u=0;u<k;u++)
        {
            for(int z=0;z<k;z++)
            {
            if(i)
            {
                if(p[i-1][y][z]==-1||p[i-1][p[i-1][y][z]][u]==-1)
                    continue;
                p[i][y][u]=p[i-1][p[i-1][y][z]][u];
                if(mi[i][y][u]==0)
                    mi[i][y][u]=1e9;

                mi[i][y][u]=min(mi[i][y][u],mi[i-1][y][z]+mi[i-1][p[i-1][y][z]][u]);
            }
            }
           /* if(i<5)
            {
                cout<<p[i][y][u]<<' ';
            }*/
        }
      //  if(i<5)
       // cout<<endl;
    }
    //if(i<5)
   // cout<<endl;
}
while(o--)
{
    int x,y;
    cin>>x>>y;
    int ans=get(x,y);
    if(ans>=1000000000)
        cout<<-1<<endl;
    else
    cout<<ans<<endl;
}



}

Compilation message

toll.cpp: In function 'int get(int, int)':
toll.cpp:43:18: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   43 |                  if(b[u]==-1||p[o][b[u]][i]==-1)
      |                  ^~
toll.cpp:46:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   46 |                     bb[i]=p[o][b[u]][i];
      |                     ^~
# Verdict Execution time Memory Grader output
1 Correct 63 ms 34760 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 3 ms 1008 KB Output is correct
6 Correct 3 ms 988 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 59 ms 30156 KB Output is correct
9 Correct 54 ms 26240 KB Output is correct
10 Correct 30 ms 18368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 32716 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 18 ms 1124 KB Output is correct
8 Correct 17 ms 1156 KB Output is correct
9 Correct 52 ms 30540 KB Output is correct
10 Correct 102 ms 34952 KB Output is correct
11 Correct 88 ms 35012 KB Output is correct
12 Correct 79 ms 27508 KB Output is correct
13 Correct 92 ms 22092 KB Output is correct
14 Correct 54 ms 20760 KB Output is correct
15 Correct 80 ms 20120 KB Output is correct
16 Correct 82 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 35 ms 30600 KB Output is correct
11 Correct 57 ms 34748 KB Output is correct
12 Correct 97 ms 34676 KB Output is correct
13 Correct 107 ms 34956 KB Output is correct
14 Correct 80 ms 34312 KB Output is correct
15 Correct 72 ms 20044 KB Output is correct
16 Correct 74 ms 20068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 2 ms 980 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 35 ms 30600 KB Output is correct
11 Correct 57 ms 34748 KB Output is correct
12 Correct 97 ms 34676 KB Output is correct
13 Correct 107 ms 34956 KB Output is correct
14 Correct 80 ms 34312 KB Output is correct
15 Correct 72 ms 20044 KB Output is correct
16 Correct 74 ms 20068 KB Output is correct
17 Correct 91 ms 34848 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 6 ms 1092 KB Output is correct
24 Correct 6 ms 1112 KB Output is correct
25 Correct 9 ms 1112 KB Output is correct
26 Correct 7 ms 1044 KB Output is correct
27 Correct 43 ms 30524 KB Output is correct
28 Correct 100 ms 34720 KB Output is correct
29 Correct 105 ms 34968 KB Output is correct
30 Correct 82 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 34760 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 3 ms 1008 KB Output is correct
6 Correct 3 ms 988 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 59 ms 30156 KB Output is correct
9 Correct 54 ms 26240 KB Output is correct
10 Correct 30 ms 18368 KB Output is correct
11 Correct 74 ms 32716 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 18 ms 1124 KB Output is correct
18 Correct 17 ms 1156 KB Output is correct
19 Correct 52 ms 30540 KB Output is correct
20 Correct 102 ms 34952 KB Output is correct
21 Correct 88 ms 35012 KB Output is correct
22 Correct 79 ms 27508 KB Output is correct
23 Correct 92 ms 22092 KB Output is correct
24 Correct 54 ms 20760 KB Output is correct
25 Correct 80 ms 20120 KB Output is correct
26 Correct 82 ms 20060 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 4 ms 1108 KB Output is correct
35 Correct 2 ms 988 KB Output is correct
36 Correct 35 ms 30600 KB Output is correct
37 Correct 57 ms 34748 KB Output is correct
38 Correct 97 ms 34676 KB Output is correct
39 Correct 107 ms 34956 KB Output is correct
40 Correct 80 ms 34312 KB Output is correct
41 Correct 72 ms 20044 KB Output is correct
42 Correct 74 ms 20068 KB Output is correct
43 Correct 91 ms 34848 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 6 ms 1092 KB Output is correct
50 Correct 6 ms 1112 KB Output is correct
51 Correct 9 ms 1112 KB Output is correct
52 Correct 7 ms 1044 KB Output is correct
53 Correct 43 ms 30524 KB Output is correct
54 Correct 100 ms 34720 KB Output is correct
55 Correct 105 ms 34968 KB Output is correct
56 Correct 82 ms 33484 KB Output is correct
57 Correct 140 ms 35516 KB Output is correct
58 Correct 59 ms 30540 KB Output is correct
59 Correct 100 ms 34976 KB Output is correct