結果

問題 No.5 数字のブロック
ユーザー hadrori
提出日時 2015-07-26 20:45:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 423 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 157,484 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 23:02:30
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void input()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d%d", &l, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:15:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     rep(i,n) scanf("%d", w+i);
      |              ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repi(i,0,n)

int l, n, w[10010], dp[10010];

int solve() {
    rep(i,n) for (int j = l; j >= w[i]; j--) dp[j] = max(dp[j],dp[j-w[i]]+1);
    return dp[l];
}

void input() {
    scanf("%d%d", &l, &n);
    rep(i,n) scanf("%d", w+i);
}

int main() {
    input();
    printf("%d\n", solve());
    return 0;
}
0