結果

問題 No.2095 High Rise
ユーザー
提出日時 2022-10-07 22:13:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 2,935 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 122,128 KB
実行使用メモリ 18,856 KB
最終ジャッジ日時 2023-09-03 13:02:31
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 45 ms
7,972 KB
testcase_18 AC 30 ms
7,404 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 47 ms
5,352 KB
testcase_21 AC 89 ms
9,072 KB
testcase_22 AC 366 ms
18,744 KB
testcase_23 AC 367 ms
18,736 KB
testcase_24 AC 368 ms
18,700 KB
testcase_25 AC 368 ms
18,812 KB
testcase_26 AC 370 ms
18,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>
using namespace std;
namespace atcoder{};using namespace atcoder;

using ull = uint64_t;
using ll = int64_t;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using ld = long double;
using P = pair<ll,ll>;
using G = vector<vector<int>>;

#ifdef MYDEBUG
#define LO(...) fprintf(stderr, __VA_ARGS__)
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl
#else
#define LO(...) (void)0
#define debug(x) (void)0
#endif

#define reps(i,a,n) for(ll i##_len = (ll)(n), i = (a); i < i##_len; ++i)
#define rep(i,n) reps(i,0,n)
#define rrep(i,n) reps(i,1,n+1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

#define inp(i) ll i; cin >> i;
#define inps(s) string s; cin >> s;
#define inpp(p) cin >> (p).first >> (p).second
#define inpv(v,N) vll v(N);rep(i,N)cin>>v[i];
#define inpg(g,N,M) g.resize(N);rep(i,M){inp(a);inp(b);a--,b--;g[a].push_back(b);g[b].push_back(a);}
#define all(v) begin(v),end(v)
#define YESNO(b) cout<<(b?"YES\n":"NO\n")
#define yesno(b) cout<<(b?"yes\n":"no\n")
#define YesNo(b) cout<<(b?"Yes\n":"No\n")
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"

#define SP cout << " "
#define ENDL cout << "\n"
#define ou(i) cout << (i)
#define ous(i) cout << (i) << " "
#define oul(i) cout << (i) << "\n"
#define setfp() cout << fixed << setprecision(16)

template<typename C> void ouv(const C &v){for(auto &&e:v){cout << e;if(&e != &v.back()) cout << ' ';}cout << "\n";}
template<typename C> void ouvadd(const C &v){for(auto &&e:v){cout << e+1;if(&e != &v.back()) cout << ' ';}cout << "\n";}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

inline ll lg(ll __n) { return sizeof(ll) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};

ll dp[1010][1010];

int main(){
    inp(N);
    inp(M);

    if(N==1){oul(0);return 0;}

    vector a(N,vll(M));
    rep(i,N){
        rep(j,M){
            cin>>a[i][j];
        }
    }

    ll mn = 0;
    rep(i,N){
        ll nex = 1e18;
        LO("i=%ld  : ", i);
        rep(j,M){
            ll sub = i?a[i-1][j]:0;
            dp[i+1][j] = min(dp[i][j] + a[i][j], mn + a[i][j] + sub);
            chmin(nex, dp[i+1][j]);
            LO("%ld ", dp[i+1][j]);
        }
        LO("\n");
        mn = nex;
    }
    ll ans = 1e18;
    rep(i,M){
        chmin(ans, dp[N][i]);
    }
    oul(ans);

    return 0;
}
0