QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763957#9251. Graph ChangingzhangshiyanWA 1ms3644kbC++202.4kb2024-11-19 22:59:492024-11-19 22:59:49

Judging History

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

  • [2024-11-19 22:59:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3644kb
  • [2024-11-19 22:59:49]
  • 提交

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 == 0)
		{
			cout << y - x << endl;
		}
		else 
		{
			cout << 1 << endl;
		}
	}
	else if(k == 2)
	{
		if(t == 0)
		{
			cout << y - x << endl;
		}
		else if(n <= 3)
		{
			if(t == 1 && x == 1 && y == 3)
			{
				cout << 1 << endl;
			}
			else
			{
				cout << -1 << endl;
			}
		}
		else if(t & 1)
		{
			calc();
		}
	}
	else if(k == 3)
	{
		if(t == 0)
		{
			cout << y - x << endl;
		}
		else if(t == 1)
		{
			calc();
		}
		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 == 5)
				{
					cout << 1 << endl;
				}
				else if(x == 2 && y == 3)
				{
					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 == 3)
		{
			if(n == 6 && x == 2 && y == 5)
			{
				cout << 1 << endl;
			}
			else
			{
				cout << -1 << endl;
			}
		}
		else
		{
			cout << -1 << endl;
		}
	}
	else
	{
		if(t == 0)
		{
			cout << y - x << endl;
		}
		else if(t == 1)
		{
			calc();
		}
		else
		{
			cout << -1 << endl;
		}
	}
}

int main()
{
//#ifndef debug
//	freopen("graph.in", "r", stdin);
//	freopen("graph.out", "w", stdout);
//#endif
	ll q = read();
	while(q--)
	{
		run();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3616kb

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
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-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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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
2
1
1
3
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
-...

result:

wrong answer 43rd lines differ - expected: '1', found: '-1'