QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720861#5420. InscryptionRepeater#WA 171ms3596kbC++20855b2024-11-07 14:30:442024-11-07 14:30:44

Judging History

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

  • [2024-11-07 14:30:44]
  • 评测
  • 测评结果:WA
  • 用时:171ms
  • 内存:3596kb
  • [2024-11-07 14:30:44]
  • 提交

answer

#include <bits/stdc++.h>

constexpr int INF = 1e9;

void solve()
{
	int n; std::cin >> n;
	std::vector<int> a(n), s(n + 1);
	for(int i = 0; i < n; i++) std::cin >> a[i];
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + (a[i] == -1 ? -1 : 1);

	int min = INF;
	for(int i = 1; i <= n; i++) min = std::min(min, s[i]);

	if(min < 0)
	{
		std::cout << -1 << "\n";
		return;
	}
	min = s[n] / 2;

	int tot = std::ranges::count(a, 0);
	int x = 1, y = 1;
	for(int i = 0; i < n; i++)
	{
		if(a[i] == 1) x++, y++;
		else if(a[i] == -1) y--;
		else
		{
			if(tot > min) x++, y++, tot--;
			else y--;
		}
	}

	int g = std::gcd(x, y);
	x /= g, y /= g;

	std::cout << x << " " << y << "\n";
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t; std::cin >> t;
	while(t--) solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 171ms
memory: 3540kb

input:

1000000
1
1
1
-1
1
1
1
1
1
1
1
1
1
-1
1
-1
1
0
1
0
1
1
1
0
1
-1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
1
1
-1
1
1
1
1
1
-1
1
0
1
1
1
0
1
-1
1
0
1
-1
1
1
1
-1
1
0
1
1
1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
5 3
3 1
6 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
3 1...

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'