結果

問題 No.10 +か×か
コンテスト
ユーザー alpha_virginis
提出日時 2016-11-14 00:52:33
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 744 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,251 ms
コンパイル使用メモリ 162,196 KB
実行使用メモリ 42,112 KB
最終ジャッジ日時 2025-12-06 14:35:37
合計ジャッジ時間 2,305 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:10:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |   scanf("%d", &total);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%d", &xs[i]);
      |     ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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