QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360980#6746. Merge the RectanglessacaveTL 18ms25592kbC++142.5kb2024-03-22 17:14:012024-03-22 17:14:02

Judging History

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

  • [2024-03-22 17:14:02]
  • 评测
  • 测评结果:TL
  • 用时:18ms
  • 内存:25592kb
  • [2024-03-22 17:14:01]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
#define x first
#define y second
#define no cout << "No" << endl
#define yes cout << "Yes" << endl

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;

const int N = 1510;
const int inf = 0x3f3f3f3f;
const ll lnf = 1e18;

int T,n,m;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
string a[N],b[N];
int hen[N][N],shu[N][N];
bool flag = 1;
map<pair<PII,PII>,int> mp;

void dfs(int x1,int y1,int x2,int y2){
	if(mp.count({{x1,y1},{x2,y2}})) return ;
	mp[{{x1,y1},{x2,y2}}] = 1;
	// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	if(x1 == x2 || y1 == y2) return ;
	bool t = 0;
	for(int i=x1+1;i<x2;i++){
		// cout << hen[i][y2] - hen[i][y1] << endl;
		if(hen[i][y2] - hen[i][y1] == y2 - y1){
			// cout << "YES" << endl;
			dfs(x1,y1,i,y2);
			dfs(i,y1,x2,y2);
			return ;
			t = 1;
		}
	}
	for(int i=y1+1;i<y2;i++){
		if(shu[x2][i] - shu[x1][i] == x2 - x1){
			dfs(x1,y1,x2,i);
			dfs(x1,i,x2,y2);
			return ;
			t = 1;
			// return ;
		}
	}
	// if(t) return ;
	// cout << endl;
	for(int i=x1;i<=x2;i++){
		int d = hen[i][y2] - hen[i][y1];
		// cout << d << endl;
		if(d >= 1 && d != y2 - y1) flag = 0;
		// if(!flag){
			// cout << "row : " << i << endl;
			// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
			// exit(0);
		// }
	}
	for(int i=y1;i<=y2;i++){
		int d = shu[x2][i] - shu[x1][i];
		if(d >= 1 && d != x2 - x1) flag = 0;
		// if(!flag){
			// cout << "col : " << i << endl;
			// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
			// exit(0);
		// }
	}
}

void solve(){
	cin >> n >> m;
	for(int i=1;i<n;i++) cin >> a[i] ,a[i] = 'a' + a[i];
	for(int i=1;i<=n;i++) {
		cin >> b[i];
		b[i] = '1' + b[i];
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			hen[i][j] = a[i][j] - '0';
			hen[i][j] += hen[i][j-1]; 
		}
	}
	for(int j=1;j<m;j++){
		for(int i=1;i<=n;i++){
			shu[i][j] = b[i][j] - '0';
			shu[i][j] += shu[i-1][j];
		}
	}
	// for(int i=1;i<=n;i++) hen[i][m] += hen[i][m-1];
	// for(int i=1;i<=m;i++) shu[n][i] += shu[n-1][i];
	
	// for(int i=0;i<=n;i++){
		// for(int j=0;j<=m;j++){
			// cout << hen[i][j] << ' ';
		// }
		// cout << endl;
	// }
	// cout << endl;
	// for(int i=0;i<=n;i++){
		// for(int j=0;j<=m;j++){
			// cout << shu[i][j] << ' ';
		// }
		// cout << endl;
	// }
	// cout << endl;
	
	dfs(0,0,n,m);
	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	solve();
	
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3672kb

input:

3 4
0000
0111
101
101
110

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

3 3
110
011
01
11
10

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 18ms
memory: 25592kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok answer is YES

Test #4:

score: -100
Time Limit Exceeded

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES

result: