QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150480 | #5420. Inscryption | Miguel0312 | WA | 156ms | 3500kb | C++20 | 1.2kb | 2023-08-25 17:45:01 | 2023-08-25 17:45:02 |
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), maxi(n + 1);
for (int i = 0; i < n; i++)
{
maxi[i] = a + c - b;
cin >> numbers[i];
if (numbers[i] == 1)
a++;
else if (numbers[i] == -1)
b++;
else
c++;
if (a + c + 1 - b == 0)
possible = false;
}
maxi[n] = a + c - b;
if (possible)
{
sum = a + c + 1;
cnt = 1 + a + c - b;
int a2 = 0, b2 = 0, c2 = 0, m = maxi[n];
for (int i = n - 1; i >= 0; i--)
{
if (numbers[i] == 1)
a2++;
else if (numbers[i] == -1)
b2++;
else
{
c2++;
}
m = min(m, maxi[i]);
if (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';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3500kb
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: 156ms
memory: 3400kb
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 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