# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
208137 |
2020-03-10T05:08:52 Z |
tri |
Soccer (JOI17_soccer) |
C++14 |
|
481 ms |
106600 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
namespace debug {
const int DEBUG = true;
template<class T1, class T2>
void pr(const pair<T1, T2> &x);
template<class T, size_t SZ>
void pr(const array<T, SZ> &x);
template<class T>
void pr(const vector<T> &x);
template<class T>
void pr(const set<T> &x);
template<class T1, class T2>
void pr(const map<T1, T2> &x);
template<class T>
void pr(const T &x) { if (DEBUG) cout << x; }
template<class T, class... Ts>
void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
template<class T1, class T2>
void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
template<class T>
void prIn(const T &x) {
pr("{");
bool fst = 1;
for (auto &a : x) {
pr(fst ? "" : ", ", a), fst = 0;
}
pr("}");
}
template<class T, size_t SZ>
void pr(const array<T, SZ> &x) { prIn(x); }
template<class T>
void pr(const vector<T> &x) { prIn(x); }
template<class T>
void pr(const set<T> &x) { prIn(x); }
template<class T1, class T2>
void pr(const map<T1, T2> &x) { prIn(x); }
void ps() { pr("\n"), cout << flush; }
template<class Arg, class... Args>
void ps(const Arg &first, const Args &... rest) {
pr(first, " ");
ps(rest...);
}
}
using namespace debug;
const ll INF = 1e15;
int H, W;
ll A, B, C;
int N;
vector<pi> pts;
pi st;
pi ed;
ll distP[600][600];
int dI[] = {-1, 0, 1, 0};
int dJ[] = {0, -1, 0, 1};
bool valid(int i, int j) {
return 0 <= i && i < H && 0 <= j && j < W;
}
void bfs() {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
distP[i][j] = INF;
}
}
queue<pi> q;
for (pi x :pts) {
distP[x.f][x.s] = 0;
q.push(x);
}
while (q.size()) {
pi x = q.front();
q.pop();
ll cDist = distP[x.f][x.s];
for (int d = 0; d < 4; d++) {
int nI = x.f + dI[d], nJ = x.s + dJ[d];
if (valid(nI, nJ)) {
if (distP[nI][nJ] == INF) {
distP[nI][nJ] = cDist + 1;
q.push({nI, nJ});
}
}
}
}
}
inline int lin(int i, int j, int t) {
return W * i + j + H * W * t;
}
const int MAXV = 501 * 501 * 3 + 10;
vector<pl> aL[MAXV];
ll dist[MAXV];
ll dijkstra(int sV, int eV) {
fill(dist, dist + MAXV, INF);
priority_queue<pl, vector<pl>, greater<pl>> q;
q.push({0, sV});
dist[sV] = 0;
while (q.size()) {
pl x = q.top();
q.pop();
ll cD = x.f;
int cV = x.s;
if (cV == eV) {
return cD;
}
if (cD > dist[cV]) {
continue;
}
for (pl aE : aL[cV]) {
int aV = aE.f;
ll eC = aE.s;
if (cD + eC < dist[aV]) {
dist[aV] = cD + eC;
q.push({cD + eC, aV});
}
}
}
// ps(dist[eV]);
assert(false);
return -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> H >> W;
H++, W++;
cin >> A >> B >> C;
cin >> N;
// ps('h');
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
pts.pb({x, y});
}
st = pts[0];
ed = pts[N - 1];
// ps("read");
sort(pts.begin(), pts.end());
pts.erase(unique(pts.begin(), pts.end()), pts.end());
N = pts.size();
bfs();
// ps("fin bfs");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
for (int d = 0; d < 4; d++) {
int nI = i + dI[d], nJ = j + dJ[d];
if (valid(nI, nJ)) {
// kick
int t = d & 1;
assert(t != 2);
aL[lin(i, j, t)].pb({lin(nI, nJ, t), A});
}
}
for (int t = 0; t < 2; t++) {
// kick the ball
aL[lin(i, j, 2)].pb({lin(i, j, t), B});
// ball stop, person run to it
aL[lin(i, j, t)].pb({lin(i, j, 2), distP[i][j] * C});
}
// run with ball
for (int d = 0; d < 4; d++) {
int nI = i + dI[d], nJ = j + dJ[d];
if (valid(nI, nJ)) {
aL[lin(i, j, 2)].pb({lin(nI, nJ, 2), C});
}
}
// if (i % 10 && j == 0) ps(i, j);
}
}
// ps("added");
int sV = lin(st.f, st.s, 2);
int eV = lin(ed.f, ed.s, 2);
ll ans = dijkstra(sV, eV);
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
44400 KB |
Output is correct |
2 |
Correct |
18 ms |
24056 KB |
Output is correct |
3 |
Correct |
282 ms |
105196 KB |
Output is correct |
4 |
Correct |
227 ms |
103124 KB |
Output is correct |
5 |
Correct |
116 ms |
52856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
103156 KB |
Output is correct |
2 |
Correct |
216 ms |
102080 KB |
Output is correct |
3 |
Correct |
253 ms |
89704 KB |
Output is correct |
4 |
Correct |
392 ms |
105104 KB |
Output is correct |
5 |
Correct |
273 ms |
90212 KB |
Output is correct |
6 |
Correct |
353 ms |
105064 KB |
Output is correct |
7 |
Correct |
283 ms |
105160 KB |
Output is correct |
8 |
Correct |
279 ms |
105064 KB |
Output is correct |
9 |
Correct |
208 ms |
102104 KB |
Output is correct |
10 |
Correct |
60 ms |
39408 KB |
Output is correct |
11 |
Correct |
358 ms |
105152 KB |
Output is correct |
12 |
Correct |
340 ms |
105192 KB |
Output is correct |
13 |
Correct |
268 ms |
89828 KB |
Output is correct |
14 |
Correct |
264 ms |
105084 KB |
Output is correct |
15 |
Correct |
164 ms |
86648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
44400 KB |
Output is correct |
2 |
Correct |
18 ms |
24056 KB |
Output is correct |
3 |
Correct |
282 ms |
105196 KB |
Output is correct |
4 |
Correct |
227 ms |
103124 KB |
Output is correct |
5 |
Correct |
116 ms |
52856 KB |
Output is correct |
6 |
Correct |
227 ms |
103156 KB |
Output is correct |
7 |
Correct |
216 ms |
102080 KB |
Output is correct |
8 |
Correct |
253 ms |
89704 KB |
Output is correct |
9 |
Correct |
392 ms |
105104 KB |
Output is correct |
10 |
Correct |
273 ms |
90212 KB |
Output is correct |
11 |
Correct |
353 ms |
105064 KB |
Output is correct |
12 |
Correct |
283 ms |
105160 KB |
Output is correct |
13 |
Correct |
279 ms |
105064 KB |
Output is correct |
14 |
Correct |
208 ms |
102104 KB |
Output is correct |
15 |
Correct |
60 ms |
39408 KB |
Output is correct |
16 |
Correct |
358 ms |
105152 KB |
Output is correct |
17 |
Correct |
340 ms |
105192 KB |
Output is correct |
18 |
Correct |
268 ms |
89828 KB |
Output is correct |
19 |
Correct |
264 ms |
105084 KB |
Output is correct |
20 |
Correct |
164 ms |
86648 KB |
Output is correct |
21 |
Correct |
100 ms |
52472 KB |
Output is correct |
22 |
Correct |
447 ms |
105052 KB |
Output is correct |
23 |
Correct |
451 ms |
95340 KB |
Output is correct |
24 |
Correct |
398 ms |
103096 KB |
Output is correct |
25 |
Correct |
395 ms |
105188 KB |
Output is correct |
26 |
Correct |
444 ms |
105316 KB |
Output is correct |
27 |
Correct |
346 ms |
102344 KB |
Output is correct |
28 |
Correct |
459 ms |
102552 KB |
Output is correct |
29 |
Correct |
481 ms |
104820 KB |
Output is correct |
30 |
Correct |
347 ms |
102512 KB |
Output is correct |
31 |
Correct |
255 ms |
103160 KB |
Output is correct |
32 |
Correct |
322 ms |
106600 KB |
Output is correct |
33 |
Correct |
366 ms |
105064 KB |
Output is correct |
34 |
Correct |
215 ms |
102104 KB |
Output is correct |
35 |
Correct |
379 ms |
102636 KB |
Output is correct |