QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150371 | #5420. Inscryption | Miguel0312 | WA | 171ms | 3788kb | C++20 | 1.2kb | 2023-08-25 16:41:29 | 2023-08-25 16:41:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define INF 1000000001
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t, n;
cin >> t;
while (t--)
{
cin >> n;
int a = 0, b = 0, c = 0, x, sum = 0, cnt = 1;
bool possible = true;
vector<int> numbers(n), mini(n);
for (int i = 0; i < n; i++)
{
cin >> numbers[i];
if (numbers[i] == 1)
a++;
else if (numbers[i] == -1)
b++;
else
c++;
if (a + c + 1 - b == 0)
possible = false;
mini[i] = b - a;
}
if (possible)
{
sum = a + c + 1;
cnt = 1 + a + c - b;
int a2 = 0, b2 = 0, c2 = 0, m = -INF;
for (int i = n - 1; i >= 0; i--)
{
if (numbers[i] == 1)
a2++;
else if (numbers[i] == -1)
b2++;
else
{
c2++;
mini[i] += 1;
}
m = max(m + 2, mini[i]);
if (c - c2 < m)
{
break;
}
sum = a + (c - c2) + 1;
cnt = 1 + a + (c - c2) - c2 - b;
}
}
if (!possible)
{
cout << -1 << '\n';
continue;
}
int g = __gcd(sum, cnt);
cout << sum / g << ' ' << cnt / g << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3572kb
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: 0
Accepted
time: 171ms
memory: 3788kb
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 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