結果

問題 No.1017 Reiwa Sequence
ユーザー yukudoyukudo
提出日時 2020-04-10 14:07:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,890 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 5,740 KB
最終ジャッジ日時 2023-09-16 07:06:37
合計ジャッジ時間 12,360 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,736 KB
testcase_01 AC 2 ms
4,644 KB
testcase_02 AC 3 ms
4,752 KB
testcase_03 AC 3 ms
4,656 KB
testcase_04 AC 3 ms
4,804 KB
testcase_05 AC 3 ms
4,712 KB
testcase_06 AC 3 ms
4,680 KB
testcase_07 AC 3 ms
4,736 KB
testcase_08 AC 3 ms
4,736 KB
testcase_09 AC 4 ms
4,680 KB
testcase_10 AC 5 ms
4,752 KB
testcase_11 WA -
testcase_12 AC 4 ms
4,728 KB
testcase_13 AC 5 ms
4,664 KB
testcase_14 AC 3 ms
4,732 KB
testcase_15 AC 4 ms
4,716 KB
testcase_16 AC 4 ms
4,740 KB
testcase_17 AC 4 ms
4,600 KB
testcase_18 AC 4 ms
4,608 KB
testcase_19 AC 5 ms
4,680 KB
testcase_20 AC 5 ms
4,668 KB
testcase_21 AC 4 ms
4,872 KB
testcase_22 AC 4 ms
4,740 KB
testcase_23 AC 5 ms
4,648 KB
testcase_24 AC 4 ms
4,908 KB
testcase_25 AC 4 ms
4,684 KB
testcase_26 AC 5 ms
4,740 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 5 ms
4,708 KB
testcase_34 AC 5 ms
4,740 KB
testcase_35 AC 2 ms
4,964 KB
testcase_36 AC 4 ms
4,864 KB
testcase_37 AC 5 ms
4,752 KB
testcase_38 AC 3 ms
4,752 KB
testcase_39 AC 5 ms
4,868 KB
testcase_40 AC 22 ms
4,928 KB
testcase_41 AC 22 ms
5,040 KB
testcase_42 AC 22 ms
5,008 KB
testcase_43 AC 22 ms
5,064 KB
testcase_44 AC 21 ms
4,948 KB
testcase_45 AC 22 ms
4,924 KB
testcase_46 AC 21 ms
5,056 KB
testcase_47 AC 22 ms
5,056 KB
testcase_48 AC 33 ms
5,504 KB
testcase_49 AC 31 ms
5,740 KB
testcase_50 AC 32 ms
5,468 KB
testcase_51 AC 2 ms
4,668 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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_V = 312345;
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 = 150000; 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