結果

問題 No.2366 登校
ユーザー pointNpointN
提出日時 2023-06-30 23:01:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,103 ms / 4,000 ms
コード長 2,141 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 157,816 KB
実行使用メモリ 24,892 KB
最終ジャッジ日時 2023-09-03 03:00:25
合計ジャッジ時間 10,135 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 434 ms
12,120 KB
testcase_13 AC 540 ms
12,340 KB
testcase_14 AC 504 ms
11,992 KB
testcase_15 AC 402 ms
12,636 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 384 ms
12,576 KB
testcase_18 AC 541 ms
12,768 KB
testcase_19 AC 398 ms
12,516 KB
testcase_20 AC 466 ms
12,572 KB
testcase_21 AC 554 ms
12,108 KB
testcase_22 AC 415 ms
11,936 KB
testcase_23 AC 6 ms
4,384 KB
testcase_24 AC 588 ms
24,892 KB
testcase_25 AC 1,079 ms
24,488 KB
testcase_26 AC 1,103 ms
24,556 KB
権限があれば一括ダウンロードができます

ソースコード

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>(400,1LL<<60)));
  vector used(N,vector(M,vector<bool>(400,false)));

  ll ans = 1LL<<60;
  priority_queue<pair<ll,vector<int>>,vector<pair<ll,vector<int>>>,greater<pair<ll,vector<int>>>> q;
  q.push({0LL,{0,0,T+200}});
  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(399,l-1+A[y][x].first)] <= d+A[y][x].second) continue;
      q.push({d+A[y][x].second,{y,x,min(399,l-1+A[y][x].first)}});
    }
  }
  for(int i=200;i<400;i++) chmin(ans,D[N-1][M-1][i]);
  if(ans>=(1LL<<60)) ans = -1;
  cout << ans << '\n';
  return 0;
};
0