QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397846 | #5438. Half Mixed | caijianhong | WA | 0ms | 3628kb | C++14 | 1.3kb | 2024-04-24 17:38:31 | 2024-04-24 17:38:31 |
Judging History
answer
//
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
typedef long long LL;
vector<int> knapsack(int n, LL m) {
// (n, m)
// (x, (x - 1) * x / 2)
vector<int> ret;
while (m) {
LL x = sqrt(x);
while (x * (x + 1) / 2 <= m) x += 1;
while (x * (x - 1) / 2 > m) x -= 1;
ret.push_back(x);
n -= x;
m -= x * (x - 1) / 2;
}
assert(n >= 0);
ret.insert(ret.end(), n, 1);
return ret;
}
auto solve(int n) { return knapsack(n, 1ll * n * (n + 1) / 4 - n); }
int main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t;
cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
if (1ll * m * (m + 1) % 4 == 0) {
string s;
auto ret = solve(m);
int c = 0;
for (int len : ret) s.append(len, c + '0'), c ^= 1;
cout << "Yes" << endl;
for (int i = 1; i <= n; i++) cout << s << endl;
} else if (1ll * n * (n + 1) % 4 == 0) {
string s;
auto ret = solve(n);
int c = 0;
for (int len : ret) s.append(len, c + '0'), c ^= 1;
cout << "Yes" << endl;
for (auto ch : s) cout << string(m, ch) << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
2 2 3 1 1
output:
Yes 010 010 No
result:
wrong output format Expected integer, but "010" found (test case 1)