結果

問題 No.545 ママの大事な二人の子供
ユーザー rapurasurapurasu
提出日時 2017-07-15 13:50:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,384 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 171,060 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-07-29 16:07:37
合計ジャッジ時間 3,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 16 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL sum=0;
int n=0;
LL A[40];
LL B[40];
LL C[40];
int main(){
    cin>>n;
    REP(i,n){
        cin>>A[i]>>B[i];
    }
    vector<LL>v;
    vector<LL>v2;
    REP(i,1<<(min(16,n))){
        LL now=0;
        REP(j,min(16,n)){
            if((i>>j)&1){
               now+=A[j];
            }else{
               now-=B[j];
            }
        }
        v.push_back(now);
        v2.push_back(-now);
        //cout<<now<<endl;
    }
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());
    if(n<=16){
       LL ans=1e12;
       REP(i,v.size()){
           ans=min(ans,abs(v[i]));
       }
       cout<<ans<<endl;
    }else{
       LL ans=1e12;
       REP(i,1<<(min(16,n-16))){
          LL now=0;
          REP(j,min(16,n-16)){
              if((i>>j)&1){
                 now+=A[j+16];
              }else{
                 now-=B[j+16];
              }
          }
          LL a=v[lower_bound(v.begin(),v.end(),now)-v.begin()];
          LL b=v2[lower_bound(v2.begin(),v2.end(),-(now))-v2.begin()];
          ans=min(ans,abs(a-now));
          ans=min(ans,abs(b+now));
      }
      cout<<ans<<endl;

    }
    
    return(0);
}
0