QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#475851#6746. Merge the Rectanglesszy10010WA 143ms463664kbC++174.1kb2024-07-13 16:51:452024-07-13 16:51:45

Judging History

你现在查看的是最新测评结果

  • [2024-07-13 16:51:45]
  • 评测
  • 测评结果:WA
  • 用时:143ms
  • 内存:463664kb
  • [2024-07-13 16:51:45]
  • 提交

answer

#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define pp pop_back()
#define int long long
#define lowbit(x) ((x)&(-x))
#define double long double
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld %lld",&x,&y)
#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const int N=2010,INF=4e18;
int n,m;
int r[N][N],c[N][N];
int cutr[N*N*2],cutc[N*N*2];
int cntr[N*N*2],cntc[N*N*2];
pair<int,int> jian[N*N*2];
int mpr[N][N],mpc[N][N];
//map<PII,int>mpr,mpc;
int idx=1,hh;
vector<int>cut[N*N*2];
void solve()
{
	cin>>n>>m;
	char cr;
	for(int i=1;i<=n-1;i++)
		for(int j=1;j<=m;j++)
		{
			cin>>cr;
			if(cr=='1')r[i][j]=1;
			else r[i][j]=0;
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m-1;j++)
		{
			cin>>cr;
			if(cr=='1')c[i][j]=1;
			else c[i][j]=0;
		}	
	bool bl;
	for(int i=1;i<=n-1;i++)
	{
		bl=false;
		for(int j=1;j<=m;j++)
		{	
			if(r[i][j]==1)
			{
				mpr[i][j]=idx,bl=true;//cout<<"行的"<<i<<" "<<j<<" 为"<<idx<<endl;
				if(j==1&&c[i][j]+c[i+1][j]==2)idx++,bl=false;
				else if(j==m&&c[i][j-1]+c[i+1][j-1]==2)idx++,bl=false;
				else if(c[i][j]+c[i+1][j]==2&&c[i][j-1]+c[i+1][j-1]==2)idx++,bl=false;				
			}
			else if(bl)idx++,bl=false;
		}
		if(bl)idx++,bl=false;
	}
//	cout<<"nowidx"<<idx<<endl;
	hh=idx-1;
	for(int j=1;j<=m-1;j++)
	{
		bl=false;
		for(int i=1;i<=n;i++)
		{
			if(c[i][j]==1)
			{
				mpc[i][j]=idx,bl=true;//cout<<"列的"<<i<<" "<<j<<" 为"<<idx<<endl;
				if(i==1&&r[i][j]+r[i][j+1]==2)idx++,bl=false;
				else if(i==n&&r[i-1][j]+r[i-1][j+1]==2)idx++,bl=false;
				else if(r[i][j]+r[i][j+1]==2&&r[i-1][j]+r[i-1][j+1]==2)idx++,bl=false;	
			}
			else if(bl)idx++,bl=false;
		}
		if(bl)idx++,bl=false;
	}
//	8986506
//	cout<<idx<<endl;
//	cout<<idx<<endl;
	for(int i=1;i<=n-1;i++)
		for(int j=1;j<=m;j++)
		{
			if(r[i][j]==1)
			{
				int now=mpr[i][j];
				if(j==1&&c[i][j]+c[i+1][j]==2&&mpc[i][j]==mpc[i+1][j])
					cutc[mpc[i][j]]++,cut[now].pb(mpc[i][j]);
				else if(j==m&&c[i][j-1]+c[i+1][j-1]==2&&mpc[i][j-1]==mpc[i+1][j-1])
					cutc[mpc[i][j-1]]++,cut[now].pb(mpc[i][j-1]);
				else 
				{
					if(c[i][j]+c[i+1][j]==2&&mpc[i][j]==mpc[i+1][j])
						cutc[mpc[i][j]]++,cut[now].pb(mpc[i][j]);
					if(c[i][j-1]+c[i+1][j-1]==2&&mpc[i][j-1]==mpc[i+1][j-1])
						cutc[mpc[i][j-1]]++,cut[now].pb(mpc[i][j-1]);
				}
			}
		}
	for(int j=1;j<=m-1;j++)
		for(int i=1;i<=n;i++)
		{
			if(c[i][j]==1)
			{
				int now=mpc[i][j];
				if(i==1&&r[i][j]+r[i][j+1]==2&&mpr[i][j]==mpr[i][j+1])
					cutr[mpr[i][j]]++,cut[now].pb(mpr[i][j]);
				else if(i==n&&r[i-1][j]+r[i-1][j+1]==2&&mpr[i-1][j]==mpr[i-1][j+1])
					cutr[mpr[i-1][j]]++,cut[now].pb(mpr[i-1][j]);
				else 
				{
					if(r[i][j]+r[i][j+1]==2&&mpr[i][j]==mpr[i][j+1])
						cutr[mpr[i][j]]++,cut[now].pb(mpr[i][j]);
					if(r[i-1][j]+r[i-1][j+1]==2&&mpr[i-1][j]==mpr[i-1][j+1])
						cutr[mpr[i-1][j]]++,cut[now].pb(mpr[i-1][j]);
				}
			}
		}
//	priority_queue<PII,vector<PII>,cmp>p;
//	multiset<PII,cmp>p;
	queue<PII>p;
	for(int i=1;i<idx;i++)
	{
		if(i<=hh)jian[i]={cutr[i],i};//cout<<"cutc"<<cutr[i]<<" "<<i<<endl;
		else jian[i]={cutc[i],i};//cout<<"cutr"<<cutc[i]<<" "<<i<<endl;
		if(jian[i].fi==0)p.push(jian[i]);//cout<<jian[i].se<<" ";
	}
	int cnt=0;
	while(p.size())
	{
		cnt++;
		auto t=p.front();
		p.pop();
//		cout<<t.fi<<" "<<t.se<<endl;
//		cout<<"now"<<t.fi<<" "<<jian[t.se]<<"编号"<<t.se<<endl;
//		cout<<t.fi<<" "<<t.se<<endl;
		for(int i=0;i<cut[t.se].size();i++)
		{
//			cout<<"cut了"<<cut[t.se][i]<<" ";
			int now=cut[t.se][i];
			jian[now].fi--;
			if(jian[now].fi<=0)p.push(jian[now]);//cout<<jian[now].se<<" ";
		}
	}
//	cout<<endl;
//	cout<<cnt<<endl;
	if(cnt==idx-1)cout<<"YES\n";
	else cout<<"NO\n";
	return;
}
signed main()
{
	IOS;
	int T=1;
//	cin>>T;
	while(T--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 206364kb

input:

3 4
0000
0111
101
101
110

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 26ms
memory: 205836kb

input:

3 3
110
011
01
11
10

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 73ms
memory: 246740kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 122ms
memory: 440468kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 70ms
memory: 274060kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

ok answer is YES

Test #6:

score: 0
Accepted
time: 86ms
memory: 270424kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok answer is YES

Test #7:

score: 0
Accepted
time: 132ms
memory: 446172kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

NO

result:

ok answer is NO

Test #8:

score: -100
Wrong Answer
time: 143ms
memory: 463664kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result:

wrong answer expected NO, found YES