結果

問題 No.2157 崖
ユーザー hourenhouren
提出日時 2022-12-09 22:31:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 630 ms / 6,000 ms
コード長 1,602 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 180,908 KB
実行使用メモリ 34,944 KB
最終ジャッジ日時 2023-08-05 00:14:42
合計ジャッジ時間 9,150 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 417 ms
24,740 KB
testcase_14 AC 565 ms
34,440 KB
testcase_15 AC 401 ms
26,480 KB
testcase_16 AC 407 ms
26,460 KB
testcase_17 AC 482 ms
31,020 KB
testcase_18 AC 471 ms
30,484 KB
testcase_19 AC 512 ms
28,432 KB
testcase_20 AC 630 ms
34,672 KB
testcase_21 AC 625 ms
34,944 KB
testcase_22 AC 452 ms
29,676 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/segtree>
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL <<62);
constexpr int INF = (1 << 30);
int op(int a, int b){ return min(a,b); }
int e(){ return INF; }
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> v0(m, 0), vI(m, INF);
    vector<segtree<int,op,e>> dp(n, segtree<int,op,e>(vI));
    dp[0] = segtree<int,op,e>(v0);
    rep(i,n){
        rep(j,m) cin >> a[i][j];
        sort(all(a[i]));
    }
    rep(i,n-1){
        int now = 0, upd = -INF;
        priority_queue<asc(P)> pq;
        rep(j,m){
            while(now<m && a[i+1][j]>=a[i][now]){
                pq.push({dp[i].get(now)+a[i][now], now});
                now++;
            }
            while(pq.size() && pq.top().first<a[i+1][j]){
                dp[i].set(pq.top().second, INF);
                chmax(upd, a[i][pq.top().second]);
                pq.pop();
            }
            dp[i+1].set(j, min(a[i+1][j]-upd, dp[i].prod(0, now)));
        }
    }
    int ans = INF;
    rep(i,m) chmin(ans, dp[n-1].get(i));
    if(ans==INF) ans = -1;
    cout << ans << '\n';
    return 0;
}
0