結果

問題 No.3368 トッピング
コンテスト
ユーザー Rubikun
提出日時 2025-11-17 23:14:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,848 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 201,752 KB
実行使用メモリ 8,016 KB
最終ジャッジ日時 2025-11-17 23:14:29
合計ジャッジ時間 4,729 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int dp[2005][205][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,C,X;cin>>N>>M>>C>>X;
    vvi A(N,vi(M));
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin>>A[i][j];
        }
    }
    
    int l=-INF,r=INF;
    while(r-l>1){
        int m=(l+r)/2;
        for(int i=0;i<=N;i++){
            for(int j=0;j<M;j++){
                dp[i][j][0]=dp[i][j][1]=-INF;
            }
        }
        for(int j=0;j<M;j++){
            if(A[0][j]>=m){
                dp[1][j][0]=0;
            }
            if(A[0][j]-C>=m&&A[1][j]-C>=m){
                dp[2][j][1]=2;
            }
        }
        for(int i=1;i<N;i++){
            int ma=-INF;
            for(int j=0;j<M;j++){
                if(A[i][j]>=m) chmax(dp[i+1][j][0],ma);
                chmax(ma,dp[i][j][0]);
                chmax(ma,dp[i][j][1]);
            }
            ma=-INF;
            for(int j=M-1;j>=0;j--){
                if(A[i][j]>=m) chmax(dp[i+1][j][0],ma);
                chmax(ma,dp[i][j][0]);
                chmax(ma,dp[i][j][1]);
            }
            for(int j=0;j<M;j++){
                if(dp[i][j][1]>=0&&A[i][j]-C>=m) chmax(dp[i+1][j][1],dp[i][j][1]+1);
            }
            
            if(i+1<N){
                ma=-INF;
                for(int j=0;j<M;j++){
                    if(A[i][j]-C>=m&&A[i+1][j]-C>=m) chmax(dp[i+2][j][1],ma+2);
                    chmax(ma,dp[i][j][0]);
                }
                ma=-INF;
                for(int j=M-1;j>=0;j--){
                    if(A[i][j]-C>=m&&A[i+1][j]-C>=m) chmax(dp[i+2][j][1],ma+2);
                    chmax(ma,dp[i][j][0]);
                }
            }
        }
        
        bool ok=false;
        for(int j=0;j<M;j++){
            if(dp[N][j][0]>=X) ok=true;
            if(dp[N][j][1]>=X) ok=true;
        }
        
        if(ok) l=m;
        else r=m;
    }
    cout<<l<<endl;
    
}


0