QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684159#5420. InscryptionnageingWA 178ms3832kbC++201.3kb2024-10-28 11:01:202024-10-28 11:01:21

Judging History

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

  • [2024-10-28 11:01:21]
  • 评测
  • 测评结果:WA
  • 用时:178ms
  • 内存:3832kb
  • [2024-10-28 11:01:20]
  • 提交

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 T) {
	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]] ++;
	}
	if (T == 28) {
		cout << n << '\n';
		for (int i = 0; i < n; i ++) {
			cout << a[i] << " \n"[i == n - 1];
		}
		return;
	}

	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 --;
					p ++;
				} 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;
	for (int i = 1; i <= t; i ++) {
		solve(i);
	}
	return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 178ms
memory: 3832kb

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
1
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
0
1
0
1
-1
1
0
1
-1
1
0
1
0
1
0
1
0
1
0
1
-1
1
1
1
0
1
0
1
1
1
0
1
-1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
...

output:

1 1
-1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
-1
1
0
1 1
1 1
-1
1 1
-1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
-1
-1
-1
1 1
1 1
-1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 ...

result:

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