QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386993 | #6746. Merge the Rectangles | Arnold_6# | TL | 47ms | 26136kb | C++14 | 1.6kb | 2024-04-11 22:35:26 | 2024-04-11 22:35:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1510;
int n,m;
char col[N][N],row[N][N];
int righ[N][N],down[N][N];
bool dfs(int x1,int y1,int x2,int y2){
// printf("%d %d %d %d\n",x1,y1,x2,y2);
bool tm1=0,tm2=0;
bool ret=1;
for(int i=x1+1;i<x2;++i){
// printf("xi=%d righ=%d\n",i,righ[i][y1]);
if(righ[i][y1]!=y1) ret=0;
if(righ[i][y1]<y2) continue;
tm1=dfs(x1,y1,i,y2);
tm2=dfs(i,y1,x2,y2);
if(!tm1) break;
if(tm2) return 1;
}
for(int i=y1+1;i<y2;++i){
// printf("yi=%d down=%d\n",i,down[x1][i]);
if(down[x1][i]<x2) continue;
if(down[x1][i]!=x1) ret=0;
tm1=dfs(x1,y1,x2,i);
tm2=dfs(x1,i,x2,y2);
if(!tm1) break;
if(tm2) return 1;
}
return ret;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<n;++i) scanf("%s",row[i]+1);
for(int i=1;i<=n;++i) scanf("%s",col[i]+1);
for(int i=1;i<n;++i){
righ[i][m]=m;
for(int j=m;j>=1;--j){
// cout<<i<<" "<<j<<" "<<row[i][j]<<endl;
if(row[i][j]=='1') righ[i][j-1]=righ[i][j];
else righ[i][j-1]=j-1;
}
}
for(int j=1;j<m;++j){
down[n][j]=n;
for(int i=n;i>=1;--i){
if(col[i][j]=='1') down[i-1][j]=down[i][j];
else down[i-1][j]=i-1;
}
}
// for(int i=1;i<n;++i){
// for(int j=0;j<=m;++j) cout<<righ[i][j];
// cout<<endl;
// }
if(dfs(0,0,n,m)) puts("YES");
else puts("NO");
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 10004kb
input:
3 4 0000 0111 101 101 110
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 9944kb
input:
3 3 110 011 01 11 10
output:
NO
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 16ms
memory: 26116kb
input:
1500 1500 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
YES
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 47ms
memory: 26136kb
input:
1500 1500 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
YES
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 11ms
memory: 26136kb
input:
1500 1500 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
YES
result:
ok answer is YES
Test #6:
score: 0
Accepted
time: 13ms
memory: 25988kb
input:
1500 1500 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
YES
result:
ok answer is YES
Test #7:
score: -100
Time Limit Exceeded
input:
1500 1500 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...