QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183330#7178. BishopsScarlett_boyWA 21ms17296kbC++172.8kb2023-09-19 13:43:182023-09-19 13:43:19

Judging History

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

  • [2023-09-19 13:43:19]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:17296kb
  • [2023-09-19 13:43:18]
  • 提交

answer

#include "bits/stdc++.h"

typedef long long ll;
using namespace std;


int n, m;
vector<pair<int, int>> vec;

void dfs(int a, int b, int x, int y) {
    if (x == y) {
        for (int i = b; i < b + y; i++) vec.emplace_back(a, i);
        for (int i = b + 1; i < b + y - 1; i++) vec.emplace_back(a + x - 1, i);
        return;
    }
    if (x > y) {
        if (x > 2 * y) {
            for (int i = 0; i < y; i++) vec.emplace_back(a, b + i);
            dfs(a + y, b, x - y, y);
        } else {
            if (x == 2 * y) {
                for (int i = 0; i < y; i++) vec.emplace_back(a, b + i);
                for (int i = 0; i < y; i++) vec.emplace_back(a + x - 1, b + i);
                int A = x / 2 - 1;
                for (int i = 1; i < b - 1; i += 2) {
                    vec.emplace_back(a + A, b + i);
                    vec.emplace_back(a + A + 1, b + i);
                }
            } else if (x == 2 * y - 1) {
                for (int i = 0; i < y; i++) vec.emplace_back(a, b + i);
                for (int i = 0; i < y; i++) vec.emplace_back(a + x - 1, b + i);
                for (int i = 1; i < b - 1; i++) {
                    vec.emplace_back(a + x / 2, b + i);
                }
            } else {
                for (int i = 0; i < y; i++) vec.emplace_back(a, b + i);
                dfs(a + y, b, x - y, y);
            }
        }
    }
    if (x < y) {
        if (y > 2 * x) {
            for (int i = 0; i < x; i++) vec.emplace_back(a + i, b);
            dfs(a, b + x, x, y - x);
        } else {
            if (y == 2 * x) {
                for (int i = 0; i < x; i++) vec.emplace_back(a + i, b);
                for (int i = 0; i < x; i++) vec.emplace_back(a + i, b + y - 1);
                int B = y / 2 - 1;
                for (int i = 1; i < x - 1; i += 2) {
                    vec.emplace_back(a + i, b + B);
                    vec.emplace_back(a + i, b + B + 1);
                }
            } else if (y == 2 * x - 1) {
                for (int i = 0; i < x; i++) vec.emplace_back(a + i, b);
                for (int i = 0; i < x; i++) vec.emplace_back(a + i, b + y - 1);
                for (int i = 1; i < a - 1; i++) {
                    vec.emplace_back(a + i, b + y / 2);
                }
            } else {
                for (int i = 0; i < x; i++) vec.emplace_back(a + i, b);
                dfs(a, b + x, x, y - x);
            }
        }
    }
}

void solve() {
    cin >> n >> m;
    dfs(1, 1, n, m);
    cout << vec.size() << '\n';
    for (auto [a, b]: vec) {
        cout << a << ' ' << b << '\n';
    }
}


signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int _ = 1;
//    cin >> _;
    for (int o = 1; o <= _; o++) {
        solve();
    }
    return 0;
}
/*


33333 99999
133331
 */

详细

Test #1:

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

input:

2 5

output:

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

result:

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

Test #2:

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

input:

5 5

output:

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

result:

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

Test #3:

score: 0
Accepted
time: 19ms
memory: 5300kb

input:

100000 100000

output:

199998
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

result:

ok n: 100000, m: 100000, bishops: 199998

Test #4:

score: 0
Accepted
time: 21ms
memory: 17296kb

input:

100000 99999

output:

199998
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

result:

ok n: 100000, m: 99999, bishops: 199998

Test #5:

score: -100
Wrong Answer
time: 6ms
memory: 4160kb

input:

100000 50000

output:

100000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

result:

wrong answer Participant's answer is not optimal (100000 < 149998)