Submission #307070

# Submission time Handle Problem Language Result Execution time Memory
307070 2020-09-27T00:16:06 Z fivefourthreeone Soccer (JOI17_soccer) C++17
100 / 100
559 ms 21892 KB
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(auto i=(a);i<(b); ++i)
#define uwu(i,a, b) for(auto i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
const int mxV = 501;
int n;
int dist[mxV][mxV];
ttgl per[mxN];
//we can represent a state the following way, x, y, movement, cost
struct state {
    int x, y, dir;
    ll w;
    bool operator <(const state &o) const {
        return w > o.w;
    }
};
int h, w;
ll a, b, c;
ll dp[mxV][mxV][6];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool inside(int x, int y) {
    return x>=0&&x<=h&&y>=0&&y<=w;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>h>>w>>a>>b>>c>>n;
    queue<array<int, 3>> Q;
    memset(dist, INF, sizeof(dist));
    memset(dp, INFLL, sizeof(dp));
    owo(i, 0, n) {
        cin>>per[i].first>>per[i].second;
        Q.push({per[i].first, per[i].second, 0});
        dist[per[i].first][per[i].second] = 0;
    }
    while(!Q.empty()) {
        auto[x, y, currd] = Q.front();
        Q.pop();
        owo(d, 0, 4) {
            if(inside(x + dx[d], y + dy[d]) && dist[x + dx[d]][y + dy[d]] == INF) {
                dist[x + dx[d]][y + dy[d]] = currd + 1;
                Q.push({x + dx[d], y + dy[d], currd + 1});
            }
        }
    }
    priority_queue<state> pq;
    pq.push({per[0].first, per[0].second, 0, 0});
    dp[per[0].first][per[0].second][0] = 0;
    while(!pq.empty()) {
        auto [x, y, dir, currd] = pq.top();
        pq.pop();
        if(currd > dp[x][y][dir])continue;
        if(dir==0) {
            owo(d, 0, 4) {
                if(inside(x + dx[d], y + dy[d])) {
                    //kick
                    if(dp[x][y][d + 2] > currd + b) {
                        dp[x][y][d + 2] = currd + b;
                        pq.push({x, y, d + 2, currd + b});
                    }
                    //run
                    if(dp[x + dx[d]][y + dy[d]][0] > currd + c) {
                        dp[x + dx[d]][y + dy[d]][0] = currd + c;
                        pq.push({x + dx[d], y + dy[d], 0, currd + c});
                    }
                }
                //drop
                if(dp[x][y][1] > currd) {
                    dp[x][y][1] = currd;
                    pq.push({x, y, 1, currd});
                }
            }
        }else if(dir==1) {
            //pick up ball
            if(dp[x][y][0] > currd + 1LL * c * dist[x][y]) {
                dp[x][y][0] = currd + 1LL * c * dist[x][y];
                pq.push({x, y, 0, dp[x][y][0]});
            }
        }else {
            //stop
            if(dp[x][y][1] > currd) {
                dp[x][y][1] = currd;
                pq.push({x, y, 1, currd});
            }
            //roll
            if(inside(x + dx[dir - 2], y + dy[dir - 2]) && dp[x + dx[dir - 2]][y + dy[dir - 2]][dir] > currd + a) {
                dp[x + dx[dir - 2]][y + dy[dir - 2]][dir] = currd + a;
                pq.push({x + dx[dir - 2], y + dy[dir - 2], dir, currd + a});
            }
        }
    }
    ll ans = INFLL;
    owo(i, 0, 6) {
        ans = min(ans, dp[per[n-1].first][per[n-1].second][i]);
    }
    cout<<ans<<"\n";
    return 0;
}

Compilation message

soccer.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
soccer.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
soccer.cpp: In function 'int main()':
soccer.cpp:58:16: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '4557430888798830399' to '1061109567' [-Woverflow]
   58 |     memset(dp, INFLL, sizeof(dp));
      |                ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 84 ms 14968 KB Output is correct
2 Correct 8 ms 13184 KB Output is correct
3 Correct 368 ms 19436 KB Output is correct
4 Correct 395 ms 19436 KB Output is correct
5 Correct 66 ms 13184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 19448 KB Output is correct
2 Correct 416 ms 19452 KB Output is correct
3 Correct 304 ms 19436 KB Output is correct
4 Correct 309 ms 19432 KB Output is correct
5 Correct 308 ms 19452 KB Output is correct
6 Correct 338 ms 19440 KB Output is correct
7 Correct 407 ms 19620 KB Output is correct
8 Correct 386 ms 19472 KB Output is correct
9 Correct 415 ms 19744 KB Output is correct
10 Correct 60 ms 14888 KB Output is correct
11 Correct 416 ms 19620 KB Output is correct
12 Correct 412 ms 19776 KB Output is correct
13 Correct 256 ms 19436 KB Output is correct
14 Correct 411 ms 19620 KB Output is correct
15 Correct 322 ms 19620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 14968 KB Output is correct
2 Correct 8 ms 13184 KB Output is correct
3 Correct 368 ms 19436 KB Output is correct
4 Correct 395 ms 19436 KB Output is correct
5 Correct 66 ms 13184 KB Output is correct
6 Correct 430 ms 19448 KB Output is correct
7 Correct 416 ms 19452 KB Output is correct
8 Correct 304 ms 19436 KB Output is correct
9 Correct 309 ms 19432 KB Output is correct
10 Correct 308 ms 19452 KB Output is correct
11 Correct 338 ms 19440 KB Output is correct
12 Correct 407 ms 19620 KB Output is correct
13 Correct 386 ms 19472 KB Output is correct
14 Correct 415 ms 19744 KB Output is correct
15 Correct 60 ms 14888 KB Output is correct
16 Correct 416 ms 19620 KB Output is correct
17 Correct 412 ms 19776 KB Output is correct
18 Correct 256 ms 19436 KB Output is correct
19 Correct 411 ms 19620 KB Output is correct
20 Correct 322 ms 19620 KB Output is correct
21 Correct 78 ms 13644 KB Output is correct
22 Correct 525 ms 19444 KB Output is correct
23 Correct 497 ms 16464 KB Output is correct
24 Correct 527 ms 16552 KB Output is correct
25 Correct 450 ms 19452 KB Output is correct
26 Correct 463 ms 19748 KB Output is correct
27 Correct 245 ms 15808 KB Output is correct
28 Correct 216 ms 16448 KB Output is correct
29 Correct 402 ms 18748 KB Output is correct
30 Correct 205 ms 16000 KB Output is correct
31 Correct 460 ms 19752 KB Output is correct
32 Correct 559 ms 21892 KB Output is correct
33 Correct 365 ms 19440 KB Output is correct
34 Correct 559 ms 19616 KB Output is correct
35 Correct 193 ms 15864 KB Output is correct