結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー どららどらら
提出日時 2017-03-24 23:05:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,652 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 177,524 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 02:57:06
合計ジャッジ時間 2,905 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define INF 1000000000

struct ST {
  int x, y, c;
};

int main(){
  int Gx, Gy, N, F;
  cin >> Gx >> Gy >> N >> F;

  vector<ST> v;
  rep(i,N){
    int x, y, c;
    cin >> x >> y >> c;
    v.push_back((ST){x,y,c});
  }

  vector<vector<int>> cost(Gy+1, vector<int>(Gx+1,INF));
  cost[0][0] = 0;

  rep(y,cost.size()){
    rep(x,cost[y].size()){
      if(y+1<cost.size()){
        cost[y+1][x] = min(cost[y+1][x], cost[y][x]+F);
      }
      if(x+1<cost[y].size()){
        cost[y][x+1] = min(cost[y][x+1], cost[y][x]+F);
      }
    }
  }

  rep(i,N){
    vector<vector<int>> new_cost = cost;
    
    rep(y,cost.size()){
      rep(x,cost[y].size()){
        if(cost[y][x] != INF){
          new_cost[y][x] = min(new_cost[y][x], cost[y][x]);
          if(x+v[i].x<cost[y].size() && y+v[i].y<cost.size()){
            new_cost[y+v[i].y][x+v[i].x] = min(new_cost[y+v[i].y][x+v[i].x],
                                           cost[y][x] + v[i].c);
          }
        }
      }
    }

    rep(y,cost.size()){
      rep(x,cost[y].size()){
        if(y+1<cost.size()){
          new_cost[y+1][x] = min(new_cost[y+1][x], new_cost[y][x]+F);
        }
        if(x+1<cost[y].size()){
          new_cost[y][x+1] = min(new_cost[y][x+1], new_cost[y][x]+F);
        }
      }
    }

    cost = new_cost;
  }


  cout << cost[Gy][Gx] << endl;
  
  return 0;
}
0