QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106723 | #5438. Half Mixed | ycccc319 | WA | 0ms | 11272kb | C++17 | 5.0kb | 2023-05-18 21:48:40 | 2023-05-18 21:48:43 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
ll C(ll n) {
if (n == 0) {
return 0;
}
return n * (n + 1) / 2;
}
ll c[1000010];
bool checker(vector<vector<int>> M, int n, int m) {
int pure = 0, dirty = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int a = i; a < n; a++) {
for (int b = j; b < m; b++) {
int zero = 0, one = 0;
for (int q = i; q <= a; q++) {
for (int w = j; w <= b; w++) {
if (M[q][w] == 0)zero++;
else one++;
}
}
if (zero == 0 || one == 0)pure++;
else dirty++;
}
}
}
}
return pure == dirty;
}
void maker(int n, int m) {
for (int t = 0; t < pow(2, n * m); t++) {
vector<vector<int>> tmp;
for (int i = 0; i < n; i++) {
vector<int> temp;
for (int j = 0; j < m; j++) {
temp.push_back((t >> (i * m + j)) & 1);
}
tmp.push_back(temp);
if (checker(tmp, n, m)) {
for (auto to: tmp) {
for (auto tu: to) {
cout << tu << " ";
}
cout << endl;
}
cout << endl;
}
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(nullptr);
// for(int i=1;i<=1000;i++)
// {
// cout<<i<<" "<<C(i+1)-C(i)<<endl;
// }
for (int i = 0; i <= 1000000; i++) {
c[i] = C(i);
}
// cout << c[6 + 1] + c[3 + 1] + 1 * c[1] << endl;
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
swap(n, m);
if (((n) * (n + 1) * (m) * (m + 1) / 4) & 1) {
cout << "NO\n";
continue;
}
bool ok = 0;
// int x=n,y=m;
vector<int> tmp;
int cn = (n) * (n + 1) / 4 - n;
if (cn >= 0) {
// cout << cn + n << endl;
while (cn > 0) {
int wz = upper_bound(c, c + 1000000, cn) - c;
wz--;
tmp.push_back(wz + 1);
cn -= c[wz];
}
int sum = 0;
for (auto to: tmp) {
sum += to;
// cout << to << " ";
}
if (sum <= n) {
ok = 1;
cout << "YES\n";
bool now = 0;
vector<bool> v;
for (auto to: tmp) {
for (int i = 1; i <= to; i++) {
v.push_back(now);
}
now = !now;
}
for (int i = n - sum; i > 0; i--) {
v.push_back(now);
now = !now;
}
for (int i = 1; i <= m; i++) {
for (auto to: v) {
cout << to << " ";
}
cout << "\n";
}
}
}
if (ok)continue;
tmp.clear();
int cm = (m) * (m + 1) / 4 - m;
if (cm >= 0) {
// cout << cn + n << endl;
while (cm > 0) {
int wz = upper_bound(c, c + 1000000, cm) - c;
wz--;
tmp.push_back(wz + 1);
cm -= c[wz];
}
int sum = 0;
for (auto to: tmp) {
sum += to;
// cout << to << " ";
}
if (sum <= m) {
ok = 1;
cout << "YES\n";
bool now = 0;
vector<bool> v;
for (auto to: tmp) {
// cout << to << endl;
for (int i = 1; i <= to; i++) {
v.push_back(now);
}
now = !now;
}
for (int i = m - sum; i > 0; i--) {
v.push_back(now);
now = !now;
}
for (auto to: v) {
for (int i = 1; i <= n; i++) { cout << to << " "; }
cout << "\n";
}
}
}
if (!ok)cout << "NO\n";
}
// ll n, m;
// for (int n = 1; n <= 1000000; n++) {
//// cin>>n>>m;
// ll ans = n * (n + 1) / 2;
//// ll x1,x2,y1,y2;
// if (n % 4 != 0) {
// continue;
// }
// bool ok = 0;
// for (int i = 1; i <= n; i++) {
// ll as = C(i) + n - i;
// if (as == ans / 2) {
// ok = 1;
// }
// }
// if (ok == 0) {
// cout << n << " ";
// }
// }
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11272kb
input:
2 2 3 1 1
output:
YES 0 1 0 0 1 0 NO
result:
wrong answer Token "YES" doesn't correspond to pattern "Yes|No" (test case 1)