結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー logxlogx
提出日時 2021-06-06 00:26:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,909 bytes
コンパイル時間 4,818 ms
コンパイル使用メモリ 174,852 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-08-20 22:31:00
合計ジャッジ時間 6,655 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,388 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 18 ms
4,384 KB
testcase_38 AC 19 ms
4,464 KB
testcase_39 AC 21 ms
4,380 KB
testcase_40 AC 19 ms
4,384 KB
testcase_41 AC 19 ms
4,384 KB
testcase_42 AC 19 ms
4,484 KB
testcase_43 AC 20 ms
4,384 KB
testcase_44 AC 19 ms
4,392 KB
testcase_45 AC 19 ms
4,380 KB
testcase_46 AC 18 ms
4,380 KB
testcase_47 AC 10 ms
4,384 KB
testcase_48 AC 25 ms
4,384 KB
testcase_49 AC 20 ms
4,464 KB
testcase_50 AC 19 ms
4,384 KB
testcase_51 AC 25 ms
4,380 KB
testcase_52 AC 25 ms
4,400 KB
testcase_53 AC 25 ms
4,484 KB
testcase_54 AC 25 ms
4,420 KB
testcase_55 AC 25 ms
4,468 KB
testcase_56 AC 25 ms
4,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:59:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   59 |     for(auto [i,j]:idx){
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int pow3(int x){
    int res=1;
    while(x--)res*=3;
    return res;
}

//作れる値:+も-も1つ以上含まれる or ただ1つの+からなる

//s:+も-も含む t:+のみ(1つ以上) u:-のみ(1つ以上)
void solve(vector<long long> a,vector<long long> &s,vector<long long> &t,vector<long long> &u){
    rep(i,pow3(a.size())){
        int j=i;
        long long now=0;
        int cntp=0,cntm=0;
        rep(k,a.size()){
            if(j%3==1)now+=a[k],cntp++;
            else if(j%3==2)now-=a[k],cntm++;
            j/=3;
        }
        if(cntp && cntm)s.emplace_back(now);
        else if(cntp)t.emplace_back(now);
        else if(cntm)u.emplace_back(now);
    }
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    sort(u.begin(),u.end());
    return;
}

const pair<int,int> idx[]={{0,0},{0,1},{0,2},{0,3},{1,0},{1,2},{2,0},{2,1},{3,0}};

int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/
    
    int n;
    long long k;
    cin >> n >> k;
    assert(1<=n && n<=20);
    assert(-(long long)1e9<=k && k<=(long long)1e9);

    vector<long long> a(n/2),b(n-n/2);
    rep(i,n/2)cin >> a[i],assert(-(long long)1e9<=a[i] && a[i]<=(long long)1e9);
    rep(i,n-n/2)cin >> b[i],assert(-(long long)1e9<=b[i] && b[i]<=(long long)1e9);
    vector<long long> res1[4],res2[4];
    solve(a,res1[0],res1[1],res1[2]);
    solve(b,res2[0],res2[1],res2[2]);

    res1[3]={0};
    res2[3]={0};

    rep(i,4)res2[i].emplace_back(1e18);
    bool ok=false;
    for(auto [i,j]:idx){
        for(auto x:res1[i]){
            if(*lower_bound(res2[j].begin(),res2[j].end(),k-x) == k-x)ok=true;
        }
    }
    for(auto x:a)if(x==k)ok=true;
    for(auto x:b)if(x==k)ok=true;
    cout << (ok ? "Yes" : "No") << endl;
}
0