QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150407#5420. InscryptionMiguel0312WA 170ms3744kbC++201.2kb2023-08-25 16:56:422023-08-25 16:56:45

Judging History

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

  • [2023-08-25 16:56:45]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:3744kb
  • [2023-08-25 16:56:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define INF 1000000001

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		int a = 0, b = 0, c = 0, x, sum = 0, cnt = 1;
		bool possible = true;
		vector<int> numbers(n), mini(n);
		for (int i = 0; i < n; i++)
		{
			cin >> numbers[i];
			if (numbers[i] == 1)
				a++;
			else if (numbers[i] == -1)
				b++;
			else
				c++;
			if (a + c + 1 - b == 0)
				possible = false;
			mini[i] = b - a - c;
			if (numbers[i] == 0)
				mini[i]++;
		}
		if (possible)
		{
			sum = a + c + 1;
			cnt = 1 + a + c - b;
			int a2 = 0, b2 = 0, c2 = 0, m = -INF;
			for (int i = n - 1; i >= 0; i--)
			{
				if (numbers[i] == 1)
					a2++;
				else if (numbers[i] == -1)
					b2++;
				else
				{
					c2++;
					m += 2;
				}
				m = max(m, mini[i] + 2 * c2);
				if (c - c2 < m)
				{
					// cout << i << endl;
					break;
				}
				sum = a + (c - c2) + 1;
				cnt = 1 + a + (c - c2) - c2 - b;
			}
		}

		if (!possible)
		{
			cout << -1 << '\n';
			continue;
		}

		int g = __gcd(sum, cnt);
		cout << sum / g << ' ' << cnt / g << '\n';
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3744kb

input:

6
7
1 1 1 -1 1 1 -1
4
1 0 -1 0
4
0 -1 -1 0
1
0
2
0 0
1
-1

output:

3 2
3 1
-1
1 1
2 1
-1

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 170ms
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7 3
3 2
3 1
3 2
-1
-1
-1
-1
1 1
6 5
-1
5 4
1 1
-1
3 2
5 1
1 1
-1
3 2
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
1 0
-1
-1
-1
-1
3 2
5 2
1 1
-1
1 0
-1
-1
1 1
-1
6 1
1 1
-1
3 2
4 3
2 1
-1
5 3
3 1
6 1
-1
2 1
5 4
-1
1 1
-1
3 1
-1
-1
4 1
1 1
2 1
5 2
-1
4 3
4 3...

result:

wrong answer 1st lines differ - expected: '4 1', found: '5 3'