結果

問題 No.2366 登校
ユーザー logxlogx
提出日時 2021-06-29 20:51:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,625 bytes
コンパイル時間 2,753 ms
コンパイル使用メモリ 218,024 KB
実行使用メモリ 19,784 KB
最終ジャッジ日時 2023-09-22 05:08:16
合計ジャッジ時間 5,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 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,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 108 ms
7,480 KB
testcase_13 AC 99 ms
7,480 KB
testcase_14 AC 101 ms
7,576 KB
testcase_15 AC 110 ms
7,576 KB
testcase_16 AC 105 ms
7,484 KB
testcase_17 AC 106 ms
7,500 KB
testcase_18 AC 105 ms
7,440 KB
testcase_19 AC 108 ms
7,548 KB
testcase_20 AC 104 ms
7,440 KB
testcase_21 AC 101 ms
7,440 KB
testcase_22 AC 86 ms
7,560 KB
testcase_23 AC 74 ms
19,644 KB
testcase_24 AC 75 ms
19,644 KB
testcase_25 AC 389 ms
19,688 KB
testcase_26 AC 391 ms
19,784 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:102:45: 警告: narrowing conversion of ‘nk’ from ‘ll’ {aka ‘long long int’} to ‘int’ [-Wnarrowing]
  102 |             q.push({dp[i][j][nk+n+m],{{i,j},nk}});
      |                                             ^~

ソースコード

diff #

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}



int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/
    
    int n,m,K,t;
    cin >> n >> m >> K >> t;
    vector<vector<pair<ll,ll>>> magic(n,vector<pair<ll,ll>>(m));
    while(K--){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        magic[a-1][b-1]={c,d};
    }
    //dp[i][j][k+n+m]=(i,j)に時刻kにいる時の疲労度の最小値
    //|k|<=n+m を考えれば良い
    vector dp(n,vector(m,vector<ll>(2*(n+m)+1)));
    rep(i,n)rep(j,m)rep2(k,-(n+m),n+m+1){
        dp[i][j][k+n+m]=inf;
    }
    dp[0][0][0+n+m]=0;
    
    using P=pair<ll,pair<pair<int,int>,int>>;//{疲労度,{{場所},時刻}}
    priority_queue<P,vector<P>,greater<P>> q;
    q.push({0,{{0,0},0}});
    while(!q.empty()){
        auto [tir,p]=q.top();q.pop();
        auto [place,k]=p;
        auto [i,j]=place;
        if(dp[i][j][k+n+m] < tir)continue;
        //前後左右への移動
        rep(ind,4){
            int ni=i+dx[ind];
            int nj=j+dy[ind];
            if(valid(ni,nj,n,m) && k<n+m && chmin(dp[ni][nj][k+1+n+m],dp[i][j][k+n+m])){
                q.push({dp[ni][nj][k+1+n+m],{{ni,nj},k+1}});
            }
        }
        //時間を巻き戻す移動 戻る先が-(n+m)より小さければ-(n+m)とする
        auto [c,d]=magic[i][j];
        if(c==0)continue;
        ll nk=max(-(ll)(n+m),k-c+1);
        if(chmin(dp[i][j][nk+n+m],dp[i][j][k+n+m]+d)){
            q.push({dp[i][j][nk+n+m],{{i,j},nk}});
        }
    }
    ll ans=inf;
    rep2(k,-(n+m),t+1){
        chmin(ans,dp[n-1][m-1][k+n+m]);
    }
    if(ans==(ll)inf)ans=-1;
    cout << ans << newl;
}
0