結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-01 13:56:34
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,526 bytes
コンパイル時間 6,606 ms
コンパイル使用メモリ 277,440 KB
実行使用メモリ 16,960 KB
最終ジャッジ日時 2024-05-01 13:56:48
合計ジャッジ時間 10,832 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'long long int solve(long long int, long long int, long long int*, long long int*, long long int*, long long int*, long long int)':
main.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
   54 | }
      | ^

ソースコード

diff #

#include<bits/stdc++.h>
#define in cin>>
#define out cout<<
#define mau ios::sync_with_stdio(0);
#define tidur cin.tie(0);
#define ll long long
using namespace std;

ll best, totgain;

ll binser(ll tree[], ll left, ll right, ll pos){
    while (left <= right) {
        int m = left + (right - left) / 2;

        if (tree[m] == pos)
            return 1;

        if (tree[m] < pos)
            left = m + 1;

        else
            right = m - 1;
    }
    return 0;
}

ll count(ll n, ll m, ll pos[], ll dark[], ll light[], ll tree[], ll c){
    ll s=0;
    for(ll i=0; i<m; i++){
        if(binser(tree, tree[0], tree[n], pos[i])){
            s+=light[i];
        } else{
            s+=dark[i];
        }
    }
    return s-c;
}

ll solve(ll n, ll m, ll pos[], ll dark[], ll light[], ll tree[], ll c){
    if(c>totgain){
        return 0;
    }
    best=max(best, count(n, m, pos, dark, light, tree, c));
    ll newposr[m+5];
    for(ll i=0; i<m; i++){
        newposr[i]=pos[i]+1;
    }
    solve(n, m, newposr, dark, light, tree, c+1);
    ll newposl[m+5];
    for(ll i=0; i<m; i++){
        newposl[i]=pos[i]-1;
    }
    solve(n, m, newposl, dark, light, tree, c+1);
}

int main(){
    ll n, m;
    in n >> m;
    ll tree[n]={0}, pos[m]={0}, dark[m]={0}, light[m]={0};
    for(ll i=0; i<n; i++){
        in tree[i];
    }
    sort(tree, tree+n);
    for(ll i=0; i<m; i++){
        in pos[i] >> dark[i] >> light[i];
        totgain+=light[i]-dark[i];
    }
    solve(n, m, pos, dark, light, tree, 0);
    out best;
}
0