QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696688#5438. Half MixedXiaoYang3TL 0ms3536kbC++232.4kb2024-11-01 00:28:222024-11-01 00:28:24

Judging History

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

  • [2024-11-01 00:28:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3536kb
  • [2024-11-01 00:28:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
ll n, m, k, ans;
const int N = 4e6 + 5;
const int P = 1e9 + 7;
ll ck(ll n) {
    return n * (n + 1) / 2;
}
void solve() {
    cin >> n >> m;
    if (ck(n) % 2 == 0) {
        vector<int> a;
        ll res = ck(n) / 2;
        int cnt = n;
        for (int i = n; i >= 1; i--) {
            if (ck(i) + cnt - i > res) {
                continue;
            }
            while (ck(i) + cnt - i <= res) {
                a.push_back(i);
                cnt -= i;
                res -= ck(i);
                if (res == 0) {
                    break;
                }
            }
        }
        vector<int> ve(n + 2);
        int sum = 0;
        for (int i = 0; i < a.size(); i++) {
            if (i & 1) {
                for (int j = sum + 1; j <= sum + a[i]; j++) {
                    ve[j] = 1;
                }
            }
            sum += a[i];
        }
        cout << "Yes\n";
        for (int j = 1; j <= n; j++) {
            for (int i = 1; i <= m; i++) {
                cout << ve[j] << ' ';
            }
            cout << '\n';
        }

    } else if (ck(m) % 2 == 0) {
        swap(n, m);
        vector<int> a;
        ll res = ck(n) / 2;
        int cnt = n;
        for (int i = n; i >= 1; i--) {
            if (ck(i) + cnt - i > res) {
                continue;
            }
            while (ck(i) + cnt - i <= res) {
                a.push_back(i);
                cnt -= i;
                res -= ck(i);
                if (res == 0) {
                    break;
                }
            }
        }
        vector<int> ve(n + 2);
        int sum = 0;
        for (int i = 0; i < a.size(); i++) {
            if (i & 1) {
                for (int j = sum + 1; j <= sum + a[i]; j++) {
                    ve[j] = 1;
                }
            }
            sum += a[i];
        }
        cout << "Yes\n";
        for (int j = 1; j <= m; j++) {
            for (int i = 1; i <= n; i++) {
                cout << ve[i] << ' ';
            }
            cout << '\n';
        }
    } else {
        cout << "No\n";
    }
}
int main() {
    //  ios::sync_with_stdio(0);
    // cin.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

2
2 3
1 1

output:

Yes
0 1 0 
0 1 0 
No

result:

ok OK, Accepted. (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

5382
1 1
1 2
2 1
1 3
2 2
3 1
1 4
2 3
3 2
4 1
1 5
2 4
3 3
4 2
5 1
1 6
2 5
3 4
4 3
5 2
6 1
1 7
2 6
3 5
4 4
5 3
6 2
7 1
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1
1 11
2 10
3 9
4 8
5 7
6 6
7 5
8 4
9 3
10 2
11 1
1 12
2 11
3 10
4 9
5 8
6 ...

output:

No
No
No
Yes
0 1 0 
No
Yes
0 
1 
0 
Yes
0 0 1 0 
Yes
0 1 0 
0 1 0 
Yes
0 0 
1 1 
0 0 
Yes
0 
0 
1 
0 
No
Yes
0 0 1 0 
0 0 1 0 
Yes
0 0 0 
1 1 1 
0 0 0 
Yes
0 0 
0 0 
1 1 
0 0 
No
No
No
Yes
0 0 0 0 
1 1 1 1 
0 0 0 0 
Yes
0 0 0 
0 0 0 
1 1 1 
0 0 0 
No
No
Yes
0 0 0 0 1 1 0 
No
Yes
0 0 0 0 0 
1 1 1 1 1...

result: