結果
問題 | No.1283 Extra Fee |
ユーザー |
![]() |
提出日時 | 2020-11-10 20:01:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,700 bytes |
コンパイル時間 | 3,104 ms |
コンパイル使用メモリ | 197,848 KB |
最終ジャッジ日時 | 2025-01-15 21:59:58 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 14 |
ソースコード
#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; }