結果

問題 No.10 +か×か
ユーザー alpha_virginisalpha_virginis
提出日時 2016-11-14 00:39:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,162 bytes
コンパイル時間 1,443 ms
コンパイル使用メモリ 165,068 KB
実行使用メモリ 7,764 KB
最終ジャッジ日時 2023-08-17 04:30:49
合計ジャッジ時間 2,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 8 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
4,828 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int n;
int total;
int xs[64];

char prev[64][100100];

int main() {
  scanf("%d", &n);
  scanf("%d", &total);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &xs[i]);
  }
 
  // step 2
  prev[0][xs[0]] = '!';
  for(int i = 1; i < n; ++i) {
    for(int j = 0; j < 100100; ++j) {
      if( prev[i-1][j] == '\0' ) continue;
      // printf("(i, j) = (%d, %d)\n", i, j);
      int x1 = j + xs[i];
      int x2 = j * xs[i];
      if( x1 < 100100 ) {
        // printf("(i, x1) = (%d, %d)\n", i, x1);
        prev[i][x1] = std::max(prev[i][x1], '+');
      }
      if( x2 < 100100 ) {
        // printf("(i, x2) = (%d, %d)\n", i, x2);
        prev[i][x2] = std::max(prev[i][x2], '*');
      }
    }
    // for(int j = 0; j < 32; ++j) {
    //   printf("%c", prev[i][j]);
    // }
    // printf("\n");
  }

  std::string ans;
  int x = total;
  for(int i = n - 1; i >= 1; --i) {
    // printf("#(i, x, prev[i][x]) = (%d, %d, %c)\n", i, x, prev[i][x]);
    char c = prev[i][x];
    ans += c;
    if( c == '+' ) x -= xs[i];
    if( c == '*' ) x /= xs[i];
  }
  std::reverse(ans.begin(), ans.end());

  printf("%s\n", ans.c_str());

  return 0;
}
0