結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー hiro71687khiro71687k
提出日時 2023-03-30 20:43:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,083 bytes
コンパイル時間 4,471 ms
コンパイル使用メモリ 274,664 KB
実行使用メモリ 18,016 KB
最終ジャッジ日時 2023-10-22 05:04:19
合計ジャッジ時間 7,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 27 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 52 ms
4,348 KB
testcase_38 AC 51 ms
4,348 KB
testcase_39 AC 51 ms
4,348 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 51 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 51 ms
4,348 KB
testcase_45 AC 52 ms
4,348 KB
testcase_46 AC 48 ms
4,348 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 51 ms
4,348 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 131 ms
18,016 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 128 ms
18,016 KB
testcase_55 WA -
testcase_56 AC 129 ms
18,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=1000000007;
ll inf=9999999999999999;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        if (a[i]==k)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    sort(a.begin(),a.end());
    vector<ll>thr(21,1);
    for (ll i = 1; i < 21; i++)
    {
        thr[i]=thr[i-1]*3;
    }
    if (n>10)
    {
        map<ll,ll>memo1;
        for (ll i = 0; i < 10; i++)
        {
            memo1[a[i]]=1;
        }
        ll d=n-10;
        for (ll i = 0; i < thr[10]; i++)
        {
            ll now=0;
            vector<ll>z(3,0);
            for (ll j = 0; j <10 ; j++)
            {
                ll x=i%thr[j+1];
                x/=thr[j];
                if (x==0)
                {
                    now+=a[j];
                }else if (x==1)
                {
                    now-=a[j];
                }
                z[x]+=1;
            }
            if (z[0]==0||z[1]==0)
            {
                continue;
            }
            memo1[now]+=1;
        }
        map<ll,ll>memo2;
        for (ll i = 0; i < d; i++)
        {
            memo2[a[10+i]]=1;
        }
        for (ll i = 0; i < thr[d]; i++)
        {
            ll now=0;
            vector<ll>z(3,0);
            for (ll j = 0; j <d ; j++)
            {
                ll x=i%thr[j+1];
                x/=thr[j];
                if (x==0)
                {
                    now+=a[j+10];
                }else if (x==1)
                {
                    now-=a[j+10];
                }
                z[x]+=1;
            }
            if (z[0]==0||z[1]==0)
            {
                continue;
            }
            memo2[now]+=1;
        }
        for(auto v:memo1){
            if (memo2[k+v.first]>=1||memo2[v.first-k]>=1)
            {
                cout << v.first << endl;
                cout << "Yes" << endl;
                return 0;
            }
        }
        if (memo1[k]>=1||memo2[k]>=1)
        {
            cout << "Yes" << endl;
            return 0;
        }
        cout << "No" << endl;
    }else{
        map<ll,ll>memo1;
        for (ll i = 0; i < thr[n]; i++)
        {
            ll now=0;
            vector<ll>z(3,0);
            for (ll j = 0; j <n ; j++)
            {
                ll x=i%thr[j+1];
                x/=thr[j];
                if (x==0)
                {
                    now+=a[j];
                }else if (x==1)
                {
                    now-=a[j];
                }
                z[x]+=1;
            }
            if (z[0]==0||z[1]==0)
            {
                continue;
            }
            memo1[now]+=1;
        }
        if (memo1[k]>=1)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }
    
}
0