QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#301516#2731. Cartesian ConquestCamillus0 283ms1659092kbC++201.8kb2024-01-10 00:41:392024-01-10 00:41:40

Judging History

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

  • [2024-01-10 00:41:40]
  • 评测
  • 测评结果:0
  • 用时:283ms
  • 内存:1659092kb
  • [2024-01-10 00:41:39]
  • 提交

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;
    }
};

int fff(int n, int m) {
    return n ^ m;
}

unordered_map<int, int> saved_mx;

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

    if (saved_mx.contains(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;
}

unordered_map<int, int>  saved_mn;

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

    if (saved_mn.contains(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);

    saved_mn.reserve(1e8);
    saved_mx.reserve(1e8);
    
    int n, m;
    cin >> n >> m;

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

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 192ms
memory: 1588560kb

input:

2 1

output:

1 1

result:

ok single line: '1 1'

Test #2:

score: 0
Accepted
time: 175ms
memory: 1588420kb

input:

2 4

output:

1 4

result:

ok single line: '1 4'

Test #3:

score: 0
Accepted
time: 180ms
memory: 1588692kb

input:

5 4

output:

4 4

result:

ok single line: '4 4'

Test #4:

score: 0
Accepted
time: 199ms
memory: 1588436kb

input:

4 6

output:

3 6

result:

ok single line: '3 6'

Test #5:

score: 0
Accepted
time: 268ms
memory: 1588848kb

input:

1000 2

output:

250 1000

result:

ok single line: '250 1000'

Test #6:

score: 0
Accepted
time: 272ms
memory: 1588664kb

input:

1 1000

output:

500 500

result:

ok single line: '500 500'

Test #7:

score: 0
Accepted
time: 247ms
memory: 1588520kb

input:

1000 1000

output:

2 8

result:

ok single line: '2 8'

Test #8:

score: -5
Wrong Answer
time: 283ms
memory: 1588512kb

input:

872 976

output:

10 115

result:

wrong answer 1st lines differ - expected: '11 133', found: '10 115'

Subtask #2:

score: 0
Wrong Answer

Test #20:

score: 8
Accepted
time: 207ms
memory: 1588832kb

input:

2 1001

output:

251 1001

result:

ok single line: '251 1001'

Test #21:

score: 0
Accepted
time: 276ms
memory: 1659092kb

input:

1 1000000

output:

500000 500000

result:

ok single line: '500000 500000'

Test #22:

score: -8
Wrong Answer
time: 207ms
memory: 1588664kb

input:

1000000 1000000

output:

2 38

result:

wrong answer 1st lines differ - expected: '2 25', found: '2 38'

Subtask #3:

score: 0
Memory Limit Exceeded

Test #45:

score: 0
Memory Limit Exceeded

input:

100000000 2

output:


result: