Submission #1063319

# Submission time Handle Problem Language Result Execution time Memory
1063319 2024-08-17T16:47:50 Z I_FloPPed21 Toll (BOI17_toll) C++14
0 / 100
110 ms 170648 KB
#include <bits/stdc++.h>
using namespace std;
int dp[50005][17][5][5],n,k,m,q,temp[5][5],ans[5][5];
void combine(int target[5][5],int a[5][5],int b[5][5])
{
    for(int x=0; x<k; x++)
        for(int y=0; y<k; y++)
        {
            for(int z=0; z<k; z++)
            {
                target[x][y]=min(target[x][y],a[x][z]+b[z][y]);
            }
        }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>k>>n>>m>>q;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<17; j++)
            for(int x=0; x<5; x++)
                for(int y=0; y<5; y++)
                    dp[i][j][x][y] =1e9;
    }
    for(int i=1; i<=m; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        dp[a/k][0][a%k][b%k]=c;
    }

    for(int i=1; i<17; i++)
    {
        for(int j=0; j+(1<<i)<(n+k-1)/k; j++)
        {
            combine(dp[j][i],dp[j][i-1],dp[j+1<<(i-1)][i-1]);
        }
    }

    while(q--)
    {
        int a,b;
        cin>>a>>b;
        int curent=a/k;
        int dest=b/k;
        for(int i=0; i<5; i++)
            for(int j=0; j<5; j++)
            {
                ans[i][j] =1e9;
                temp[i][j] =1e9;
            }
        for(int i = 0 ; i <5; i++)
            ans[i][i] =0;
        for(int i =16; i>=0; i--)
        {
            if(curent+(1<<i) >dest)
                continue;
            combine(temp,ans,dp[curent][i]);
            for(int t=0; t<5; t++)
                for(int j=0; j< 5; j++)
                {

                    ans[t][j]=temp[t][j];
                    temp[t][j] =1e9;
                }
            curent+=(1<<i);
        }

        if(ans[a%k][b%k]==1e9)
            cout<<-1<<'\n';
        else
            cout<<ans[a%k][b%k]<<'\n';
    }

    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:39:45: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   39 |             combine(dp[j][i],dp[j][i-1],dp[j+1<<(i-1)][i-1]);
      |                                            ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 105 ms 170064 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 110 ms 170648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Runtime error 4 ms 3932 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Runtime error 4 ms 3932 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 105 ms 170064 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -