結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
小指が強い人
|
| 提出日時 | 2016-06-03 03:05:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,271 bytes |
| コンパイル時間 | 2,095 ms |
| コンパイル使用メモリ | 179,524 KB |
| 実行使用メモリ | 19,152 KB |
| 最終ジャッジ日時 | 2024-10-08 06:08:09 |
| 合計ジャッジ時間 | 9,691 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 WA * 1 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
void write(long double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}
int h,w,n;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int res[1000][1000]={0};
bool b[1000][1000][4]={0};
int xh[1000][1000]={0};
int yh[1000][1000]={0};
typedef pair<int,int> Vec;
Vec sp(int num){
int x=num%w;
int y=num/w;
Vec p;
p.first=x;p.second=h-y-1;
return p;
}
int main(void)
{
cin>>h>>w>>n;
rep(i,h)rep(j,w)res[i][j]=-1;
rep(i,n){
int m=read<int>();
Vec bef=sp(read<int>());
rep(j,m){
Vec p=sp(read<int>());
if(p.second==bef.second){
int x1=p.first;
int x2=bef.first;
if(x1>x2)swap(x1,x2);
xh[p.second][x1]=max(xh[p.second][x1],x2);
}
else{
int y1=p.second;
int y2=bef.second;
if(y1>y2)swap(y1,y2);
yh[p.first][y1]=max(yh[p.second][y1],y2);
}
bef=p;
}
}
rep(i,h){
int j=0;
while(j<w){
if(xh[i][j]==0){
j++;
continue;
}
int p=xh[i][j];
int sj=j;
while(j<w&&j<=p){
p=max(p,xh[i][j]);
b[i][j][0]=b[i][j][2]=true;
//cout<<j;
j++;
}
//cout<<endl;
b[i][sj][2]=false;
b[i][j-1][0]=false;
}
}
//cout<<endl;
rep(i,w){
int j=0;
while(j<h){
if(yh[i][j]==0){
j++;
continue;
}
int p=yh[i][j];
int sj=j;
while(j<h&&j<=p){
p=max(p,yh[i][j]);
//cout<<j;
b[j][i][1]=b[j][i][3]=true;
j++;
}
//cout<<endl;
b[sj][i][3]=false;
b[j-1][i][1]=false;
}
}
int sx=0,sy=h-1;
queue<Vec> q;
q.push(Vec(sx,sy));
res[sy][sx]=0;
while(!q.empty()){
Vec top=q.front();
int x=top.first;
int y=top.second;
q.pop();
rep(i,4){
if(!b[y][x][i])continue;
int cx=x+dx[i];
int cy=y+dy[i];
if(res[cy][cx]>-1)continue;
res[cy][cx]=res[y][x]+1;
q.push(Vec(cx,cy));
}
}
if(res[0][w-1]!=-1)
write(res[0][w-1]);
else
write("Odekakedekinai..");
return 0;
}
小指が強い人