QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684137#5420. InscryptionnageingWA 175ms3628kbC++201.1kb2024-10-28 10:49:282024-10-28 10:49:28

Judging History

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

  • [2024-10-28 10:49:28]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:3628kb
  • [2024-10-28 10:49:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

bool chmin(int &a, int b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> cnt;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		cnt[a[i]] ++;
	}


	int p = 1, q = 1, t = 0;
	for (int i = 0; i < n; i ++) {
		if (a[i] == 1) {
			p ++;
			q ++;
		} else if (a[i] == -1) {
			if (q + t < 2) {
				cout << -1 << '\n';
				return;
			} else {
				if (q < 2) {
					t --;
				} else {
					q --;
				}
			}
		} else {
			t ++;
		}
	}
	//cout << p << ' ' << q << ' ' << t << '\n';
	if (q - 1 >= t) {
		q = q - t;
	} else {
		if ((q + t) % 2) {
			
			p = p + (q + t + 1) / 2  - q;
			q = 1; 
		} else {
			//cout << "there\n";
			
			p = p + (q + t + 2) / 2 - q;
			q = 2;
		}
	}
	//cout << p << ' ' << q << '\n';
	int g = __gcd(p, q);
	cout << p / g << ' ' << q / g << "\n";

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t --) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

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: 175ms
memory: 3628kb

input:

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

result:

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