QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657595#9251. Graph ChangingFiatiustitia#WA 0ms3912kbC++174.0kb2024-10-19 15:02:352024-10-19 15:02:44

Judging History

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

  • [2024-10-19 15:02:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3912kb
  • [2024-10-19 15:02:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int T;
inline int read()
{
    int ret = 0;
    char ch = getchar();
    bool flg = 0;
    while (!isdigit(ch))
        flg ^= !(ch ^ '-'), ch = getchar();
    while (isdigit(ch))
        ret = (ret << 3) + (ret << 1) + ch - 48, ch = getchar();
    return flg ? -ret : ret;
}
bool check(int k, int x, int y, int n)
{
    if (y - x >= k)
    {
        // printf("1\n");
        return 0;
    }
    if (x >= k + 1 || y + k <= n)
    {
        // printf("2\n");
        return 0;
    }
    // x n 1 y

    if (n - x >= k && y - 1 >= k)
    {
        // printf("3\n");
        return 1;
    }
    // printf("-1\n");
    return 0;
}
void solve()
{
    int t = read(), n = read(), k = read(), x = read(), y = read();
    if (x > y)
        swap(x, y);
    if (t == 0)
    {
        printf("%d\n", (y - x));
        return;
    }
    if (k == 1)
    {
        printf("%d\n", 1);
        return;
    }
    if (k == 2)
    {
        if (n <= 3)
        {
            if (t == 1 && x == 1 && y == 3)
            {
                printf("1\n");
                return;
            }
            printf("-1\n");
            return;
        }
        t &= 1;
        if (t == 0)
        {
            printf("%d\n", (y - x));
            return;
        }
        else
        {
            if (y - x >= k)
            {
                printf("1\n");
                return;
            }
            if (x >= k + 1 || y + k <= n)
            {
                printf("2\n");
                return;
            }
            // x n 1 y

            if (n - x >= k && y - 1 >= k)
            {
                printf("3\n");
                return;
            }
            printf("-1\n");
            return;
        }
        return;
    }
    if (k == 3)
    {
        if (t >= 3)
        {
            printf("-1\n");
            return;
        }
        if (t == 1)
        {
            if (y - x >= k)
            {
                printf("1\n");
                return;
            }
            if (x >= k + 1 || y + k <= n)
            {
                printf("2\n");
                return;
            }
            // x n 1 y

            if (n - x >= k && y - 1 >= k)
            {
                printf("3\n");
                return;
            }
            printf("-1\n");
            return;
        }
        if (t == 2)
        {
            if ((x == 2 && y == 3) || (x == 2 && y == 4) || (x == 3 && y == 4) || (x == 3 && y == 5))
            {
                if (check(k, x, y, n))
                {
                    printf("1\n");
                    return;
                }
            }
            if (x == 2 && y == 5)
            {
                if (check(k, 2, 3, n) && check(k, 3, 5, n))
                {
                    printf("2\n");
                    return;
                }
                if (check(k, 2, 4, n) && check(k, 3, 4, n) && check(k, 3, 5, n))
                {
                    printf("3\n");
                    return;
                }
            }
            printf("-1\n");
            return;
        }
    }
    if (k >= 4)
    {
        if (t >= 2)
        {
            printf("-1\n");
            return;
        }
        if (y - x >= k)
        {
            printf("1\n");
            return;
        }
        if (x >= k + 1 || y + k <= n)
        {
            printf("2\n");
            return;
        }
        // x n 1 y

        if (n - x >= k && y - 1 >= k)
        {
            printf("3\n");
            return;
        }
        printf("-1\n");
        return;
    }
}
int main()
{
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
    auto _ = clock();
#endif
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    T = read();

    while (T--)
        solve();
#ifdef LOCAL
    cerr << clock() - _ << '\n';
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 5 3 2 4
1 10 4 2 4
2 10 5 2 4
1 3 2 1 3
1 3 2 1 2

output:

3
2
-1
1
-1

result:

ok 5 lines

Test #2:

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

input:

30
1 2 1 1 2
1 2 2 1 2
1 2 3 1 2
1 2 4 1 2
1 2 5 1 2
1 2 6 1 2
2 2 1 1 2
2 2 2 1 2
2 2 3 1 2
2 2 4 1 2
2 2 5 1 2
2 2 6 1 2
3 2 1 1 2
3 2 2 1 2
3 2 3 1 2
3 2 4 1 2
3 2 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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300 lines

Test #6:

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

input:

450
1 6 1 1 2
1 6 1 1 3
1 6 1 1 4
1 6 1 1 5
1 6 1 1 6
1 6 1 2 3
1 6 1 2 4
1 6 1 2 5
1 6 1 2 6
1 6 1 3 4
1 6 1 3 5
1 6 1 3 6
1 6 1 4 5
1 6 1 4 6
1 6 1 5 6
1 6 2 1 2
1 6 2 1 3
1 6 2 1 4
1 6 2 1 5
1 6 2 1 6
1 6 2 2 3
1 6 2 2 4
1 6 2 2 5
1 6 2 2 6
1 6 2 3 4
1 6 2 3 5
1 6 2 3 6
1 6 2 4 5
1 6 2 4 6
1 6 2 ...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
2
3
1
1
3
3
1
2
2
2
2
-1
-1
1
1
-1
-1
3
1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
3
4
5
1
2
3
4
1
2
3
1
2
1
-1
-1
-1
-1
-1
-1
1
3
...

result:

wrong answer 126th lines differ - expected: '2', found: '-1'