QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277627#5420. InscryptionFirystalTL 8ms27012kbC++231.2kb2023-12-06 20:55:022023-12-06 20:55:03

Judging History

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

  • [2023-12-06 20:55:03]
  • 评测
  • 测评结果:TL
  • 用时:8ms
  • 内存:27012kb
  • [2023-12-06 20:55:02]
  • 提交

answer

#include<iostream>
#include<map>
#include<cmath>
#include<algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define int long long

signed main()
{
ios::sync_with_stdio(false),cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--)
	{
ll n;
ll a[1000010]={0}, b[1000010]={0};
ll po[1000010]={0};
bool f;
		f = true;
		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 = false;
					break;
				}
			}
		}
		if (f)
		{
			cout << att / __gcd(att, num) << " " << num / __gcd(att, num) << endl;
		}
	}
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 27012kb

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
Time Limit Exceeded

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

result: