結果

問題 No.10 +か×か
ユーザー alpha_virginisalpha_virginis
提出日時 2016-11-14 00:52:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 2,976 ms
コンパイル使用メモリ 163,660 KB
実行使用メモリ 41,828 KB
最終ジャッジ日時 2023-08-21 06:21:11
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,824 KB
testcase_01 AC 4 ms
5,108 KB
testcase_02 AC 4 ms
5,064 KB
testcase_03 AC 53 ms
41,704 KB
testcase_04 AC 53 ms
41,708 KB
testcase_05 AC 52 ms
41,700 KB
testcase_06 AC 53 ms
41,780 KB
testcase_07 AC 50 ms
41,828 KB
testcase_08 AC 27 ms
22,960 KB
testcase_09 AC 22 ms
19,148 KB
testcase_10 AC 8 ms
8,108 KB
testcase_11 AC 7 ms
7,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int n;
int total;
int xs[64];
uint64_t prev[64][100100];

int main() {
  scanf("%d", &n);
  scanf("%d", &total);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &xs[i]);
  }
 
  prev[0][xs[0]] = '!';
  for(int i = 1; i < n; ++i) {
    for(int j = 0; j < 100100; ++j) {
      int x1 = j + xs[i];
      int x2 = j * xs[i];
      uint64_t y1 = (prev[i-1][j] << 1) | 1ULL;
      uint64_t y2 = (prev[i-1][j] << 1);
      if( x1 < 100100 ) {
        prev[i][x1] = std::max(prev[i][x1], y1);
      }
      if( x2 < 100100 ) {
        prev[i][x2] = std::max(prev[i][x2], y2);
      }
    }
  }
  for(int i = n-1-1; i >= 0; --i) {
    putchar( (prev[n-1][total] & (1ULL << i)) ? '+' : '*' );
  }
  putchar('\n');

  return 0;
}
0