QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301524#2731. Cartesian ConquestCamillus5 63ms92916kbC++201.7kb2024-01-10 00:49:102024-01-10 00:49:11

Judging History

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

  • [2024-01-10 00:49:11]
  • 评测
  • 测评结果:5
  • 用时:63ms
  • 内存:92916kb
  • [2024-01-10 00:49:10]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

struct pair_hash {
    size_t operator()(const pair<int, int> &p) const {
        return p.first ^ p.second;
    }
};

static constexpr int maxn = 200000131;

int fff(int n, int m) {
    return ((1ll * n) << 26 | m) % maxn;
}

int saved_mx[maxn];

int mx_func(int n, int m) {
    if (n > m) {
        swap(n, m);
    }

    if (saved_mx[fff(n, m)]) {
        return saved_mx[fff(n, m)];
    }

    int cur = 0;

    if (n % 2 == 0 && m - n / 2 > 0) {
        cur = max(cur, mx_func(n, m - n / 2));
    }

    if (m % 2 == 0 && n - m / 2 > 0) {
        cur = max(cur, mx_func(n - m / 2, m));
    }

    if (m - 2 * n > 0) {
        cur = max(cur, mx_func(n, m - 2 * n));
    }

    if (n - 2 * m > 0) {
        cur = max(cur, mx_func(n - 2 * m, m));
    }

    return saved_mx[fff(n, m)] = cur + 1;
}

int saved_mn[maxn];

int mn_func(int n, int m) {
    if (n > m) {
        swap(n, m);
    }

    if (saved_mn[fff(n, m)]) {
        return saved_mn[fff(n, m)];
    }

    if (n == 2 * m || m == 2 * n) {
        return 1;
    }

    int cur = INT32_MAX;

    if (n % 2 == 0 && m - n / 2 > 0) {
        cur = min(cur, mn_func(n, m - n / 2));
    }

    if (m % 2 == 0 && n - m / 2 > 0) {
        cur = min(cur, mn_func(n - m / 2, m));
    }

    if (m - 2 * n > 0) {
        cur = min(cur, mn_func(n, m - 2 * n));
    }

    if (n - 2 * m > 0) {
        cur = min(cur, mn_func(n - 2 * m, m));
    }

    return saved_mn[fff(n, m)] = cur + 1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;

    cout << mn_func(n, m) << ' ' << mx_func(n, m) << '\n';
    return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3600kb

input:

2 1

output:

1 1

result:

ok single line: '1 1'

Test #2:

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

input:

2 4

output:

1 4

result:

ok single line: '1 4'

Test #3:

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

input:

5 4

output:

4 4

result:

ok single line: '4 4'

Test #4:

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

input:

4 6

output:

3 6

result:

ok single line: '3 6'

Test #5:

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

input:

1000 2

output:

250 1000

result:

ok single line: '250 1000'

Test #6:

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

input:

1 1000

output:

500 500

result:

ok single line: '500 500'

Test #7:

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

input:

1000 1000

output:

2 8

result:

ok single line: '2 8'

Test #8:

score: 0
Accepted
time: 2ms
memory: 4248kb

input:

872 976

output:

11 133

result:

ok single line: '11 133'

Test #9:

score: 0
Accepted
time: 1ms
memory: 4284kb

input:

768 992

output:

8 124

result:

ok single line: '8 124'

Test #10:

score: 0
Accepted
time: 1ms
memory: 4208kb

input:

960 896

output:

6 85

result:

ok single line: '6 85'

Test #11:

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

input:

832 992

output:

6 182

result:

ok single line: '6 182'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3660kb

input:

26 7

output:

8 8

result:

ok single line: '8 8'

Test #13:

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

input:

38 71

output:

7 30

result:

ok single line: '7 30'

Test #14:

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

input:

52 22

output:

5 17

result:

ok single line: '5 17'

Test #15:

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

input:

18 74

output:

6 26

result:

ok single line: '6 26'

Test #16:

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

input:

63 88

output:

12 12

result:

ok single line: '12 12'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

378 251

output:

11 43

result:

ok single line: '11 43'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

981 122

output:

12 52

result:

ok single line: '12 52'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

410 478

output:

10 82

result:

ok single line: '10 82'

Subtask #2:

score: 0
Wrong Answer

Test #20:

score: 8
Accepted
time: 0ms
memory: 3716kb

input:

2 1001

output:

251 1001

result:

ok single line: '251 1001'

Test #21:

score: 0
Accepted
time: 11ms
memory: 50540kb

input:

1 1000000

output:

500000 500000

result:

ok single line: '500000 500000'

Test #22:

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

input:

1000000 1000000

output:

2 25

result:

ok single line: '2 25'

Test #23:

score: 0
Accepted
time: 4ms
memory: 6912kb

input:

80400 64364

output:

18 622

result:

ok single line: '18 622'

Test #24:

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

input:

5290 4513

output:

15 633

result:

ok single line: '15 633'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

663518 314601

output:

82 148

result:

ok single line: '82 148'

Test #26:

score: -8
Wrong Answer
time: 63ms
memory: 92916kb

input:

913836 913838

output:

34 913829

result:

wrong answer 1st lines differ - expected: '34 913838', found: '34 913829'

Subtask #3:

score: 0
Runtime Error

Test #45:

score: 0
Runtime Error

input:

100000000 2

output:


result: