結果

問題 No.2366 登校
ユーザー momoyuumomoyuu
提出日時 2023-10-26 11:02:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,781 bytes
コンパイル時間 3,719 ms
コンパイル使用メモリ 272,588 KB
実行使用メモリ 466,932 KB
最終ジャッジ日時 2023-10-26 11:02:17
合計ジャッジ時間 11,721 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
21,080 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 15 ms
6,864 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 273 ms
38,592 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 20 ms
7,956 KB
testcase_11 WA -
testcase_12 TLE -
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;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 

    ll ans = 1e18;
    ll n,m,k,t;
    cin>>n>>m>>k>>t;
    vector<vector<pair<ll,ll>>> use(n,vector<pair<ll,ll>>(m));
    for(int i = 0;i<k;i++){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;b--;
        use[a][b] = make_pair(c,d);
    }
    using dat = pair<ll,pair<ll,ll>>;
    priority_queue<pair<ll,dat>,vector<pair<ll,dat>>,greater<pair<ll,dat>>> que;
    map<dat,int> vis;
    map<dat,ll> memo;
    que.push(make_pair(0,make_pair(0,make_pair(0,0))));
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};

    while(!que.empty()){
        auto now = que.top();
        que.pop();
        if(vis[now.second]++) continue;
        int ni = now.second.second.first;
        int nj = now.second.second.second;
        if(ni==n-1&&nj==m-1){
            if(now.second.first>t) continue;
            ans = min(ans,now.first);
            continue;
        }
        for(int k = 0;k<4;k++){
            int nni = ni + dx[k];
            int nnj = nj + dy[k];
            if(nni<0||nnj<0||nni>=n||nnj>=m) continue;
            ll nxt = now.second.first;
            nxt++;
            ll cost = now.first;
            if(use[nni][nnj].first!=0){
                nxt++;
                nxt -= use[nni][nnj].first;
                cost += use[nni][nnj].second;
            }
            if(nxt<=-7000) nxt = -7000;
            if(nxt>=7000) nxt = 7000;
            dat will = make_pair(nxt,make_pair(nni,nnj));
            if(memo.find(will)!=memo.end()&&memo[will]<=cost) continue;
            memo[will] = cost;
            que.push(make_pair(cost,will));
        }
    }
    if(ans==1e18) ans = -1;
    cout<<ans<<endl;


        

}
0