結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー goodbatongoodbaton
提出日時 2017-06-05 22:13:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 3,832 ms
コンパイル使用メモリ 87,348 KB
実行使用メモリ 6,224 KB
最終ジャッジ日時 2023-10-22 05:38:58
合計ジャッジ時間 1,867 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
6,224 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 44 ms
6,224 KB
testcase_09 AC 44 ms
6,224 KB
testcase_10 AC 4 ms
6,168 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,532 KB
testcase_13 AC 4 ms
5,188 KB
testcase_14 AC 5 ms
5,236 KB
testcase_15 AC 4 ms
4,892 KB
testcase_16 AC 5 ms
5,932 KB
testcase_17 AC 7 ms
5,392 KB
testcase_18 AC 5 ms
5,244 KB
testcase_19 AC 5 ms
4,876 KB
testcase_20 AC 5 ms
5,900 KB
testcase_21 AC 3 ms
4,988 KB
testcase_22 AC 35 ms
6,224 KB
testcase_23 AC 35 ms
6,224 KB
testcase_24 AC 36 ms
6,224 KB
testcase_25 AC 35 ms
6,224 KB
testcase_26 AC 36 ms
6,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   scanf("%d%d%d%d",&gx,&gy,&n,&f);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%d%d%d",x+i, y+i, c+i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int dp[51][110][110];

int main(){
  int gx, gy, n, f;
  int x[51], y[51], c[51];
  
  scanf("%d%d%d%d",&gx,&gy,&n,&f);

  for(int i=0;i<n;i++){
    scanf("%d%d%d",x+i, y+i, c+i);
  }

  
  for(int i=0;i<=gx;i++){
    for(int j=0;j<=gy;j++){
      for(int k=0;k<51;k++){
        dp[k][i][j] = INF;
      }
    }
  }

  dp[0][0][0] = 0;
  
  for(int i=0;i<=gx;i++){
    for(int j=0;j<=gy;j++){

      for(int k=0;k<=n;k++){
        
        for(int r=k;r<n;r++){
          if(i+x[r] <= gx && j+y[r] <= gy)
            dp[r+1][i+x[r]][j+y[r]] = min(dp[r+1][i+x[r]][j+y[r]],
                                          dp[k][i][j] + c[r]);
        }

        if(i+1 <= gx)
          dp[k][i+1][j] = min(dp[k][i+1][j],dp[k][i][j] + f);
        
        if(j+1 <= gy)
          dp[k][i][j+1] = min(dp[k][i][j+1],dp[k][i][j] + f);
      }
      
    }
  }

  int ans = INF;
  
  for(int i=0;i<=n;i++){
    ans = min(ans,dp[i][gx][gy]);
  }

  printf("%d\n",ans);
  
  return 0;
}
0