結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2017-12-18 13:43:32 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 2,000 ms | 
| コード長 | 940 bytes | 
| コンパイル時間 | 670 ms | 
| コンパイル使用メモリ | 83,248 KB | 
| 実行使用メモリ | 5,632 KB | 
| 最終ジャッジ日時 | 2024-12-15 23:47:59 | 
| 合計ジャッジ時間 | 1,704 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:47:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |   for (int i = 0; i < n; i++) scanf("%d", &as[i]);
      |                               ~~~~~^~~~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 617.cc: No.617 Nafmo、買い出しに行く - yukicoder
 */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;
/* constant */
const int MAX_N = 20;
const int MAX_K = 2000000;
/* typedef */
/* global variables */
int as[MAX_N];
bool dp[MAX_K + 1];
/* subroutines */
/* main */
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &as[i]);
  dp[0] = true;
  for (int i = 0; i < n; i++) {
    int &ai = as[i];
    for (int j = k - ai; j >= 0; j--) dp[j + ai] |= dp[j];
  }
  for (int j = k; j >= 0; j--)
    if (dp[j]) {
      printf("%d\n", j);
      break;
    }
  return 0;
}
            
            
            
        