結果
| 問題 | No.340 雪の足跡 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-06-27 21:31:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,194 bytes |
| コンパイル時間 | 406 ms |
| コンパイル使用メモリ | 56,192 KB |
| 最終ジャッジ日時 | 2024-11-14 19:45:38 |
| 合計ジャッジ時間 | 3,171 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:25:31: error: 'abs' was not declared in this scope
25 | int k=abs(y-x);
| ^~~
ソースコード
#include <map>
#include <queue>
#include <cstdio>
using namespace std;
typedef pair<int,int> coor;
typedef struct{
int x;
int y;
}dir;
const dir D[]={
{0,-1},{0,1},{-1,0},{1,0}
};
int main(){
int W,H,N;
scanf("%d%d%d",&W,&H,&N);
vector<vector<int> >M(H*2-1);
for(auto &e:M)e.resize(W*2-1);
for(;N--;){
int n,x,y;
scanf("%d%d",&n,&x);
for(int i=0;i<n;i++,x=y){
scanf("%d",&y);
int coorx=x%W*2,coory=x/W*2;
int k=abs(y-x);
if(k<W){
if(y-x>0)for(int i=0;i<k;i++)M[coory][coorx+i*2+1]=1;
else for(int i=0;i<k;i++)M[coory][coorx-i*2-1]=1;
}else{
k/=W;
if(y-x>0)for(int i=0;i<k;i++)M[coory+i*2+1][coorx]=1;
else for(int i=0;i<k;i++)M[coory-i*2-1][coorx]=1;
}
}
}
map<coor,int> m={{{0,0},0}};
queue<coor> q;
for(q.push({0,0});!q.empty();){
coor cur=q.front();q.pop();
if(cur==make_pair(W*2-2,H*2-2))return !printf("%d\n",m[cur]);
for(auto &d:D){
if(0<=cur.first+d.x&&cur.first+d.x<W*2-1 && 0<=cur.second+d.y&&cur.second+d.y<H*2-1 && M[cur.second+d.y][cur.first+d.x]){
coor nxt={cur.first+d.x*2,cur.second+d.y*2};
if(m.find(nxt)==m.end()){
q.push(nxt);
m[nxt]=m[cur]+1;
}
}
}
}
puts("Odekakedekinai..");
}