QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#150491#5420. InscryptionMiguel0312WA 166ms3532kbC++201.2kb2023-08-25 17:59:052023-08-25 17:59:06

Judging History

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

  • [2023-08-25 17:59:06]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:3532kb
  • [2023-08-25 17:59:05]
  • 提交

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 + 1);
		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;
		}
		mini[n] = b - a;
		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;
					mini[i]++;
				}
				m = max(m, mini[i]);
				// cout << m << endl;
				if ((c - c2) < m)
					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';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: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1
-1
2 1
-1
-1
6 1
1 0
1 0
3 2
-1
-1
-1
-1
2 1
5 3
-1
5 4
2 1
-1
3 2
5 1
1 1
-1
1 0
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
1 0
-1
-1
-1
-1
3 2
1 0
1 1
-1
1 0
-1
-1
1 1
-1
4 -3
3 2
-1
3 2
4 3
2 1
-1
5 3
1 0
-5 1
-1
2 1
2 1
-1
1 1
-1
3 1
-1
-1
4 1
1 1
2 1
5 2
-1
3 1
4...

result:

wrong answer 18th lines differ - expected: '3 2', found: '1 0'