# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
635924 |
2022-08-27T11:39:47 Z |
Karliver |
Soccer (JOI17_soccer) |
C++17 |
|
429 ms |
19412 KB |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int mod = (ll)1e9 + 7;
const int INF = 1e9 + 1;
const int N = 502;
const double eps = 1e-7;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
return (x > y ? x = y, 1 : 0);
}
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
ll d[N][N][5], com[N][N];
int n, h, w;
ll A, B, C;
PR<int> c[200001];
const long long inf = 1e18 + 2;
V<PR<int>> dir{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
void solve() {
cin >> h >> w >> A >> B >> C >> n;
forn(i, n) cin >> c[i].ff >> c[i].se;
forn(i, h + 1) forn(j, w + 1) {
com[i][j] = -1;
forn(k, 5) d[i][j][k] = inf;
}
queue<PR<int>> q;
forn(k, n) {
auto &[i, j] = c[k];
if(com[i][j] == -1) {
com[i][j] = 0;
q.emplace(i, j);
}
}
while(size(q)) {
auto [i, j] = q.front();
q.pop();
for(auto [di, dj] : dir) {
int x = di + i, y = j + dj;
if(0 <= x && x <= h && 0 <= y && y <= w && com[x][y] == -1) {
com[x][y] = com[i][j] + C;
q.push({x, y});
}
}
}
priority_queue<tuple<ll, int, int, int>> pq;
d[c[0].ff][c[0].se][4] = 0;
pq.push({0, c[0].ff, c[0].se, 4});
auto upd = [&](int i, int j, int t, ll a) {
if(0 <= i && i <= h && 0 <= j && j <= w && a < d[i][j][t]) {
d[i][j][t] = a;
pq.push({-a, i, j, t});
}
};
while(!pq.empty()) {
auto [s, i, j, t] = pq.top();
pq.pop();
s = -s;
//debug(i, j, s);
if(d[i][j][t] < s) continue;
if(t == 4) {
forn(p, 4) {
int x = dir[p].ff + i, y = dir[p].se + j;
upd(i, j, p, s+B);
upd(x, y, 4, s+C);
}
}
else {
int x = dir[t].ff + i, y = dir[t].se + j;
upd(x, y, t, s+A);
upd(i, j, 4, s+com[i][j]);
}
}
cout << d[c[n-1].ff][c[n-1].se][4] << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
6736 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
270 ms |
18352 KB |
Output is correct |
4 |
Correct |
311 ms |
18420 KB |
Output is correct |
5 |
Correct |
72 ms |
6792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
18392 KB |
Output is correct |
2 |
Correct |
306 ms |
18436 KB |
Output is correct |
3 |
Correct |
267 ms |
16108 KB |
Output is correct |
4 |
Correct |
226 ms |
18408 KB |
Output is correct |
5 |
Correct |
233 ms |
18372 KB |
Output is correct |
6 |
Correct |
265 ms |
18448 KB |
Output is correct |
7 |
Correct |
323 ms |
18552 KB |
Output is correct |
8 |
Correct |
273 ms |
18448 KB |
Output is correct |
9 |
Correct |
323 ms |
18588 KB |
Output is correct |
10 |
Correct |
50 ms |
7652 KB |
Output is correct |
11 |
Correct |
317 ms |
18460 KB |
Output is correct |
12 |
Correct |
322 ms |
18404 KB |
Output is correct |
13 |
Correct |
195 ms |
16064 KB |
Output is correct |
14 |
Correct |
348 ms |
18464 KB |
Output is correct |
15 |
Correct |
249 ms |
18516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
6736 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
270 ms |
18352 KB |
Output is correct |
4 |
Correct |
311 ms |
18420 KB |
Output is correct |
5 |
Correct |
72 ms |
6792 KB |
Output is correct |
6 |
Correct |
325 ms |
18392 KB |
Output is correct |
7 |
Correct |
306 ms |
18436 KB |
Output is correct |
8 |
Correct |
267 ms |
16108 KB |
Output is correct |
9 |
Correct |
226 ms |
18408 KB |
Output is correct |
10 |
Correct |
233 ms |
18372 KB |
Output is correct |
11 |
Correct |
265 ms |
18448 KB |
Output is correct |
12 |
Correct |
323 ms |
18552 KB |
Output is correct |
13 |
Correct |
273 ms |
18448 KB |
Output is correct |
14 |
Correct |
323 ms |
18588 KB |
Output is correct |
15 |
Correct |
50 ms |
7652 KB |
Output is correct |
16 |
Correct |
317 ms |
18460 KB |
Output is correct |
17 |
Correct |
322 ms |
18404 KB |
Output is correct |
18 |
Correct |
195 ms |
16064 KB |
Output is correct |
19 |
Correct |
348 ms |
18464 KB |
Output is correct |
20 |
Correct |
249 ms |
18516 KB |
Output is correct |
21 |
Correct |
78 ms |
6728 KB |
Output is correct |
22 |
Correct |
364 ms |
18360 KB |
Output is correct |
23 |
Correct |
340 ms |
14168 KB |
Output is correct |
24 |
Correct |
393 ms |
15484 KB |
Output is correct |
25 |
Correct |
310 ms |
18468 KB |
Output is correct |
26 |
Correct |
376 ms |
18672 KB |
Output is correct |
27 |
Correct |
240 ms |
13652 KB |
Output is correct |
28 |
Correct |
228 ms |
14036 KB |
Output is correct |
29 |
Correct |
369 ms |
16400 KB |
Output is correct |
30 |
Correct |
188 ms |
13524 KB |
Output is correct |
31 |
Correct |
310 ms |
18536 KB |
Output is correct |
32 |
Correct |
408 ms |
19412 KB |
Output is correct |
33 |
Correct |
268 ms |
18420 KB |
Output is correct |
34 |
Correct |
429 ms |
18524 KB |
Output is correct |
35 |
Correct |
197 ms |
13184 KB |
Output is correct |