結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー mint6421mint6421
提出日時 2019-08-03 22:56:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,417 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 178,176 KB
実行使用メモリ 49,520 KB
最終ジャッジ日時 2023-09-20 17:05:22
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
36,392 KB
testcase_01 AC 21 ms
36,488 KB
testcase_02 AC 23 ms
38,236 KB
testcase_03 AC 25 ms
38,232 KB
testcase_04 WA -
testcase_05 AC 23 ms
38,360 KB
testcase_06 AC 18 ms
35,404 KB
testcase_07 AC 18 ms
35,344 KB
testcase_08 AC 41 ms
49,260 KB
testcase_09 AC 44 ms
49,520 KB
testcase_10 WA -
testcase_11 AC 32 ms
44,588 KB
testcase_12 WA -
testcase_13 AC 33 ms
44,168 KB
testcase_14 AC 31 ms
40,208 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 24 ms
39,676 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;




template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int gx,gy,n,f;
  cin>>gx>>gy>>n>>f;
  WG<int> es(1000*1000);
  
  rep(i,101){
    rep(j,100){
      es[i*1000+j].PB(edge<int>(i*1000+j+1,f));
    }
    FOR(j,1,101){
      es[i*1000+j].PB(edge<int>(i*1000+j-1,f));
    }
  }
  rep(j,101){
    rep(i,100){
      es[i*1000+j].PB(edge<int>((i+1)*1000+j,f));
    }
    FOR(i,1,101){
      es[i*1000+j].PB(edge<int>((i-1)*1000+j,f));
    }
  }
  

  rep(i,n){
    int x,y,c;
    cin>>x>>y>>c;
    rep(i,100-y+1){
      rep(j,100-x+1){
        es[i*1000+j].PB(edge<int>((i+y)*1000+j+x,c));
      }
    }
  }

  vector<int> dist=dijkstra(es,0);

  cout<<dist[gy*1000+gx]<<endl;


}
0