結果

問題 No.1017 Reiwa Sequence
ユーザー yukudoyukudo
提出日時 2020-04-10 14:11:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,924 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 169,424 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2023-09-16 07:06:50
合計ジャッジ時間 12,972 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,456 KB
testcase_01 AC 8 ms
9,244 KB
testcase_02 AC 7 ms
9,388 KB
testcase_03 AC 15 ms
9,512 KB
testcase_04 AC 7 ms
9,468 KB
testcase_05 AC 9 ms
9,396 KB
testcase_06 AC 8 ms
9,432 KB
testcase_07 AC 7 ms
9,356 KB
testcase_08 AC 7 ms
9,544 KB
testcase_09 AC 16 ms
9,544 KB
testcase_10 AC 18 ms
9,440 KB
testcase_11 AC 16 ms
9,524 KB
testcase_12 AC 19 ms
9,328 KB
testcase_13 AC 15 ms
9,404 KB
testcase_14 AC 17 ms
9,244 KB
testcase_15 AC 18 ms
9,368 KB
testcase_16 AC 16 ms
9,252 KB
testcase_17 AC 20 ms
9,452 KB
testcase_18 AC 16 ms
9,336 KB
testcase_19 AC 29 ms
9,556 KB
testcase_20 AC 31 ms
9,264 KB
testcase_21 AC 30 ms
9,252 KB
testcase_22 AC 29 ms
9,248 KB
testcase_23 AC 29 ms
9,448 KB
testcase_24 AC 28 ms
9,548 KB
testcase_25 AC 26 ms
9,340 KB
testcase_26 AC 25 ms
9,368 KB
testcase_27 AC 27 ms
9,612 KB
testcase_28 AC 26 ms
9,472 KB
testcase_29 AC 19 ms
9,408 KB
testcase_30 AC 20 ms
9,520 KB
testcase_31 AC 22 ms
9,396 KB
testcase_32 AC 24 ms
9,548 KB
testcase_33 AC 19 ms
9,404 KB
testcase_34 AC 26 ms
9,648 KB
testcase_35 AC 7 ms
9,484 KB
testcase_36 AC 13 ms
9,452 KB
testcase_37 AC 25 ms
9,340 KB
testcase_38 AC 8 ms
9,524 KB
testcase_39 AC 26 ms
9,420 KB
testcase_40 AC 46 ms
9,772 KB
testcase_41 AC 47 ms
9,608 KB
testcase_42 AC 46 ms
9,736 KB
testcase_43 AC 47 ms
9,636 KB
testcase_44 AC 27 ms
9,628 KB
testcase_45 AC 43 ms
9,768 KB
testcase_46 AC 42 ms
9,648 KB
testcase_47 AC 40 ms
9,644 KB
testcase_48 AC 45 ms
10,272 KB
testcase_49 AC 36 ms
10,136 KB
testcase_50 AC 36 ms
10,160 KB
testcase_51 AC 6 ms
9,248 KB
testcase_52 AC 26 ms
9,392 KB
testcase_53 AC 24 ms
9,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_A = 150000;
const int MAX_V = 1500000;
int dp[MAX_V];

int main2() {
  CLR(dp, -1);

  int N = nextInt();
  vector<int> a(N);
  REP(i, N) a[i] = nextInt();

  bool yes = false;

  vector<int> s, t;

  dp[0] = 0;

  REP(i, N) {
    for (int v = MAX_V - MAX_A; v >= 0; v--) {
      if (dp[v] >= 0 && v + a[i] < MAX_V) {
        if (dp[ v + a[i] ] != -1) {
          yes = true;
          {
            int S = v + a[i];
            while (S > 0) {
              int p = dp[S];
              s.push_back(p);
              S -= a[p];
            }
          }
          {
            t.push_back(i);
            int S = v;
            while (S > 0) {
              int p = dp[S];
              t.push_back(p);
              S -= a[p];
            }
          }
          goto END;
        } else {
          dp[ v + a[i] ] = i;
        }
      }
    }
  }

  END:

  if (yes) {
    cout << "Yes" << endl;

    vector<int> ans(N);
    for (int x : s) ans[x]--;
    for (int x : t) ans[x]++;

    bool first = true;
    REP(i, N) {
      if (first) { first = false; } else printf(" ");
      printf("%d", ans[i] * a[i]);
    }
    printf("\n");

  } else {
    cout << "No" << endl;
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0