結果
| 問題 |
No.179 塗り分け
|
| コンテスト | |
| ユーザー |
smiken_61
|
| 提出日時 | 2015-10-23 12:42:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 3,000 ms |
| コード長 | 1,395 bytes |
| コンパイル時間 | 479 ms |
| コンパイル使用メモリ | 61,376 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-23 14:33:07 |
| 合計ジャッジ時間 | 1,691 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
using namespace std;
int za(int ta, int yo,int i, int j){
if(-1<i && -1<j && ta>i && yo>j) return (i*yo)+j;
else return -1;
}
pair<int,int> mo(int ta,int yo,int m){
return make_pair(m/yo,m%yo);
}
int main() {
int ta,yo;
string s;
int ma[52][52]={0};
int re[2704]={0};
int minz=10000;
cin>>ta>>yo;
for(int i=0;i<ta;i++){
cin>>s;
for(int j=0;j<yo;j++){
if(s[j]=='.'){
ma[i][j]=0;
re[za(ta,yo,i,j)]=0;
}
else if(s[j]=='#'){
ma[i][j]=1;
re[za(ta,yo,i,j)]=1;
if(za(ta,yo,i,j)<minz) minz=za(ta,yo,i,j);
}
}
}
int ans=0,l;
//cout<<minz<<endl;
if(minz==10000) ans=0;
else{
for(int k=1;k<ta*yo-minz;k++){
//if(k>=ta*yo-minz) break;
if(ans==0&&re[minz+k]==1){
int co[2704]={0};
for(int i=0;i<2704;i++) co[i]=re[i];
co[minz+k]=2;
l=minz+1;
int dx=mo(ta,yo,minz+k).first-mo(ta,yo,minz).first;
int dy=mo(ta,yo,minz+k).second-mo(ta,yo,minz).second;
while(l<ta*yo){
if(co[l]==1) {
if(za(ta,yo,dx+mo(ta,yo,l).first,dy+mo(ta,yo,l).second)<0) l=ta*yo+1;
else if(co[za(ta,yo,dx+mo(ta,yo,l).first,dy+mo(ta,yo,l).second)]!=1) l=ta*yo+1;
else co[za(ta,yo,dx+mo(ta,yo,l).first,dy+mo(ta,yo,l).second)]=2;
}
l=l+1;
}
if(l==ta*yo) ans=1;
// cout<<k<<" ";
// for(int i=0;i<9;i++) cout<<co[i];
// cout<<endl;
}
}
}
if(ans==0) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}
smiken_61