QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#369#164795#7178. Bishopsucup-team1208ucup-team004Failed.2023-09-10 13:52:342023-09-10 13:52:36

Details

Extra Test:

Invalid Input

input:

8 4
12

output:


result:

FAIL Expected EOF (stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164795#7178. Bishopsucup-team004#AC ✓39ms12260kbC++201.4kb2023-09-05 13:42:572023-09-05 13:42:57

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m;
    std::cin >> n >> m;
    
    std::vector<std::pair<int, int>> ans;
    for (int t = 0; t < 2; t++) {
        std::vector<std::vector<std::pair<int, int>>> a(n + m - 1);
        for (int i = -m + 1; i < n; i++) {
            if ((i + t) % 2) {
                continue;
            }
            int l = std::max(-i, i);
            int r = std::min(2 * n - 2 - i, 2 * m - 2 + i);
            a[l].push_back({r, i});
        }
        std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<>> q;
        for (int j = 0; j < n + m - 1; j++) {
            for (auto [r, i] : a[j]) {
                q.push({r, i});
            }
            if ((j + t) % 2) {
                continue;
            }
            while (!q.empty()) {
                auto [r, i] = q.top();
                q.pop();
                if (r < j) {
                    continue;
                }
                int x = (i + j) / 2 + 1;
                int y = (j - i) / 2 + 1;
                ans.push_back({x, y});
                break;
            }
        }
    }
    std::cout << ans.size() << "\n";
    for (auto [x, y] : ans) {
        std::cout << x << " " << y << "\n";
    }
    
    return 0;
}