結果
| 問題 |
No.1538 引きこもりさんは引き算が得意。
|
| コンテスト | |
| ユーザー |
logx
|
| 提出日時 | 2021-06-06 00:26:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,909 bytes |
| コンパイル時間 | 2,172 ms |
| コンパイル使用メモリ | 177,820 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-14 05:19:10 |
| 合計ジャッジ時間 | 4,229 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:59:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
59 | for(auto [i,j]:idx){
| ^
ソースコード
#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;
}
logx