QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277627 | #5420. Inscryption | Firystal | TL | 8ms | 27012kb | C++23 | 1.2kb | 2023-12-06 20:55:02 | 2023-12-06 20:55:03 |
Judging History
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 ...