結果
問題 | No.1323 うしらずSwap |
ユーザー |
![]() |
提出日時 | 2020-12-20 00:33:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,894 bytes |
コンパイル時間 | 2,721 ms |
コンパイル使用メモリ | 235,236 KB |
実行使用メモリ | 322,900 KB |
最終ジャッジ日時 | 2023-10-21 09:55:02 |
合計ジャッジ時間 | 19,757 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 1 ms
4,348 KB |
testcase_05 | AC | 1 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,348 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | WA | - |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 439 ms
322,612 KB |
testcase_17 | AC | 866 ms
322,316 KB |
testcase_18 | AC | 438 ms
322,900 KB |
testcase_19 | AC | 845 ms
322,344 KB |
testcase_20 | AC | 436 ms
322,612 KB |
testcase_21 | AC | 432 ms
322,336 KB |
testcase_22 | AC | 845 ms
322,612 KB |
testcase_23 | AC | 450 ms
322,200 KB |
testcase_24 | AC | 871 ms
322,404 KB |
testcase_25 | AC | 442 ms
322,200 KB |
testcase_26 | AC | 419 ms
322,696 KB |
testcase_27 | AC | 433 ms
322,752 KB |
testcase_28 | AC | 504 ms
322,488 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 193 ms
19,720 KB |
testcase_34 | AC | 177 ms
19,720 KB |
testcase_35 | AC | 173 ms
19,720 KB |
testcase_36 | AC | 168 ms
19,984 KB |
testcase_37 | AC | 166 ms
20,188 KB |
testcase_38 | AC | 157 ms
19,720 KB |
testcase_39 | AC | 156 ms
19,720 KB |
testcase_40 | AC | 168 ms
19,720 KB |
testcase_41 | AC | 167 ms
19,984 KB |
testcase_42 | AC | 146 ms
19,720 KB |
testcase_43 | AC | 213 ms
166,044 KB |
testcase_44 | AC | 254 ms
192,228 KB |
testcase_45 | AC | 379 ms
235,868 KB |
testcase_46 | AC | 358 ms
192,296 KB |
testcase_47 | AC | 274 ms
192,536 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | AC | 3 ms
4,420 KB |
testcase_60 | AC | 3 ms
4,348 KB |
testcase_61 | WA | - |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/mincostflow> using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int H,W; vector<string> S; vector<int> dy = {0,0,1,-1},dx = {1,-1,0,0}; vector<vector<int>> get(int r,int c){ queue<pair<int,int>> Q; vector<vector<int>> dis(H,vector<int>(W,Inf)); dis[r][c] = 0; Q.emplace(r,c); while(Q.size()>0){ int y = Q.front().first,x = Q.front().second; Q.pop(); rep(i,4){ int yy = y+dy[i],xx = x+dx[i]; if(yy<0||yy>=H||xx<0||xx>=W)continue; if(S[yy][xx]=='#')continue; if(dis[yy][xx]!=Inf)continue; dis[yy][xx] = dis[y][x]+1; Q.emplace(yy,xx); } } return dis; } int main(){ cin>>H>>W; S.resize(H); int r0,c0,r1,c1; cin>>r0>>c0>>r1>>c1; r0--,c0--,r1--,c1--; rep(i,H){ cin>>S[i]; } auto d0 = get(r0,c0),d1 = get(r1,c1); if(d0[r1][c1]==Inf)cout<<-1<<endl; else{ int D = d0[r1][c1]; int cnt = 0; rep(i,H){ rep(j,W){ if(d0[i][j] + d1[i][j]==D)cnt++; } } int ans = Inf; if(cnt>D+1){ cout<<2*D<<endl; return 0; } else{ rep(i,H){ rep(j,W){ if(d0[i][j]==Inf)continue; if(d0[i][j]+d1[i][j]==D)continue; rep(k,4){ int ii = i+dy[k],jj = j+dx[k]; if(d0[ii][jj]+d1[ii][jj]==D && d0[ii][jj]!=0 && d1[ii][jj]!=0){ ans = 2*D+2;//cout<<2*D+2<<endl; } } } } } mcf_graph<int,int> G(2*H*W); rep(i,H){ rep(j,W){ if(S[i][j]=='#')continue; G.add_edge(2*(i*W+j),2*(i*W+j)+1,1,0); rep(k,4){ int ii = i,jj = j; ii += dy[k],jj += dx[k]; if(S[ii][jj]=='#')continue; G.add_edge(2*(i*W+j)+1,2*(ii*W+jj),1,1); } } } auto ret = G.flow(2*(r0*W+c0)+1,2*(r1*W+c1),2); if(ret.first>=2)ans = min(ans,ret.second); if(ans!=Inf)cout<<ans<<endl; else cout<<-1<<endl; } return 0; }