제출 #1345409

#제출 시각아이디문제언어결과실행 시간메모리
1345409Francisco_MartinIMO (EGOI25_imo)C++20
100 / 100
819 ms18580 KiB
//EGOI 2025 IMO
//https://qoj.ac/contest/2344/problem/13171

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;

int main(){
    ll n, m, K, ans=0;
    cin >> n >> m >> K;
    vector<vll> A(n,vll(m)); vll tot(n), ord(n); iota(ord.begin(),ord.end(),0);
    for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j], tot[i]+=A[i][j];
    sort(ord.begin(),ord.end(),[&](ll a,ll b){
        if(tot[a]!=tot[b]) return tot[a]>tot[b];
        return a<b;
    });
    vll dp(m+1,-1); dp[0]=1e18;
    for(int i=0; i<n; i++){
        ll cur=tot[ord[i]], nxt=(i+1<n?tot[ord[i+1]]:0), len=cur-nxt;
        vector<vector<bool>> dp2(len+1,vector<bool>(m+1,false)); dp2[len][0]=true;
        for(int x:A[ord[i]]){
            vector<vector<bool>> ndp2=dp2;
            for(int j=0; j<=len; j++) for(int k=0; k<m; k++) if(dp2[j][k]){
                if(j>=x) ndp2[j-x][k+1]=true;
            }
            swap(dp2,ndp2);
        }
        vll ndp(m+1,-1);
        for(int k=0; k<=m; k++) if(dp[k]!=-1){
            for(int j=0; j<=len; j++) for(int k2=0; k2<=m; k2++) if(dp2[j][k2]){
                if(k+k2>m) continue;
                ll l=nxt+j, r=l+k2*K; bool flag=false;
                if(i==0) flag=true;
                else if(dp[k]>r || (dp[k]==r && ord[i-1]<ord[i])) flag=true;
                if(flag) ndp[k+k2]=max(ndp[k+k2],l);
            }
        }
        swap(dp,ndp);
    }
    for(int i=0; i<=m; i++) if(dp[i]!=-1) ans=i;
    cout << n*m-ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...