QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#763904 | #9251. Graph Changing | zhangshiyan | RE | 0ms | 0kb | C++14 | 2.3kb | 2024-11-19 22:42:05 | 2024-11-19 22:42:10 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18
inline ll read()
{
ll x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9')
{
if(c == '-')
{
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
ll t, n, k, x, y;
void calc()
{
if(llabs(x - y) >= k)
{
cout << 1 << endl;
}
else if(x - k >= 1 || y + k <= n)
{
cout << 2 << endl;
}
else if(x + k <= n && y - k >= 1)
{
cout << 3 << endl;
}
else
{
cout << -1 << endl;
}
}
void run()
{
t = read(), n = read(), k = read(), x = read(), y = read();
if(x > y)
{
swap(x, y);
}
else if(k == 1)
{
if(t)
{
cout << 1 << endl;
}
else
{
cout << y - x << endl;
}
}
else if(k == 2)
{
if(t >= 1 && n <= 3)
{
if(t == 1 && x == 1 && y == 3)
{
cout << 1 << endl;
}
else
{
cout << -1 << endl;
}
}
else if(t % 2)
{
calc();
}
else
{
cout << y - x << endl;
}
}
else if(k == 3)
{
if(t > 3)
{
cout << -1 << endl;
}
else if(t == 3)
{
if(n == 6 && x == 2 && y == 5)
{
cout << 1 << endl;
}
else
{
cout << -1 << endl;
}
}
else if(t == 2)
{
if(n == 5 && x == 2 && y == 4)
{
cout << 1 << endl;
}
else if(n == 6 && x != 1 && y != 6)
{
if(x == 2 && y == 4)
{
cout << 1 << endl;
}
else if(x == 3 && y == 4)
{
cout << 1 << endl;
}
else if(x == 3 && y == 4)
{
cout << 2 << endl;
}
else if(x == 4 && y == 5)
{
cout << 2 << endl;
}
else if(x == 2 && y == 5)
{
cout << 3 << endl;
}
}
else if(n == 7 && x == 3 && y == 5)
{
cout << 1 << endl;
}
else
{
cout << -1 << endl;
}
}
else if(t == 1)
{
calc();
}
else
{
cout << y - x << endl;
}
}
else
{
if(t > 1)
{
cout << -1 << endl;
}
else if(t == 1)
{
calc();
}
else
{
cout << y - x << endl;
}
}
}
int main()
{
#ifndef debug
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
#endif
ll q = read();
while(q--)
{
run();
}
return 0;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
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