QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405465#5420. InscryptionFOY#WA 443ms3752kbC++171005b2024-05-05 23:49:122024-05-05 23:49:14

Judging History

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

  • [2024-05-05 23:49:14]
  • 评测
  • 测评结果:WA
  • 用时:443ms
  • 内存:3752kb
  • [2024-05-05 23:49:12]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll ZERO = 0;

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 swaps = max(ZERO, d - cnt[1]);

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

		if (a[i] == 1) {
			num_b++;
			tot_a++;
		} 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();
	}

}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 443ms
memory: 3752kb

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

result:

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