結果
問題 | No.2366 登校 |
ユーザー | i_am_noob |
提出日時 | 2023-06-30 22:17:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 205 ms / 4,000 ms |
コード長 | 1,758 bytes |
コンパイル時間 | 2,140 ms |
コンパイル使用メモリ | 205,488 KB |
実行使用メモリ | 24,080 KB |
最終ジャッジ日時 | 2023-09-03 02:59:45 |
合計ジャッジ時間 | 4,187 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,436 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 2 ms
5,652 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 77 ms
16,852 KB |
testcase_13 | AC | 96 ms
16,808 KB |
testcase_14 | AC | 91 ms
16,740 KB |
testcase_15 | AC | 86 ms
16,896 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 73 ms
16,744 KB |
testcase_18 | AC | 99 ms
16,940 KB |
testcase_19 | AC | 68 ms
16,764 KB |
testcase_20 | AC | 63 ms
16,824 KB |
testcase_21 | AC | 97 ms
16,840 KB |
testcase_22 | AC | 70 ms
16,784 KB |
testcase_23 | AC | 1 ms
4,380 KB |
testcase_24 | AC | 154 ms
23,976 KB |
testcase_25 | AC | 189 ms
24,080 KB |
testcase_26 | AC | 205 ms
23,956 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) ((int)a.size()) const int N=85,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; int n,m,k,t,c[N][N],d[N][N]; ll dis[N][N][N*4]; bool vis[N][N][N*4]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> n >> m >> k >> t; if(t>=n+m-2){ cout << "0\n"; return 0; } for(int i=0; i<k; ++i){ int x,y; cin >> x >> y; x--,y--; cin >> c[x][y] >> d[x][y]; } for(int i=0; i<n; ++i) for(int j=0; j<m; ++j) for(int cur=0; cur<=N*2+n+m; ++cur) dis[i][j][cur]=4e18; using T=pair<ll,array<int,3>>; priority_queue<T,vector<T>,greater<T>> pq; dis[0][0][N*2+t]=0,pq.push({0,{0,0,N*2+t}}); while(!pq.empty()){ auto [_,arr]=pq.top(); pq.pop(); auto [x,y,cur]=arr; if(vis[x][y][cur]) continue; //cout << x << ' ' << y << ' ' << cur << endl; vis[x][y][cur]=1; if(cur-(n-1-x)-(m-1-y)>=N*2){ cout << dis[x][y][cur] << "\n"; return 0; } if(cur>0){ for(int i=0; i<4; ++i){ int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&nx<n&&ny>=0&&ny<m&&dis[x][y][cur]<dis[nx][ny][cur-1]){ dis[nx][ny][cur-1]=dis[x][y][cur]; pq.push({dis[nx][ny][cur-1],{nx,ny,cur-1}}); } } } if(c[x][y]>0){ int ncur=min(cur+c[x][y]-1,N*2+(n+m-1)); if(dis[x][y][cur]+d[x][y]<dis[x][y][ncur]){ dis[x][y][ncur]=dis[x][y][cur]+d[x][y]; pq.push({dis[x][y][ncur],{x,y,ncur}}); } } } cout << "-1\n"; }