結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー どららどらら
提出日時 2017-03-24 22:55:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,507 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 180,252 KB
実行使用メモリ 814,576 KB
最終ジャッジ日時 2023-09-20 02:03:05
合計ジャッジ時間 5,839 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 10000000

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(i,N){
    vector<vector<int>> new_cost = cost;
    
    rep(y,cost.size()){
      rep(x,cost[y].size()){
        if(cost[y][x] != INF){
          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);
          }
        }
      }
    }

    queue<ST> que;
    que.push((ST){0,0,0});
    while(!que.empty()){
      ST st = que.front(); que.pop();
      if(st.y+1<cost.size()){
        new_cost[st.y+1][st.x] = min(new_cost[st.y+1][st.x], new_cost[st.y][st.x]+F);
        que.push((ST){st.x,st.y+1,0});
      }
      if(st.x+1<cost[st.y].size()){
        new_cost[st.y][st.x+1] = min(new_cost[st.y][st.x+1], new_cost[st.y][st.x]+F);
        que.push((ST){st.x+1,st.y,0});
      }
    }
    
    cost = new_cost;
  }

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

0