QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#675#440111#7178. Bishopsshenzhiyancyb1010Failed.2024-06-13 14:46:342024-06-13 14:46:34

Details

Extra Test:

Accepted
time: 0ms
memory: 3760kb

input:

1 1

output:

1
1 1

result:

ok n: 1, m: 1, bishops: 1

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440111#7178. Bishopscyb1010AC ✓16ms5340kbC++141.6kb2024-06-13 09:14:442024-06-13 09:14:44

answer

/**
 * @author : cyb1010
 * @date   : 2024-06-13 08:10:59
 * @file   : bishop.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<pair<int, int>> vp;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
int __, n, m;
vp ans;
vp solve(int n, int m) {
    vp res;
    if (n > m) {
        res = solve(m, n);
        for (auto &[x, y] : res) swap(x, y);
        return res;
    }
    if (n & 1) {
        for (int i = 1; i <= n; i++)
            res.emplace_back(i, 1), res.emplace_back(i, m);
        int rw = n / 2 + 1;
        for (int i = rw + 1; i + rw <= m; i++) res.emplace_back(rw, i);
        return res;
    }
    for (int i = 1; i <= n; i++) res.emplace_back(i, 1), res.emplace_back(i, m);
    int rw = n / 2;
    for (int i = rw + 2; i + rw < m; i += 2)
        res.emplace_back(rw, i), res.emplace_back(rw + 1, i);
    return res;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    if (n == m) {
        if (n == 1) return cout << "1\n1 1\n", 0;
        cout << n * 2 - 2 << '\n';
        for (int i = 1; i < n; i++)
            cout << i << " 1\n" << i << ' ' << n << '\n';
        return 0;
    }
    vp ans = solve(n, m);
    cout << SZ(ans) << '\n';
    for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
    return 0 ^ __ ^ 0;
}