結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー ngtkana
提出日時 2020-04-13 23:26:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,381 ms / 2,500 ms
コード長 1,088 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 205,108 KB
最終ジャッジ日時 2025-01-09 18:20:07
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n+1),b(n+1),d(n);
    for(lint&x:a)std::cin>>x;
    for(lint&x:b)std::cin>>x;
    for(lint&x:d)std::cin>>x;
    std::sort(ALL(d));
    std::map<std::tuple<lint,lint,lint>,lint>map;
    auto ok=[&](lint c)->bool{
        std::vector<std::vector<lint>>dp(n+1,std::vector<lint>(n+1,-1));
        auto dfs=[&](auto&&f,lint i,lint j)->bool{
            lint&x=dp.at(i).at(j);
            if(x!=-1)return x;
            lint k=c-i-j;
            return x=k==0
                ||d.at(k-1)<=a.at(i+1)+b.at(j)&&f(f,i+1,j)
                ||d.at(k-1)<=a.at(i)+b.at(j+1)&&f(f,i,j+1);
        };
        return dfs(dfs,0,0);
    };
    lint l=0,r=n+1;
    while(1<r-l){
        lint c=(l+r)/2;
        (ok(c)?l:r)=c;
    }
    std::cout<<l<<'\n';
}
0