# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874066 |
2023-11-16T08:42:11 Z |
hqminhuwu |
Toll (BOI17_toll) |
C++17 |
|
82 ms |
169296 KB |
#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"
using namespace std;
const int N = 5e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;
inline void mnmize (int &u, int v){
if (u > v)
u = v;
}
int n,m,x,q,u,v,w,i,up[20][100005][6][6],j,k,g,l;
vector <pii> a[N];
int res[6][6],nres[6][6];
void jump (int u, int d){
forr (l,0,16)
if ((1 << l) & d){
forf (i,0,x)
forf (j,0,x)
nres[i][j] = oo;
forf (i,0,x)
forf (j,0,x)
forf (k,0,x)
mnmize (nres[i][k],res[i][j] + up[l][u][j][k]);
swap(res,nres);
u += (1 << l);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> x >> n >> m >> q;
int bl = n / x;
forr (i,1,m){
cin >> u >> v >> w;
a[u].pb({v,w});
a[v].pb({u,w});
}
forr (l,0,16)
forr (i,0,bl)
forf (j,0,x)
forf (k,0,x)
up[l][i][j][k] = oo;
forr (i,0,bl)
forf (j,0,x)
for (pii v : a[i * x + j]){
mnmize (up[0][i][j][v.st % x],v.nd);
}
forr (l,1,16)
forr (i,0,bl){
int f = i + (1 << (l - 1));
forf (j,0,x)
forf (k,0,x)
forf (g,0,x)
mnmize (up[l][i][j][g],up[l - 1][i][j][k] + up[l - 1][i + f][k][g]);
}
while (q--){
int b,c;
cin >> b >> c;
memset(res,0,sizeof res);
jump(b/x, c/x - b/x);
if (res[b % x][c % x] < oo)
cout << res[b % x][c % x] << "\n";
else cout << "-1\n";
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
169296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
111796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
45656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
45656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
169296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |