結果

問題 No.332 数列をプレゼントに
ユーザー kenjiiiHkenjiiiH
提出日時 2016-03-16 19:33:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,383 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 58,140 KB
実行使用メモリ 11,924 KB
最終ジャッジ日時 2024-04-08 16:35:56
合計ジャッジ時間 7,739 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 6 ms
6,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 7 ms
6,676 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 WA -
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 WA -
testcase_22 AC 7 ms
6,676 KB
testcase_23 WA -
testcase_24 AC 2 ms
6,676 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>

using namespace std;

int n;
long long x;
long long a[100];
bool z[100];

const int psize = 5;
int p[] = {1009, 1013, 1019, 1021, 1031};
int dp[psize][101][1100];

bool solve() {
  long long sum = 0;
  for (int i = 0; i < n; i++)
    sum += a[i];
  if (x > sum)
    return false;
  
  memset(dp, -1, sizeof(dp));
  for (int k = 0; k < psize; k++) {
    dp[k][0][0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < p[k]; j++) {
        if (dp[k][i][j] == -1)
          continue;
        dp[k][i+1][j] = dp[k][i][j];
        dp[k][i+1][(j+a[i]) % p[k]] = i;
      }
    }
  }

  bool r = true;
  for (int k = 0; k < psize; k++)
    r &= dp[k][n][x % p[k]] != -1;

  if (r) {
    while (x > 0) {
      for (int i = 0; i < n; i++) {
        bool ck = true;
        for (int k = 0; k < psize; k++) {
          if (dp[k][i][(x-a[i]) % p[k]] == -1)
            ck = false;
        }
        if (ck) {
          x -= a[i];
          z[i] = true;
          break;
        }
      }
    }
  }
  
  return r;
}

int main(int argc, char *argv[])
{
  
  cin >> n >> x;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (solve()) {
    string ret;
    for (int i = 0; i < n; i++) {
      if (z[i])
        ret += 'o';
      else
        ret += 'x';
    }
    cout << ret << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}
0