QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763904#9251. Graph ChangingzhangshiyanRE 0ms0kbC++142.3kb2024-11-19 22:42:052024-11-19 22:42:10

Judging History

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

  • [2024-11-19 22:42:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-19 22:42:05]
  • 提交

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

output:


result: