結果
問題 | No.1283 Extra Fee |
ユーザー | ぷら |
提出日時 | 2021-03-13 01:58:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 290 ms / 2,000 ms |
コード長 | 1,825 bytes |
コンパイル時間 | 1,725 ms |
コンパイル使用メモリ | 173,716 KB |
実行使用メモリ | 24,456 KB |
最終ジャッジ日時 | 2024-04-27 23:49:09 |
合計ジャッジ時間 | 6,587 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
9,472 KB |
testcase_01 | AC | 3 ms
9,344 KB |
testcase_02 | AC | 3 ms
9,472 KB |
testcase_03 | AC | 3 ms
9,600 KB |
testcase_04 | AC | 3 ms
9,472 KB |
testcase_05 | AC | 4 ms
9,472 KB |
testcase_06 | AC | 3 ms
9,600 KB |
testcase_07 | AC | 3 ms
9,344 KB |
testcase_08 | AC | 4 ms
9,472 KB |
testcase_09 | AC | 3 ms
9,472 KB |
testcase_10 | AC | 4 ms
9,344 KB |
testcase_11 | AC | 13 ms
11,008 KB |
testcase_12 | AC | 15 ms
11,008 KB |
testcase_13 | AC | 13 ms
10,368 KB |
testcase_14 | AC | 47 ms
12,416 KB |
testcase_15 | AC | 71 ms
13,824 KB |
testcase_16 | AC | 19 ms
10,624 KB |
testcase_17 | AC | 153 ms
23,932 KB |
testcase_18 | AC | 246 ms
19,968 KB |
testcase_19 | AC | 267 ms
20,480 KB |
testcase_20 | AC | 254 ms
19,968 KB |
testcase_21 | AC | 258 ms
20,076 KB |
testcase_22 | AC | 235 ms
19,328 KB |
testcase_23 | AC | 211 ms
20,224 KB |
testcase_24 | AC | 284 ms
20,352 KB |
testcase_25 | AC | 277 ms
20,608 KB |
testcase_26 | AC | 290 ms
20,352 KB |
testcase_27 | AC | 274 ms
20,584 KB |
testcase_28 | AC | 285 ms
20,480 KB |
testcase_29 | AC | 172 ms
24,456 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; int cost[505][505]; long long dist[505][505][5]; vector<array<long long,3>> road[505][505]; int main() { int N,M; cin >> N >> M; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cost[i][j] = 1; for(int k = 0; k < 2; k++) { dist[i][j][k] = 1e18; } } } dist[0][0][0] = 0; for(int i = 0; i < M; i++) { int h,w,c; cin >> h >> w >> c; h--; w--; cost[h][w] += c; } priority_queue<array<long long,4>,vector<array<long long,4>>,greater<array<long long,4>>>que; que.push({0,0,0,0}); while(!que.empty()) { array<long long,4> x = que.top(); que.pop(); if(x[0] > dist[x[1]][x[2]][x[3]]) { continue; } for(int i = 0; i < 4; i++) { int nx = x[1]+dx[i]; int ny = x[2]+dy[i]; if(nx >= 0 && nx < N && ny >= 0 && ny < N) { if(x[3] == 0) { if(dist[nx][ny][0] > x[0]+cost[nx][ny]) { dist[nx][ny][0] = x[0]+cost[nx][ny]; que.push({dist[nx][ny][0],nx,ny,0}); } if(dist[nx][ny][1] > x[0]+1) { dist[nx][ny][1] = x[0]+1; que.push({dist[nx][ny][1],nx,ny,1}); } } else { if(dist[nx][ny][1] > x[0]+cost[nx][ny]) { dist[nx][ny][1] = x[0]+cost[nx][ny]; que.push({dist[nx][ny][1],nx,ny,1}); } } } } } cout << min(dist[N-1][N-1][0],dist[N-1][N-1][1]) << endl; }