結果

問題 No.914 Omiyage
ユーザー LayCurseLayCurse
提出日時 2019-10-25 21:37:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 2,785 ms
コンパイル使用メモリ 216,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:12:59
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int K;
int A[10];
int dp[501];
int nx[501];
int main(){
  int Lj4PdHRW, i;
  int res = -1;
  rd(N);
  rd(M);
  rd(K);
  dp[0] = 1;
  for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
    int i;
    {
      int KL2GvlyY;
      for(KL2GvlyY=(0);KL2GvlyY<(M);KL2GvlyY++){
        rd(A[KL2GvlyY]);
      }
    }
    for(i=(0);i<(K+1);i++){
      nx[i] = 0;
    }
    for(i=(0);i<(K+1);i++){
      if(dp[i]){
        int j;
        for(j=(0);j<(M);j++){
          if(i + A[j] <= K){
            nx[i + A[j]] = 1;
          }
        }
      }
    }
    for(i=(0);i<(K+1);i++){
      dp[i] = nx[i];
    }
  }
  for(i=(0);i<(K+1);i++){
    if(dp[i]){
      res = i;
    }
  }
  if(res==-1){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(K - res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191012-1

// --- original code ---
// int N, M, K, A[10];
// int dp[501], nx[501];
// {
//   int res = -1;
//   rd(N,M,K);
//   dp[0] = 1;
//   rep(N){
//     rd(A(M));
//     rep(i,K+1) nx[i] = 0;
//     rep(i,K+1) if(dp[i]) rep(j,M) if(i + A[j] <= K) nx[i + A[j]] = 1;
//     rep(i,K+1) dp[i] = nx[i];
//   }
//   rep(i,K+1) if(dp[i]) res = i;
//   wt(if[res==-1, -1, K - res]);
// }
0