QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763938#9251. Graph ChangingzhangshiyanWA 1ms3688kbC++202.2kb2024-11-19 22:53:122024-11-19 22:53:12

Judging History

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

  • [2024-11-19 22:53:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3688kb
  • [2024-11-19 22:53:12]
  • 提交

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

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: 100
Accepted
time: 0ms
memory: 3636kb

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

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
-1
-1

result:

ok 30 lines

Test #3:

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

input:

90
1 3 1 1 2
1 3 1 1 3
1 3 1 2 3
1 3 2 1 2
1 3 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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'