QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#681828 | #5420. Inscryption | blue_sky | WA | 162ms | 3608kb | C++20 | 1.4kb | 2024-10-27 12:14:59 | 2024-10-27 12:15:01 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define bug(X) cout << "bug:# " << X << endl
#define bug2(f, X) cout << "bug:# " << f << " " << X << endl
#define bug3(i, j, G) cout << "bug:# " << i << ' ' << j << ' ' << G << endl
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1), rpre(n + 2);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i; i--)
rpre[i] = (a[i] == -1) + rpre[i + 1];
int attack = 1, cnt = 1;
for (int i = 1; i <= n; i++)
{
if (a[i] == 1)
attack++, cnt++;
else if (a[i] == -1)
{
cnt--;
if (cnt == 0)
{
cout << -1 << endl;
return;
}
}
else
{
// ((double)attack + 1) / (cnt + 1) > (double)attack / (cnt - 1) ||
if ( cnt - rpre[i] - 1 < 1)
attack++, cnt++;
else
cnt--;
}
// bug3(i,attack,cnt);
}
int g = __gcd(attack, cnt);
cout << attack / g << ' ' << cnt / g << endl;
}
Details
Tip: Click on the bar to expand more detailed information
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: 162ms
memory: 3608kb
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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