QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413527 | #6746. Merge the Rectangles | HHY_zZhu# | RE | 1ms | 5668kb | C++14 | 3.6kb | 2024-05-17 17:51:33 | 2024-05-17 17:51:34 |
Judging History
answer
template<class T,class T2> int chkmn(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2> int chkmx(T &a,T2 b){return a<b?a=b,1:0;}
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
#ifdef LOCAL
#include "C:/Users/lijia/Desktop/vscode/algo/debug.h"
#else
#define debug(...) 42
#endif
const int MN = 1500 + 10;//MaxN 记得改一下
const int INF = 2e9+1000;//INF
const LL INFLL = 8e18+1000;//INF long long
mt19937 mrand(random_device{}());
//模板区域~~~~~~~
//模板结束~~~~~~~
int use[2][MN][MN][2];
void solve() {
int n, m; cin >> n >> m;
V<string> hor(n + 1);
V<string> ver(m + 1);
for(int i = 1; i <= n - 1; i++) {
cin >> hor[i], hor[i] = " " + hor[i];
}
string tot1 = " ";
for(int i = 1; i <= m; i++) tot1.pb('1');
hor[0] = hor[n] = tot1;
for(int i = 1; i <= m - 1; i++) {
ver[i].resize(n + 1);
}
for(int i = 1; i <= n; i++) {
string s; cin >> s;
s = " " + s;
for(int j = 1; j <= m; j++) ver[j][i] = s[j];
}
tot1 = " ";
for(int i = 1; i <= n; i++) tot1.pb('1');
ver[0] = ver[m] = tot1;
// for(int i = 0; i <= m; i++) cout << ver[i] << endl;
queue<array<int, 3>> que;
auto upd = [&](int t, int x, int y, int dy, int mxd) {
// cout << t << " " << x << " " << y << " " << dy << " " << mxd << endl;
int chg = dy;
if(dy == -1) chg = 0;
while(y >= 0 && y <= mxd) {
if(use[t][x][y][chg]) return;
if(t == 1 && ver[x][y] == '0') return;
if(t == 0 && hor[x][y] == '0') return;
// cout << "solve" << t << " " << x << " " << y << chg << endl;
use[t][x][y][chg] = 1;
if(use[t][x][y][0] && use[t][x][y][1]) que.push({t, x, y});
y += dy;
}
};
for(int i = 1; i <= m; i++) {
que.push({0, 0, i});
use[0][0][i][0] = use[0][0][i][1] = 1;
que.push({0, n, i});
use[0][n][i][0] = use[0][n][i][1] = 1;
}
for(int i = 1; i <= n; i++) {
que.push({1, 0, i});
use[1][0][i][0] = use[1][0][i][1] = 1;
que.push({1, m, i});
use[1][m][i][0] = use[1][m][i][1] = 1;
}
V<array<int, 3>> dir = {{0, 0, -1}, {0, 1, 1}, {-1, 0, -1}, {-1, 1, 1}};
while(que.size()) {
auto [t, x, y] = que.front();
swap(x, y);
que.pop();
for(auto [dx, dy, ddy] : dir) {
int mxx = n, mxy = m;
if(t == 0) swap(mxx, mxy);
if(dx + x > mxx || dx + x < 0 || dy + y <= 0 || dy + y > mxy) continue;
upd(t ^ 1, dx + x, dy + y, ddy, mxy);
}
}
bool ok = 1;
for(int i = 1; i < n; i++) {
for(int j = 1; j <= m; j++) {
if(hor[i][j] == '1' && !(use[0][i][j][1] && use[0][i][j][0])) ok = 0;//, cout << 0 << " " << i << " " << j << endl;
}
}
for(int i = 1; i < m; i++) {
for(int j = 1; j <= n; j++) {
if(ver[i][j] == '1' && !(use[1][i][j][1] && use[1][i][j][0])) ok = 0;//, cout << 1 << " " << i << " " << j << endl;
}
}
cout << (ok ? "YES" : "NO");
}
int32_t main() {
#ifndef LOCAL
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#endif
int tt=1;
//cin >> tt;
while (tt--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5540kb
input:
3 4 0000 0111 101 101 110
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
3 3 110 011 01 11 10
output:
NO
result:
ok answer is NO
Test #3:
score: -100
Runtime Error
input:
1500 1500 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...