QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#445676#8528. Chordsucup-team3924WA 0ms3832kbC++202.8kb2024-06-16 07:38:212024-06-16 07:38:22

Judging History

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

  • [2024-06-16 07:38:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-06-16 07:38:21]
  • 提交

answer

#include <bits/stdc++.h>

int dist(int a, int b, int N) {
    if (a <= b) return b - a;
    return N - (a - b);
}

int main() {
    std::cin.tie(NULL);
    std::iostream::sync_with_stdio(false);

    int N;

    std::cin >> N;

    std::vector<int> link(2 * N);

    for (int i = 0; i < N; i++) {
        int x, y;
        std::cin >> x >> y;
        x--;y--;
        link[x] = y;
        link[y] = x;
    }

    std::vector<std::vector<int>> dp(1, std::vector<int>(2 * N, -1));

    std::vector<int> best_ans(2 * N, 1);

    for (int i = 0; i < 2 * N; i++) {
        dp[0][i] = i;
    }

    int res = 0, ans = 1;
    bool compute = true;

    while (compute) {
        dp.push_back(std::vector<int>(2 * N, -1));

        for (int i = 0; i < 2 * N; i++) {
            int j = link[i];
            int x = (i + 1) % (2 * N);
            int y = dp[ans - 1][x];

            if (ans == 1)
                dp[ans][i] = j;
            else if (y != -1 && dist(i, j, 2 * N) == dist(i, x, 2 * N) + dist(x, y, 2 * N) + dist(y, j, 2 * N)) {
                dp[ans][i] = j;
            }
        }

        for (int i = 0; i < 2 * N; i++) {
            bool computable = false;
            while (computable && best_ans[i] < ans) {
                int ansp = best_ans[i];
                int j = dp[ansp][i];

                if (j == -1) {
                    computable = false;
                    break;
                }

                int x = (j + 1) % (2 * N);
                int y = dp[ans - ansp][x];

                if (x != i && y != i && y != -1 && dist(j, i, 2 * N) == dist(j, x, 2 * N) + dist(x, y, 2 * N) + dist(y, i, 2 * N)) {
                    if (dp[ans][i] == -1)
                        dp[ans][i] = y;
                    else if (dist(i, y, 2 * N) <= dist(i, dp[ans][i], 2 * N))
                        dp[ans][i] = y;
                    best_ans[i]++;
                } else
                    computable = false;
            }
        }

        for (int _i = 4 * N - 1; _i >= 0; _i--) {
            int i = _i % (2 * N);
            int inext = (i + 1) % (2 * N);

            if (dp[ans][i] == -1 && dp[ans][inext] != i)
                dp[ans][i] = dp[ans][inext];
            else if (dp[ans][inext] != -1 && dp[ans][inext] != i && dist(i, dp[ans][inext], 2 * N) <= dist(i, dp[ans][i], 2 * N))
                dp[ans][i] = dp[ans][inext];
        }

        //std::cerr << ans << ": \n";

        compute = false;
        for (int i = 0; i < 2 * N; i++)
            if (dp[ans][i] != -1) {
                res = ans;
                compute = true;
                //std::cerr << i + 1 << " -> " << dp[ans][i] + 1 << "\n";
            }
        ans++;
    }

    std::cout << res;

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2
4 10
7 9
3 5
6 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1 3
2 4

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
1 4
2 3

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

3
3 5
1 4
2 6

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

4
2 7
1 6
3 8
4 5

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3520kb

input:

6
8 9
6 7
4 10
1 5
11 12
2 3

output:

3

result:

wrong answer 1st numbers differ - expected: '5', found: '3'