# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644631 | 2022-09-25T04:50:44 Z | guagua0407 | Toll (BOI17_toll) | C++17 | 214 ms | 524288 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int k,n,m,o; const int mxn=5e5+4; int dp[mxn][20][5][5]; int ans[5][5]; int tmp[5][5]; void ckmin(int a[5][5],int b[5][5],int c[5][5]){ for(int x=0;x<5;x++){ for(int y=0;y<5;y++){ for(int z=0;z<5;z++){ a[x][z]=min(a[x][z],b[x][y]+c[y][z]); } } } } int main() {_ //setIO("wayne"); cin>>k>>n>>m>>o; memset(dp,0x3f,sizeof dp); for(int i=0;i<m;i++){ int a,b,t; cin>>a>>b>>t; dp[a/k][0][a%k][b%k]=t; } for(int j=1;j<20;j++){ for(int i=0;i+(1<<j-1)<=(n/k);i++){ ckmin(dp[i][j],dp[i][j-1],dp[i+(1<<j-1)][j-1]); } } for(int i=0;i<o;i++){ int a,b; cin>>a>>b; int node=a/k; int length=floor(b/k)-floor(a/k); memset(ans,0x3f,sizeof ans); for(int i=0;i<5;i++){ ans[i][i]=0; } //cout<<length<<'\n'; for(int i=0;i<20;i++){ if(length&(1<<i)){ memset(tmp,0x3f,sizeof tmp); ckmin(tmp,ans,dp[node][i]); memcpy(ans,tmp,sizeof ans); } } cout<<(ans[a%k][b%k]==0x3f3f3f3f?-1:ans[a%k][b%k])<<'\n'; } return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 197 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 183 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 214 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 214 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 197 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |