QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277624 | #5420. Inscryption | Firystal | RE | 0ms | 0kb | C++23 | 1.2kb | 2023-12-06 20:53:28 | 2023-12-06 20:53:28 |
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()
{
ios::sync_with_stdio(false),cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
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: 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