QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505155 | #7178. Bishops | Esouling | ML | 0ms | 3816kb | C++20 | 1.7kb | 2024-08-04 20:51:25 | 2024-08-04 20:51:26 |
Judging History
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;
if (n == m) {
for (int i = 1; i <= n; i ++) {
ans.push_back({i, 1});
}
for (int i = 2; i <= n - 1; i ++) {
ans.push_back({i, m});
}
} else if (n & 1) {
for (int i = 1; i <= n; i ++) {
ans.push_back({i, 1});
}
for (int i = 1; i <= n; i ++) {
ans.push_back({i, m});
}
int l = n / 2 + 2, r = m - (n / 2 + 1);
for (int j = l; j <= r; j ++) {
ans.push_back({n / 2 + 1, j});
}
} else {
for (int i = 1; i <= n; i ++) {
ans.push_back({i, 1});
}
for (int i = 1; i <= n; i ++) {
ans.push_back({i, m});
}
int l = n / 2 + 2, r = m - (n / 2 + 1);
for (int j = l; j <= n / 2; j += 2) {
ans.push_back({n / 2, j});
ans.push_back({n / 2 + 1, j});
}
for (int j = r; j >= n / 2 + 1; j -= 2) {
ans.push_back({n / 2, j});
ans.push_back({n / 2 + 1, j});
}
}
std::cout << ans.size() << '\n';
std::vector a(n + 5, std::vector<int> (m + 5, 0));
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
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: 3524kb
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
Memory Limit Exceeded
input:
100000 100000