QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504991#7178. BishopsEsoulingTL 0ms3616kbC++201.3kb2024-08-04 18:06:372024-08-04 18:06:37

Judging History

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

  • [2024-08-04 18:06:37]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3616kb
  • [2024-08-04 18:06:37]
  • 提交

answer

#include <bits/stdc++.h>

using loint = long long;
using db = double;

void solve() {
    
    int n, m;
    std::cin >> n >> m;
    int inv = 0;
    if (n > m) {
        std::swap(n, m);
        inv = 1;
    }
    std::vector<std::pair<int, int>> ans;
    std::set<int> st1, st2;

    int l = 1, r = m;
    int cur = 1;
    while (l <= r) {
        if (cur & 1) {
            for (int i = 1; i <= n; i ++) {
                if (st1.count(i + l) == 0 && st2.count(i - l) == 0) {
                    st1.insert(i + l);
                    st2.insert(i - l);
                    ans.push_back({i, l});
                }
            }
            l ++;
        } else {
            for (int i = 1; i <= n; i ++) {
                if (st1.count(i + r) == 0 && st2.count(i - r) == 0) {
                    st1.insert(i + r);
                    st2.insert(i - r);
                    ans.push_back({i, r});
                }
            }
            r --;
        }
        cur ^= 1;
    }

    std::cout << ans.size() << '\n';
    for (auto &[x, y] : ans) {
        if (inv) std::swap(x, y);
        std::cout << x << ' ' << y << '\n';
    }
}

int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 5

output:

6
1 1
2 1
1 5
2 5
1 3
2 3

result:

ok n: 2, m: 5, bishops: 6

Test #2:

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

input:

5 5

output:

8
1 1
2 1
3 1
4 1
5 1
2 5
3 5
4 5

result:

ok n: 5, m: 5, bishops: 8

Test #3:

score: -100
Time Limit Exceeded

input:

100000 100000

output:


result: