結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー logxlogx
提出日時 2021-06-06 00:23:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,822 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 176,464 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 11:59:24
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,948 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 15 ms
6,944 KB
testcase_38 AC 16 ms
6,940 KB
testcase_39 AC 16 ms
6,940 KB
testcase_40 AC 15 ms
6,940 KB
testcase_41 AC 16 ms
6,944 KB
testcase_42 AC 15 ms
6,944 KB
testcase_43 AC 16 ms
6,944 KB
testcase_44 AC 16 ms
6,944 KB
testcase_45 AC 16 ms
6,940 KB
testcase_46 AC 15 ms
6,944 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 16 ms
6,940 KB
testcase_51 AC 16 ms
6,944 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 17 ms
6,940 KB
testcase_55 WA -
testcase_56 AC 17 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   56 |     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);
    }
    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