結果
問題 | No.1283 Extra Fee |
ユーザー | 👑 kmjp |
提出日時 | 2020-11-06 22:07:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 1,618 bytes |
コンパイル時間 | 1,931 ms |
コンパイル使用メモリ | 209,348 KB |
実行使用メモリ | 10,196 KB |
最終ジャッジ日時 | 2024-04-27 23:17:20 |
合計ジャッジ時間 | 4,722 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 8 ms
8,136 KB |
testcase_12 | AC | 9 ms
6,944 KB |
testcase_13 | AC | 6 ms
6,944 KB |
testcase_14 | AC | 22 ms
7,396 KB |
testcase_15 | AC | 33 ms
7,976 KB |
testcase_16 | AC | 8 ms
7,796 KB |
testcase_17 | AC | 84 ms
10,008 KB |
testcase_18 | AC | 112 ms
8,116 KB |
testcase_19 | AC | 121 ms
8,400 KB |
testcase_20 | AC | 114 ms
8,180 KB |
testcase_21 | AC | 124 ms
8,404 KB |
testcase_22 | AC | 105 ms
8,060 KB |
testcase_23 | AC | 100 ms
8,348 KB |
testcase_24 | AC | 111 ms
8,308 KB |
testcase_25 | AC | 121 ms
8,432 KB |
testcase_26 | AC | 123 ms
8,428 KB |
testcase_27 | AC | 126 ms
8,432 KB |
testcase_28 | AC | 125 ms
8,388 KB |
testcase_29 | AC | 93 ms
10,196 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; int C[500][500]; ll D[500][500][2]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; FOR(i,M) { cin>>y>>x>>r; C[y-1][x-1]=r; } FOR(y,N) FOR(x,N) FOR(i,2) D[y][x][i]=1LL<<60; D[0][0][0]=0; priority_queue<pair<ll,int>> Q; Q.push({0,0}); while(Q.size()) { ll co=-Q.top().first; int cy=Q.top().second/500%500; int cx=Q.top().second%500; int turn=Q.top().second/500/500; Q.pop(); if(D[cy][cx][turn]!=co) continue; if(cy==N-1&&cx==N-1) { cout<<co<<endl; return; } co++; int d[]={1,0,-1,0}; FOR(i,4) { int ty=cy+d[i]; int tx=cx+d[i^1]; if(tx<0||ty<0||tx>=N||ty>=N) continue; if(D[ty][tx][turn]>co+C[ty][tx]) { D[ty][tx][turn]=co+C[ty][tx]; Q.push({-D[ty][tx][turn],turn*500*500+ty*500+tx}); } if(turn==0&&D[ty][tx][1]>co) { D[ty][tx][1]=co; Q.push({-D[ty][tx][1],1*500*500+ty*500+tx}); } } } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }