QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250765#5420. Inscryptioncscnk52WA 0ms3696kbC++14914b2023-11-13 17:06:282023-11-13 17:06:29

Judging History

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

  • [2023-11-13 17:06:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2023-11-13 17:06:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e6 + 7;
int a[N];
int gcd(int x, int y) {
	return x ? gcd(y % x, x) : y;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int cnt = 0;
		int ans1 = 1, ans2 = 1;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1) {
				ans1++;
				ans2++;
			} else if (a[i] == -1) {
				if (ans2 >= 2) {
					ans2--;
				} else if (cnt >= 1) {
					cnt--;
					ans1++;
					ans2++;
				} else {
					cout << -1 << '\n';
					continue;
				}
			} else {
				if (ans2 >= 2) {
					ans2--;
					cnt++;
				} else {
					ans1++;
					ans2++;
				}
			}
		}
		int g = gcd(ans1, ans2);
		cout << ans1 / g << ' ' << ans2 / g << '\n';
	}

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3696kb

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

result:

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