結果

問題 No.1283 Extra Fee
ユーザー FUN_era1FUN_era1
提出日時 2020-11-10 20:01:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,700 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 202,992 KB
実行使用メモリ 9,368 KB
最終ジャッジ日時 2023-09-30 00:10:26
合計ジャッジ時間 7,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 48 ms
9,008 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 150 ms
9,264 KB
testcase_24 AC 218 ms
9,368 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 47 ms
9,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include <atcoder/all>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll ZER = 0;
const ll MOD = 1e9 + 7;


ll dp[501][501][2];
int main(){
    // std::cin.tie(0);
    // std::ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<vector<ll>> fld(n + 1, vector<ll> (n + 1, 0));
    rep(i, n + 1)rep(j, n + 1)rep(k, 2)dp[i][j][k] = (INF * INF);
    dp[0][0][0] = 0;
    dp[1][1][0] = 0;
    rep(i, m){
        ll h, w, c;
        cin >> h >> w >> c;
        fld[h][w] = c;
    }
    REP(i, 1, n){
        REP(j, 1, n){
            chmin(dp[i][j][0], dp[i][j - 1][0] + fld[i][j]);
            chmin(dp[i][j][0], dp[i - 1][j][0] + fld[i][j]);
            chmin(dp[i][j][1], dp[i][j - 1][0]);
            chmin(dp[i][j][1], dp[i - 1][j][0]);

            chmin(dp[i][j][1], dp[i][j - 1][1] + fld[i][j]);
            chmin(dp[i][j][1], dp[i - 1][j][1] + fld[i][j]);
        }
    }
    cout << min(dp[n][n][0], dp[n][n][1]) + 2 * n - 2 << endl;
    // rep(i, n + 1){rep(j, n + 1)cout << dp[i][j][0] << " ";cout << endl;}
    // cout << endl;
    // rep(i, n + 1){rep(j, n + 1)cout << dp[i][j][1] << " ";cout << endl;}
    // cout << endl;
    // rep(i, n + 1){rep(j, n + 1)cout << fld[i][j] << " ";cout << endl;}
    // cout << endl;
}
0