Submission #575866

# Submission time Handle Problem Language Result Execution time Memory
575866 2022-06-11T11:52:33 Z vaaven Soccer (JOI17_soccer) C++14
100 / 100
424 ms 23112 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <stack>
#include <iomanip>
#include <bitset>
#include <map>
#include <cassert>
#include <array>
#include <queue>
#include <cstring>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define pqueue priority_queue
#define pb(x) push_back(x)
 #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long  long
     
using namespace std;
     
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
     
const int inf = 1e9 + 228;
const int infll = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-14;
     
     
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("inputik.txt", "r", stdin);
//    freopen("outputik.txt", "w", stdout);
}
  
int w, h, n, a, b, c;
pii kek[100000];
int dist1[501][501];
int dist2[501][501][5];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
 
bool check(pii i){
    return 0 <= i.first && i.first <= w && 0 <= i.second && i.second <= h;
}
 
void calc1(){
    queue<pii> q;
    for(int i=0; i<n; i++){
        dist1[kek[i].first][kek[i].second] = 0;
        q.push(kek[i]);
    }
    while(!q.empty()){
        pii cur = q.front();
        q.pop();
        for(int j=0; j<4; j++){
            pii nw = make_pair(cur.first + dx[j], cur.second + dy[j]);
            if(check(nw) && dist1[nw.first][nw.second] > dist1[cur.first][cur.second] + c){
                dist1[nw.first][nw.second] = dist1[cur.first][cur.second] + c;
                q.push(nw);
            }
        }
    }
}
 
void calc2(){
    pqueue<array<int, 4>> q;
    q.push({0, kek[0].first, kek[0].second, 4});
    while(!q.empty()){
        array<int, 4> cur = q.top();
        q.pop();
//        cout << cur[0] << " " << cur[1] << " " << cur[2] << " " << cur[3] << endl;
        if(cur[3] == 4){
            for(int i=0; i<4; i++){
                array<int, 4> nw = {cur[0] - b, cur[1], cur[2], i};
                if(check({nw[1], nw[2]}) && dist2[nw[1]][nw[2]][nw[3]] > -nw[0]){
                    dist2[nw[1]][nw[2]][nw[3]] = -nw[0];
                    q.push(nw);
                }
            }
            for(int i=0; i<4; i++){
                array<int, 4> nw = {cur[0] - c, cur[1] + dx[i], cur[2] + dy[i], 4};
                if(check({nw[1], nw[2]}) && dist2[nw[1]][nw[2]][nw[3]] > -nw[0]){
                    dist2[nw[1]][nw[2]][nw[3]] = -nw[0];
                    q.push(nw);
                }
            }
        } else{
            if(dist2[cur[1]][cur[2]][4] > -cur[0] + dist1[cur[1]][cur[2]]){
                dist2[cur[1]][cur[2]][4] = min(dist2[cur[1]][cur[2]][4], -cur[0] + dist1[cur[1]][cur[2]]);
                q.push({cur[0] - dist1[cur[1]][cur[2]], cur[1], cur[2], 4});
            }
            if(cur[1] == kek[n-1].first && cur[2] == kek[n-1].second && dist2[cur[1]][cur[2]][4] > -cur[0]){
                dist2[cur[1]][cur[2]][4] = min(dist2[cur[1]][cur[2]][4], -cur[0]);
                q.push({cur[0], cur[1], cur[2], 4});
            }
            array<int, 4> nw = {cur[0] - a, cur[1] + dx[cur[3]], cur[2] + dy[cur[3]], cur[3]};
            if(check({nw[1], nw[2]}) && dist2[nw[1]][nw[2]][nw[3]] > -nw[0]){
                dist2[nw[1]][nw[2]][nw[3]] = -nw[0];
                q.push(nw);
            }
        }
    }
}
 
 
void solve(){
    cin >> w >> h >> a >> b >> c;
    cin >> n;
    for(auto &i:dist1)
        for(auto &j:i)
            j = infll;
    for(auto &i:dist2){
        for(auto &j:i){
            for(auto &l:j){
                l = infll;
            }
        }
    }
    for(int i=0; i<n; i++){
        cin >> kek[i].first >> kek[i].second;
    }
    calc1();
    calc2();
    cout << dist2[kek[n-1].first][kek[n-1].second][4] << endl;
}
    
signed main(){
     fast_io();
//  ;(time(NULL));
    cout << fixed << setprecision(10);
    int q = 1;
//    cin >> q;
    while(q--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 14288 KB Output is correct
2 Correct 6 ms 12116 KB Output is correct
3 Correct 266 ms 20412 KB Output is correct
4 Correct 265 ms 20424 KB Output is correct
5 Correct 68 ms 12236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 20500 KB Output is correct
2 Correct 311 ms 20400 KB Output is correct
3 Correct 227 ms 20420 KB Output is correct
4 Correct 211 ms 20556 KB Output is correct
5 Correct 229 ms 20532 KB Output is correct
6 Correct 232 ms 20476 KB Output is correct
7 Correct 309 ms 20656 KB Output is correct
8 Correct 263 ms 20452 KB Output is correct
9 Correct 342 ms 20656 KB Output is correct
10 Correct 49 ms 14280 KB Output is correct
11 Correct 304 ms 20596 KB Output is correct
12 Correct 325 ms 20404 KB Output is correct
13 Correct 170 ms 20444 KB Output is correct
14 Correct 302 ms 20572 KB Output is correct
15 Correct 237 ms 20552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 14288 KB Output is correct
2 Correct 6 ms 12116 KB Output is correct
3 Correct 266 ms 20412 KB Output is correct
4 Correct 265 ms 20424 KB Output is correct
5 Correct 68 ms 12236 KB Output is correct
6 Correct 320 ms 20500 KB Output is correct
7 Correct 311 ms 20400 KB Output is correct
8 Correct 227 ms 20420 KB Output is correct
9 Correct 211 ms 20556 KB Output is correct
10 Correct 229 ms 20532 KB Output is correct
11 Correct 232 ms 20476 KB Output is correct
12 Correct 309 ms 20656 KB Output is correct
13 Correct 263 ms 20452 KB Output is correct
14 Correct 342 ms 20656 KB Output is correct
15 Correct 49 ms 14280 KB Output is correct
16 Correct 304 ms 20596 KB Output is correct
17 Correct 325 ms 20404 KB Output is correct
18 Correct 170 ms 20444 KB Output is correct
19 Correct 302 ms 20572 KB Output is correct
20 Correct 237 ms 20552 KB Output is correct
21 Correct 77 ms 12760 KB Output is correct
22 Correct 368 ms 20400 KB Output is correct
23 Correct 350 ms 16312 KB Output is correct
24 Correct 424 ms 16700 KB Output is correct
25 Correct 322 ms 20476 KB Output is correct
26 Correct 364 ms 20920 KB Output is correct
27 Correct 225 ms 15788 KB Output is correct
28 Correct 218 ms 16748 KB Output is correct
29 Correct 315 ms 20080 KB Output is correct
30 Correct 180 ms 16060 KB Output is correct
31 Correct 314 ms 20572 KB Output is correct
32 Correct 394 ms 23112 KB Output is correct
33 Correct 256 ms 20412 KB Output is correct
34 Correct 389 ms 20656 KB Output is correct
35 Correct 178 ms 16084 KB Output is correct