QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277586#5420. InscryptionyimonRE 0ms0kbC++231.1kb2023-12-06 20:25:032023-12-06 20:25:04

Judging History

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

  • [2023-12-06 20:25:04]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-06 20:25:03]
  • 提交

answer

#include<iostream>
#include<map>
#include<cmath>
#include<algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define int long long
ll n;
ll a[1000010], b[1000010];
ll po[1000010];
bool f;
signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		f = 1;
		ll res = -1;
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
		ll pos, cnt3 = 0;
		for (int i = 1; i <= n; i++)
		{
			if (a[i] == 0)
			{
				cnt3++;
				po[cnt3] = i;
				a[i] = -1;
			}
		}
		ll att =1, num = 1;
		ll i = 0;
		ll cnt = 1;
		ll cnt0 = 0;
		while(i<n)
		{
			i++;
			if (a[i] == 1)
			{
				att++; num++;
			}
			else if (a[i] == -1)
			{
				num--;
			}
			if (b[i] == 0) cnt0++;
			if (num <= 0)
			{
				res = -1;
				cnt = cnt0;
				while (a[po[cnt0]] == 1 || a[po[cnt0]] == 0)
				{
					cnt0--;
				}
				if (cnt0 >= 1)
				{
					res = 1;
					a[po[cnt0]] = 0;
					att++; num += 2;
					cnt0 = cnt;
				}
				else
				{
					cout << -1 << endl;
					f = 0;
					break;
				}
			}
		}
		if (f)
		{
			cout << att / __gcd(att, num) << " " << num / __gcd(att, num) << endl;
		}
	}
}

详细

Test #1:

score: 0
Runtime Error

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

result: