QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211614#6743. water235psycho#WA 0ms3880kbC++142.2kb2023-10-12 19:23:042023-10-12 19:23:04

Judging History

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

  • [2023-10-12 19:23:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3880kb
  • [2023-10-12 19:23:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

pair<int, vector<vector<int>>> get(int n, int m) {
    vector<vector<int>> a(n, vector<int> (m, 0));
    int cnt = 0;
    for (int i = 0, s = 0; i < n; i += 2, s ^= 1) {
        for (int j = s; j < m; j += 2) {
            a[i][j] = 1;
            ++cnt;
        }
        if (n % 2 == 0 && i + 1 == n - 1) {
            for (int j = 0; j < m; j += 2) {
                a[i + 1][j] = 1;
                ++cnt;
            }
        }
    }
    return make_pair(cnt, a);
}

void print(vector<vector<int>> a) {
    for (auto &el : a) {
        for (auto &i : el) cerr << i << ' ';
        cerr << '\n';
    }
    cerr << '\n';
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    if (max(n, m) <= 2) {
        if (n == 2 && m == 2) {
            cout << "2\n1 0\n0 1";
            return 0;
        }
        cout << n * m << '\n';
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                cout << 1 << ' ';
            }
            cout << '\n';
        }
        return 0;
    }
    if (n == 1 || m == 1) {
        vector<int> ans(max(n, m), 0);
        int sm = 0;
        for (int i = 0, s = 1; i < max(n, m); ++++i) {
            ans[i] = s;
            ++sm;
        }
        if (max(n, m) % 2 == 0) {
            ans.back() = 1;
            ++sm;
        }
        cout << sm << '\n';
        for (auto &el : ans) {
            cout << el << ' ';
            if (n > 1) {
                cout << "\n";
            }
        }
        return 0;
    }
    auto [cnt1, ans1] = get(n, m);
    auto [cnt2, ans2] = get(m, n);
    cout << min(cnt1, cnt2) << '\n';
    if (cnt1 < cnt2) {
        for (auto &el : ans1) {
            for (auto &i : el) cout << i << ' ';
            cout << '\n';
        }
    } else {
        vector<vector<int>> ns(n, vector<int> (m));
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                ns[j][i] = ans2[i][j];
            }
        }
        for (auto &el : ns) {
            for (auto &i : el) cout << i << ' ';
            cout << '\n';
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1

output:

2
1 
1 

result:

ok The answer is correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

3 3

output:

3
1 0 0 
0 0 1 
1 0 0 

result:

ok The answer is correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 4

output:

3
1 0 1 1 

result:

ok The answer is correct.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

2 2

output:

2
1 0
0 1

result:

ok The answer is correct.

Test #5:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

2 4

output:

3
1 0 0 1 
0 0 1 0 

result:

ok The answer is correct.

Test #6:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

4 3

output:

4
1 0 0 
0 0 1 
1 0 0 
0 0 1 

result:

ok The answer is correct.

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3572kb

input:

4 4

output:

6
1 0 0 1 
0 0 1 0 
1 0 0 1 
0 0 1 0 

result:

wrong answer The answer is wrong: expected = 4, found = 6