QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657739 | #9251. Graph Changing | Fiatiustitia# | WA | 0ms | 3964kb | C++17 | 4.3kb | 2024-10-19 15:22:40 | 2024-10-19 15:22:41 |
Judging History
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 == 4) || (x == 3 && y == 4) || (x == 3 && y == 5))
{
if (check(k, x, y, n))
{
printf("1\n");
return;
}
}
if (x == 2 && y == 3)
{
if (check(k, 2, 4, n) && check(k, 3, 4, n))
{
printf("2\n");
return;
}
}
if (x == 4 && y == 5)
{
if (check(k, 3, 4, n) && check(k, 3, 5, n))
{
printf("2\n");
return;
}
}
if (x == 2 && y == 5)
{
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
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: 3840kb
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 5 1 2 3 2 6 1 2 4 2 1 1 2 4 2 2 1 2 4 2 3 1 2 4 2 4 1 2 4 2 5 1 2 4 2 6 1 2 5 2 1 1 2 5 2 2 1 2 5 2 3 1 2 5 2 4 1 2 5 2 5 1 2 5 2 6 1 2
output:
1 -1 -1 -1 -1 -1 1 -1 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