結果

問題 No.1017 Reiwa Sequence
ユーザー tnakao0123tnakao0123
提出日時 2020-04-05 02:13:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 585 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 95,992 KB
実行使用メモリ 69,208 KB
最終ジャッジ日時 2023-09-16 06:24:05
合計ジャッジ時間 20,790 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 59 ms
13,756 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 564 ms
68,972 KB
testcase_13 AC 559 ms
68,948 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 56 ms
13,564 KB
testcase_20 AC 56 ms
13,736 KB
testcase_21 AC 56 ms
13,684 KB
testcase_22 AC 56 ms
13,632 KB
testcase_23 AC 56 ms
13,748 KB
testcase_24 AC 55 ms
13,628 KB
testcase_25 AC 55 ms
13,572 KB
testcase_26 AC 54 ms
13,684 KB
testcase_27 AC 55 ms
13,700 KB
testcase_28 AC 54 ms
13,756 KB
testcase_29 AC 54 ms
13,700 KB
testcase_30 AC 53 ms
13,748 KB
testcase_31 AC 55 ms
13,736 KB
testcase_32 AC 56 ms
13,688 KB
testcase_33 AC 55 ms
13,752 KB
testcase_34 AC 56 ms
13,676 KB
testcase_35 AC 53 ms
13,700 KB
testcase_36 AC 57 ms
13,648 KB
testcase_37 AC 55 ms
13,692 KB
testcase_38 AC 54 ms
13,820 KB
testcase_39 AC 55 ms
13,648 KB
testcase_40 AC 556 ms
68,996 KB
testcase_41 AC 553 ms
68,992 KB
testcase_42 AC 552 ms
69,112 KB
testcase_43 AC 555 ms
69,208 KB
testcase_44 AC 585 ms
69,080 KB
testcase_45 AC 553 ms
69,060 KB
testcase_46 AC 549 ms
69,004 KB
testcase_47 AC 553 ms
69,040 KB
testcase_48 AC 558 ms
69,204 KB
testcase_49 AC 552 ms
69,124 KB
testcase_50 AC 513 ms
69,112 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 55 ms
13,696 KB
testcase_53 AC 54 ms
13,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1017.cc:  No.1017 Reiwa Sequence - 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_M = 22;
const int MBITS = 1 << MAX_M;

/* typedef */

typedef long long ll;
typedef pair<ll,int> pli;

/* global variables */

int as[MAX_M];
pli ps[MBITS];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int m = min(n, MAX_M);
  for (int i = 0; i < m; i++) scanf("%d", as + i);

  int mbits = 1 << m;
  for (int bits = 1, msb = 1, bi = 0; bits < mbits; bits++) {
    if ((msb << 1) <= bits) msb <<= 1, bi++;
    ps[bits].first = ps[bits ^ msb].first + as[bi];
    ps[bits].second = bits;
  }
  sort(ps, ps + mbits);

  for (int i = 0; i + 1 < mbits; i++)
    if (ps[i].first == ps[i + 1].first) {
      int bits0 = ps[i].second, bits1 = ps[i + 1].second;
      int msk = bits0 & bits1;
      bits0 ^= msk, bits1 ^= msk;

      puts("Yes");
      for (int j = 0, bj = 1; j < m; j++, bj <<= 1) {
	if (j) putchar(' ');
	int aj = 0;
	if (bits0 & bj) aj = as[j];
	else if (bits1 & bj) aj = -as[j];
	printf("%d", aj);
      }
      for (int j = m; j < n; j++) printf(" 0");
      putchar('\n');
      return 0;
    }

  puts("No");
  return 0;
}
0