結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー Kiona1018Kiona1018
提出日時 2019-09-15 20:04:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 167,476 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2023-09-21 04:12:59
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 6 ms
7,840 KB
testcase_09 AC 5 ms
7,564 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,464 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 5 ms
7,844 KB
testcase_23 AC 5 ms
7,632 KB
testcase_24 AC 5 ms
7,588 KB
testcase_25 AC 5 ms
7,636 KB
testcase_26 AC 5 ms
7,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
struct crystal{int x, y, c;};

int main()
{
    int gx, gy, n, f;
    cin >> gx >> gy >> n >> f;

    vector<crystal> cry;
    rep(i, 0, n)
    {
        crystal c;
        cin >> c.x >> c.y >> c.c;
        
        cry.push_back(c);
        // cout << "***" << endl;
    }
    // cout <<"*LJ:J" << endl;

    int dp[n+1][2*gx + 1][2*gy + 1];
    rep(k, 0, n+1) rep(i, 0, gx + 1) rep(j, 0, gy + 1)
        dp[k][i][j] = (i + j) * f;
    // cout << n << ' ' << gx << ' ' << gy << ' ' << f << endl;
    // cout << dp[n][gx][gy] << endl;

    // cout << "***********" << endl;
    rep(k, 0, n)
    {
        crystal c = cry[k];
        rep(i, 0, gx + 1)
            rep(j, 0, gy + 1)
            {
                dp[k+1][i][j] = min(
                    dp[k+1][i][j],
                    dp[k][i][j]
                );
                if (i+c.x <= gx and j+c.y <= gy)
                    dp[k+1][i+c.x][j+c.y] = min(
                        dp[k][i+c.x][j+c.y],
                        dp[k][i][j] + c.c
                    );
                // cout << k << ' ' << i <<' ' << j << ' ' << dp[k+1][i][j] << endl;
            }
    }

    cout << dp[n][gx][gy] << endl;
    return 0;
}
0