結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-12-09 22:31:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 603 ms / 6,000 ms |
| コード長 | 1,602 bytes |
| コンパイル時間 | 1,801 ms |
| コンパイル使用メモリ | 182,568 KB |
| 実行使用メモリ | 35,072 KB |
| 最終ジャッジ日時 | 2024-10-14 22:27:00 |
| 合計ジャッジ時間 | 8,691 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#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;
}
houren