結果
問題 | No.1283 Extra Fee |
ユーザー | kappybar |
提出日時 | 2020-11-06 22:22:34 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 1,832 bytes |
コンパイル時間 | 1,873 ms |
コンパイル使用メモリ | 171,440 KB |
実行使用メモリ | 18,204 KB |
最終ジャッジ日時 | 2023-08-10 06:01:23 |
合計ジャッジ時間 | 8,020 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
5,636 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
5,488 KB |
testcase_09 | AC | 3 ms
5,508 KB |
testcase_10 | AC | 2 ms
5,476 KB |
testcase_11 | AC | 17 ms
6,496 KB |
testcase_12 | AC | 20 ms
6,016 KB |
testcase_13 | AC | 14 ms
5,892 KB |
testcase_14 | AC | 58 ms
6,460 KB |
testcase_15 | AC | 93 ms
6,624 KB |
testcase_16 | AC | 20 ms
5,988 KB |
testcase_17 | AC | 278 ms
17,708 KB |
testcase_18 | AC | 332 ms
9,260 KB |
testcase_19 | AC | 354 ms
9,268 KB |
testcase_20 | AC | 333 ms
9,132 KB |
testcase_21 | AC | 339 ms
9,472 KB |
testcase_22 | AC | 300 ms
9,116 KB |
testcase_23 | AC | 353 ms
9,404 KB |
testcase_24 | AC | 419 ms
9,664 KB |
testcase_25 | AC | 366 ms
9,364 KB |
testcase_26 | AC | 364 ms
9,472 KB |
testcase_27 | AC | 366 ms
9,368 KB |
testcase_28 | AC | 361 ms
9,480 KB |
testcase_29 | AC | 298 ms
18,204 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; ll dp[505][505][2]; ll check[505][505]; int main(){ int n,m; cin >> n >> m; rep(i,m){ int h,w; ll c; cin >> h >> w >> c; --h;--w; check[h][w] = c; } rep(i,n)rep(j,n)rep(k,2) dp[i][j][k] = -1; priority_queue<pll,vector<pll>,greater<pll>> pq; auto id = [&](int i,int j,int k){ return 2*(i+j*n)+k;}; pq.push(pll(0,id(0,0,0))); while(!pq.empty()){ pll now = pq.top(); pq.pop(); ll res = now.first; int i = (now.second / 2) % n; int j = (now.second / 2) / n; int k = (now.second % 2); if(dp[i][j][k] != -1) continue; dp[i][j][k] = res; rep(c,4){ int now_i = i + dx[c]; int now_j = j + dy[c]; if(now_i < 0 || now_j < 0 || n <= now_i || n <= now_j) continue; if(check[now_i][now_j] == 0){ if(dp[now_i][now_j][k] == -1) pq.push(pll(res+1,id(now_i,now_j,k))); }else{ if(k == 0){ if(dp[now_i][now_j][k] == -1) pq.push(pll(res+1+check[now_i][now_j],id(now_i,now_j,k))); if(dp[now_i][now_j][k+1] == -1) pq.push(pll(res+1,id(now_i,now_j,k+1))); }else{ if(dp[now_i][now_j][k] == -1) pq.push(pll(res+1+check[now_i][now_j],id(now_i,now_j,k))); } } } } cout << min(dp[n-1][n-1][0],dp[n-1][n-1][1]) << endl; return 0; }