結果

問題 No.1017 Reiwa Sequence
ユーザー uenokuuenoku
提出日時 2020-04-24 13:48:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 173,280 KB
実行使用メモリ 36,452 KB
最終ジャッジ日時 2023-09-16 07:24:19
合計ジャッジ時間 21,393 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 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 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 8 ms
4,428 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 487 ms
36,184 KB
testcase_20 AC 532 ms
36,108 KB
testcase_21 AC 562 ms
36,112 KB
testcase_22 AC 533 ms
36,116 KB
testcase_23 AC 431 ms
36,240 KB
testcase_24 AC 423 ms
36,120 KB
testcase_25 AC 384 ms
36,120 KB
testcase_26 AC 322 ms
36,116 KB
testcase_27 AC 306 ms
24,668 KB
testcase_28 AC 386 ms
27,952 KB
testcase_29 AC 7 ms
4,384 KB
testcase_30 AC 12 ms
4,956 KB
testcase_31 AC 36 ms
7,452 KB
testcase_32 AC 170 ms
19,752 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 166 ms
19,728 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 191 ms
19,804 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 192 ms
19,784 KB
testcase_40 AC 545 ms
36,452 KB
testcase_41 AC 487 ms
36,188 KB
testcase_42 AC 504 ms
36,204 KB
testcase_43 AC 475 ms
36,112 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 474 ms
36,128 KB
testcase_46 AC 409 ms
36,280 KB
testcase_47 AC 321 ms
36,124 KB
testcase_48 AC 15 ms
4,380 KB
testcase_49 AC 14 ms
4,380 KB
testcase_50 AC 14 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 423 ms
35,860 KB
testcase_53 AC 76 ms
11,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

int main()
{
  int n;

  vector<lli> a(22);
  cin >> n;
  lli N = n;
  n = min(n, 22);
  rep(i, min(n, 22)) cin >> a[i];
  map<lli, lli> s;
  rep(i, 1 << n)
  {
    lli ret = 0;
    lli sum = 0;
    rep(j, n)
    {
      if ((i >> j) & 1)
      {
        sum += a[j];
      }
    }
    if (sum)
    {
      if (s.count(sum))
      {
        lli mask = i & s[sum];
        cout << "Yes" << endl;
        rep(k, N)
        {
          if (k <= 22)
          {
            if ((mask >> k) & 1)
            {
              cout << 0;
            }
            else if ((i >> k) & 1)
            {
              cout << a[k];
            }
            else if ((s[sum] >> k) & 1)
            {
              cout << -a[k];
            }
            else
            {
              cout << 0;
            }
          }
          else
          {
            cout << 0;
          }
          cout << " ";
        }
        return 0;
      }
      s[sum] = i;
    }
  }
  cout << "No" << endl;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}
0