結果

問題 No.2366 登校
ユーザー momoyuumomoyuu
提出日時 2023-10-26 11:13:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,473 ms / 4,000 ms
コード長 2,296 bytes
コンパイル時間 3,236 ms
コンパイル使用メモリ 261,580 KB
実行使用メモリ 232,052 KB
最終ジャッジ日時 2023-10-26 11:14:07
合計ジャッジ時間 29,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,800 KB
testcase_01 AC 3 ms
7,688 KB
testcase_02 AC 3 ms
7,732 KB
testcase_03 AC 6 ms
11,892 KB
testcase_04 AC 2 ms
7,688 KB
testcase_05 AC 4 ms
9,792 KB
testcase_06 AC 5 ms
11,876 KB
testcase_07 AC 5 ms
11,968 KB
testcase_08 AC 9 ms
12,048 KB
testcase_09 AC 8 ms
12,048 KB
testcase_10 AC 3 ms
7,748 KB
testcase_11 AC 4 ms
11,828 KB
testcase_12 AC 1,511 ms
129,444 KB
testcase_13 AC 1,350 ms
129,644 KB
testcase_14 AC 1,441 ms
129,488 KB
testcase_15 AC 1,471 ms
130,024 KB
testcase_16 AC 1,458 ms
129,740 KB
testcase_17 AC 1,445 ms
129,532 KB
testcase_18 AC 1,466 ms
129,884 KB
testcase_19 AC 1,486 ms
130,012 KB
testcase_20 AC 1,480 ms
129,920 KB
testcase_21 AC 1,350 ms
129,508 KB
testcase_22 AC 1,256 ms
129,292 KB
testcase_23 AC 956 ms
206,120 KB
testcase_24 AC 962 ms
206,120 KB
testcase_25 AC 3,473 ms
232,052 KB
testcase_26 AC 3,460 ms
232,052 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:28:92: warning: iteration 3000 invokes undefined behavior [-Waggressive-loop-optimizations]
   28 |     for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) for(int k = 0;k<15000;k++) memo[i][j][k] = 1e18;
      |                                                                              ~~~~~~~~~~~~~~^~~~~~
main.cpp:28:66: note: within this loop
   28 |     for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) for(int k = 0;k<15000;k++) memo[i][j][k] = 1e18;
      |                                                                 ~^~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


const int mask = 1000;
ll memo[81][81][3000];
int vis[81][81][3000];
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<char,char>>;
    priority_queue<pair<ll,dat>,vector<pair<ll,dat>>,greater<pair<ll,dat>>> que;
    que.push(make_pair(0,make_pair(0,make_pair(0,0))));
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) for(int k = 0;k<15000;k++) memo[i][j][k] = 1e18;

    ll can = 1e18;
    while(!que.empty()){
        auto now = que.top();
        que.pop();
        int ni = now.second.second.first;
        int nj = now.second.second.second;
        if(vis[ni][nj][now.second.first+7000]++) continue;
        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(nxt<=-mask) nxt = -mask;
            if(nxt>=mask) nxt = mask;
            dat will = make_pair(nxt,make_pair(nni,nnj));
            if(memo[nni][nnj][nxt+mask]<=cost) continue;
            memo[nni][nnj][nxt+mask] = cost;
            que.push(make_pair(cost,will));
        }
        if(use[ni][nj].first!=0){
            ll nxt = now.second.first + 1;
            ll cost = now.first;
            nxt -= use[ni][nj].first;
            cost += use[ni][nj].second;
            int nni = ni;
            int nnj = nj;
            dat will = make_pair(nxt,make_pair(nni,nnj));
            if(nxt<=-mask) nxt = -mask;
            if(nxt>=mask) nxt = mask;
            if(memo[ni][nj][nxt+mask]<=cost) continue;
            memo[ni][nj][nxt+mask] = cost;
            que.push(make_pair(cost,will));
        }
    }
    if(ans==1e18) ans = -1;
    cout<<ans<<endl;
}
0