QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#615095 | #5420. Inscryption | ucup-team1769# | WA | 0ms | 3628kb | C++20 | 1.9kb | 2024-10-05 17:36:39 | 2024-10-05 17:36:40 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e6;
signed main()
{
IOS;
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 0; i < n; i++)
cin >> v[i];
int fz = 1, fm = 1, ff = 1;
for (int i = 0; i < n; i++)
{
if (v[i] == 1 || v[i] == 0)
{
fz++;
fm++;
}
else
{
fm--;
if (fm < 1)
ff = 0;
}
}
int fm1 = fm, fz1 = fz;
if (!ff)
{
cout << "-1\n";
}
else
{
int cnt = 0;
for (int i = n - 1; i >= 0; i--)
{
if (v[i] == 1)
{
if (cnt)
cnt--;
fz1--;
fm1--;
}
else if (v[i] == -1)
{
cnt++;
fm1++;
}
else
{
if (fm1 > cnt + 2)
{
cnt++;
fz -= 1;
fm -= 2;
fm1++;
}
else
{
if (cnt)
cnt--;
fz1--;
fm1--;
}
}
}
int _ = gcd(fz, fm);
cout << fz / _ << " " << fm / _ << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
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 2 -1 -1 1 1 1 -1 -1
result:
wrong answer 2nd lines differ - expected: '3 1', found: '2 -1'