結果
| 問題 | No.1538 引きこもりさんは引き算が得意。 |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-06-08 14:35:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,643 bytes |
| 記録 | |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 97,568 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-26 14:49:08 |
| 合計ジャッジ時間 | 2,491 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 WA * 9 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1538.cc: No.1538 引きこもりさんは引き算が得意。 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 20;
const int MAX_H = MAX_N / 2;
const int MAX_M = 59049; // = 3^10
/* typedef */
typedef long long ll;
/* global variables */
int as[MAX_N];
ll ass[MAX_M];
/* subroutines */
inline int exp3(int n) {
int e = 1;
while (n--) e *= 3;
return e;
}
inline ll t2sum(int t, int l, int r) {
ll sum = 0;
for (int i = l; i < r; i++, t /= 3) {
int d = t % 3;
if (d == 1) sum += as[i];
else if (d == 2) sum -= as[i];
}
return sum;
}
bool afind(int m, ll a) {
int l = lower_bound(ass, ass + m, a) - ass;
return (l < m && ass[l] == a);
}
/* main */
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", as + i);
int a = (n + 1) / 2, b = n - a;
int am = exp3(a), bm = exp3(b);
for (int ts = 0; ts < am; ts++) ass[ts] = t2sum(ts, 0, a);
sort(ass, ass + am);
int m = unique(ass, ass + am) - ass;
//for (int i = 0; i < m; i++) printf("%lld ", ass[i]); putchar('\n');
for (int ts = 0; ts < bm; ts++) {
ll sum = t2sum(ts, a, n);
//printf("%d -> %lld\n", ts, sum);
if (afind(m, sum + k) || afind(m, sum - k)) {
puts("Yes"); return 0;
}
}
puts("No");
return 0;
}
tnakao0123