QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405460#5420. InscryptionFOY#WA 459ms3580kbC++171.1kb2024-05-05 23:33:092024-05-05 23:33:10

Judging History

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

  • [2024-05-05 23:33:10]
  • 评测
  • 测评结果:WA
  • 用时:459ms
  • 内存:3580kb
  • [2024-05-05 23:33:09]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

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

	ll tot = cnt[-1] + cnt[0] + cnt[1];
	ll d = tot / 2;
	if (tot & 1) {
		d = tot / 2 + 1;
	}

	ll d1 = d - cnt[1];
	if (d1 > 0) {
		cnt[1] += min(cnt[0], d1);
		cnt[0] -= min(cnt[0], d1);
	}

	cnt[-1] += cnt[0];
	cnt[0] = 0;

	// cout << cnt[1] << " " << cnt[-1] << endl;

	ll num_b = 1, tot_a = 1;
	for (ll i = 0; i < n; i++) {
		if (a[i] == 0 && cnt[1] > 0) {
			a[i] = 1;
		} 
		if (a[i] == 0 && cnt[1] == 0) {
			a[i] == -1;
		}

		if (a[i] == 1) {
			num_b++;
			tot_a++;

			cnt[1]--;
		} else {
			num_b--;
		}

		// cout << "A " << tot_a << " " << num_b << endl;

		if (num_b <= 0) {
			cout << -1 << endl;
			return;
		}
	}

	ll g = gcd(num_b, tot_a);

	cout << tot_a / g << " " << num_b / g << endl;

	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll t;
	cin >> t;

	while (t--) {
		solve();
	}

}



详细

Test #1:

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

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

result:

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