Submission #1101882

# Submission time Handle Problem Language Result Execution time Memory
1101882 2024-10-17T06:26:46 Z simona1230 Toll (BOI17_toll) C++17
0 / 100
116 ms 524288 KB
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;

int k,n,m,o;
vector<pair<int,int> > v[50001];
long long d[50001][32][8][8];

void read()
{
    cin>>k>>n>>m>>o;
    
    for(int b=0;b<=(n-1)/k;b++)
        for(int i1=0;i1<k;i1++)
            for(int i2=0;i2<k;i2++)
                d[b][0][i1][i2]=1e9;
                
    for(int i=1;i<=m;i++)
    {
        int a,b;
        long long t;
        cin>>a>>b>>t;
        v[a].push_back({b,t});
        int b1=a/k;
        int i1=a%k;
        int i2=b%k;
        d[b1][0][i1][i2]=min(d[b1][0][i1][i2],t);
    }
}

void prec()
{
    for(int lg=1;lg<2;lg++)
        for(int i1=0;i1<k;i1++)
            for(int i2=0;i2<k;i2++)
                for(int b=0;b<=(n-1)/k;b++)
                    {
                        d[b][lg][i1][i2]=1e9;
                        for(int i3=0;i3<k;i3++)
                             d[b][lg][i1][i2]=min(d[b][lg-1][i1][i3]
                                +d[b+(1<<(lg-1))][lg-1][i3][i2],
                                    d[b][lg][i1][i2]);
                    }
}


long long ans[8],ans2[8];
void compute(int a,int b)
{
    for(int i=0;i<k;i++)
        ans[i]=1e9;
    ans[a%k]=0;
    
    int jump=b/k-a/k;
    int block=a/k;
    for(int lg=0;lg<2;lg++)
    {
        if((1<<lg)&jump)
        {
            for(int i=0;i<k;i++)
                ans2[i]=ans[i];
            for(int i2=0;i2<k;i2++)
            {
                ans[i2]=1e9;
                for(int i1=0;i1<k;i1++)
                    ans[i2]=min(ans[i2],ans2[i1]+d[block][lg][i1][i2]);
            }
            block+=(1<<lg);
        }
    }
    
    int i=b%k;
    if(ans[i]>=1e9)cout<<-1<<endl;
    else cout<<ans[i]<<endl;
}

void solve()
{
    for(int i=1;i<=o;i++)
    {
        int a,b;
        cin>>a>>b;
        compute(a,b);
    }
}

int main() {
    read();
    prec();
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 53 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 116 ms 406568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 53 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -