結果
問題 | No.86 TVザッピング(2) |
ユーザー |
![]() |
提出日時 | 2016-02-19 06:14:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 664 ms / 5,000 ms |
コード長 | 1,482 bytes |
コンパイル時間 | 1,472 ms |
コンパイル使用メモリ | 157,084 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:59:28 |
合計ジャッジ時間 | 3,218 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++) #define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++) #define all(n) (n).begin(),(n).end() typedef long long ll; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<long long,long long> Pii; typedef vector<Pii> VPii; int dx[] = {-1,0,+1,0}; int dy[] = {0,+1,0,-1}; char a[128][128]; int dn[128][128]; int H,W; int valid(int x,int y){ if( x < 0 || y < 0 || x >= W || y >= H ) return 0; if( a[y][x] == '#' ) return 0; if( dn[y][x] ) return 0; return 1; } int main(){ cin >> H >> W; int c = 0; rep(i,H)rep(j,W) cin >> a[i][j], c += a[i][j] == '.'; rep(i,H)rep(j,W){ if( valid(j,i) == 0 ) continue; rep(d_,4){ int s = 0; int d = d_; int x = j; int y = i; while(1){ if( valid(x+dx[d],y+dy[d]) == 0 ){ //cout << i << " " << j << "|" << y << " " << x << "|" << s << "(" << dx[d_] << ")" << endl; if( (x+dx[d] == j && y+dy[d] == i || x+dx[(d+3)%4] == j && y+dy[(d+3)%4] == i) && s == c ){ //cout << i << " " << j << "|" << y << " " << x << "|" << d_ << " " << d << endl; cout << "YES" << endl; return 0; } break; } if( dn[y][x] == 0 ){ s++; dn[y][x] = true; } while( valid(x+dx[d],y+dy[d]) ){ x += dx[d]; y += dy[d]; dn[y][x] = true; s ++; } d = (d+1) % 4; } memset(dn,0,sizeof(dn)); } } cout << "NO" << endl; }