# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527887 |
2022-02-18T15:56:06 Z |
AdamGS |
Soccer (JOI17_soccer) |
C++17 |
|
3000 ms |
262148 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=507, MAXN=1e5+7;
const ll INF=1e18+7;
int dx[]={1, 0, -1, 0}, dy[]={0, 1, 0, -1};
ll wart[LIM][LIM], odl[LIM][LIM], h, w, a, b, c, n;
pair<int,int>T[MAXN];
bool ok(int a, int b) {
return 0<=a && a<h && 0<=b && b<w;
}
void BFS() {
rep(i, h) rep(j, w) wart[i][j]=INF;
queue<pair<int,int>>q;
rep(i, n) {
wart[T[i].st][T[i].nd]=0;
q.push({T[i].st, T[i].nd});
}
while(!q.empty()) {
int x=q.front().st, y=q.front().nd; q.pop();
rep(i, 4) if(ok(x+dx[i], y+dy[i]) && wart[x+dx[i]][y+dy[i]]==INF) {
wart[x+dx[i]][y+dy[i]]=wart[x][y]+c;
q.push({x+dx[i], y+dy[i]});
}
}
}
void dijkstra() {
rep(i, h) rep(j, w) odl[i][j]=INF;
priority_queue<pair<ll,pair<int,int>>>q;
q.push({0, {T[0].st, T[0].nd}});
while(!q.empty()) {
ll o=-q.top().st, x=q.top().nd.st, y=q.top().nd.nd; q.pop();
if(odl[x][y]<=o) continue;
odl[x][y]=o;
rep(i, 4) for(ll j=1; ok(x+dx[i]*j, y+dy[i]*j); ++j) {
ll p=min(j*c, j*a+b+wart[x+dx[i]*j][y+dy[i]*j]);
if(odl[x+dx[i]*j][y+dy[i]*j]>o+p) q.push({-o-p, {x+dx[i]*j, y+dy[i]*j}});
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> h >> w >> a >> b >> c >> n; ++h; ++w;
rep(i, n) cin >> T[i].st >> T[i].nd;
BFS();
dijkstra();
cout << odl[T[n-1].st][T[n-1].nd] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3107 ms |
134160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
444 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3107 ms |
134160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |