結果

問題 No.2366 登校
ユーザー pointNpointN
提出日時 2023-06-30 22:49:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,163 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 158,284 KB
実行使用メモリ 14,372 KB
最終ジャッジ日時 2023-09-22 05:19:01
合計ジャッジ時間 4,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

vector<int> dy = {-1,0,1,0};
vector<int> dx = {0,-1,0,1};

int main(){
  int N,M,K,T; cin >> N >> M >> K >> T;
  vector<vector<pair<int,int>>> A(N,vector<pair<int,int>>(M,{0,0}));
  rep(i,K){
    int a,b,c,d; cin >> a >> b >> c >> d; a--; b--;
    if(c!=1) A[a][b] = {c,d};
  }
  if(N+M-2<=T){
    cout << "0\n";
    return 0;
  }
  vector D(N,vector(M,vector<ll>(200,1LL<<60)));
  vector used(N,vector(M,vector<bool>(200,false)));

  ll ans = 1LL<<60;
  rep(i,200) chmin(ans,D[N-1][M-1][i]);
  priority_queue<pair<ll,vector<int>>,vector<pair<ll,vector<int>>>,greater<pair<ll,vector<int>>>> q;
  q.push({0LL,{0,0,T}});
  while(!q.empty()){
    ll d = q.top().first;
    vector<int> tv = q.top().second; q.pop();
    int y = tv[0], x = tv[1], l = tv[2];
    if(used[y][x][l]) continue;
    used[y][x][l] = true; D[y][x][l] = d;
    if(l!=0){
      rep(i,4){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(!(0<=ny&&ny<N&&0<=nx&&nx<M)) continue;
        if(D[ny][nx][l-1] <= d) continue;
        q.push({d,{ny,nx,l-1}});
      }
    }
    if(A[y][x]!=pair<int,int>({0,0})){
      if(D[y][x][min(199,l-1+A[y][x].first)] <= d+A[y][x].second) continue;
      q.push({d+A[y][x].second,{y,x,min(199,l-1+A[y][x].first)}});
    }
  }
  rep(i,200) chmin(ans,D[N-1][M-1][i]);
  if(ans>=(1LL<<60)) ans = -1;
  cout << ans << '\n';
  return 0;
};
0