QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196550#5438. Half MixedPHarrWA 0ms3816kbC++201.3kb2023-10-01 19:01:152023-10-01 19:01:17

Judging History

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

  • [2023-10-01 19:01:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2023-10-01 19:01:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

using vi = vector<int>;

void solve() {
    int n, m;
    cin >> n >> m;
    if ((n * (n + 1) * m * (m + 1) / 4) & 1) {
        cout << "No\n";
        return;
    }
    cout << "YES\n";
    int t = n, T = n * (n + 1) / 2;
    if (T & 1) t = m, T = m * (m + 1) / 2;
    T = T / 2 - t;
    auto f = [&t, &T]() {
        int l = 1, r = t, res = -1;
        for (int mid; l <= r;) {
            mid = (l + r) / 2;
            if (mid * (mid - 1) / 2 <= T) res = mid, l = mid + 1;
            else r = mid - 1;
        }
        t -= res, T -= res * (res - 1) / 2;
        return res;
    };
    vector<int> res;
    for (int x = 0, y; t; x ^= 1) {
        y = f();
        for (; y; y--) res.push_back(x);
    }
    if (res.size() == m) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++)
                cout << res[j] << " ";
            cout << "\n";
        }
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << res[i] << " ";
            }
            cout << "\n";
        }
    }
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int TC;
    for (cin >> TC; TC; TC--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3816kb

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)