結果
| 問題 | No.3723 Climb or Detour |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-19 13:41:55 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 1,553 bytes |
| 記録 | |
| コンパイル時間 | 2,195 ms |
| コンパイル使用メモリ | 353,028 KB |
| 実行使用メモリ | 10,072 KB |
| 最終ジャッジ日時 | 2026-09-19 13:42:06 |
| 合計ジャッジ時間 | 9,477 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 RE * 12 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,K;
cin>>N>>K;
ll SY,SX,GY,GX;
cin>>SY>>SX>>GY>>GX;
SY--;SX--;GY--;GX--;
bool ys=0,xs=0;
if(SY>GY){
SY=N-SY-1;
GY=N-GY-1;
ys=1;
}
if(SX>GX){
SX=N-SX-1;
GX=N-GX-1;
xs=1;
}
ll d=(GX-SX)+(GY-SY);
if(K<d||d>2*K){
cout<<-1<<"\n";
}
ll e=K-d;
vector<string> S(N,string(N,'.'));
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
ll r=abs(SY-i)+abs(SX-j);
r=min(r,e);
if(r%2==1)S[i][j]='#';
}
}
if(S[GY][GX]=='#'){
cout<<-1<<"\n";
return 0;
}
vector<vector<int>> D(N,vector<int>(N,1e9));
D[SY][SX]=0;
priority_queue<array<ll,3>,vector<array<ll,3>>,greater<array<ll,3>>> Q;
Q.push({0,SY,SX});
vector<int> u={0,1,0,-1,0};
while(!Q.empty()){
auto [c,y,x]=Q.top();
Q.pop();
if(D[y][x]!=c)continue;
for(int dd=0;dd<4;dd++){
int ny=y+u[dd];
int nx=x+u[dd+1];
if(ny<0||nx<0||ny>=N||nx>=N)continue;
ll nc=c+1+(S[ny][nx]!=S[y][x]);
if(D[ny][nx]<=nc)continue;
D[ny][nx]=nc;
Q.push({nc,ny,nx});
}
}
assert(D[GY][GX]==K);
if(ys)reverse(S.begin(),S.end());
if(xs){
for(int i=0;i<N;i++)reverse(S[i].begin(),S[i].end());
}
for(int i=0;i<N;i++)cout<<S[i]<<"\n";
}