QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105960 | #5420. Inscryption | RabbieWjy# | WA | 194ms | 3676kb | C++14 | 994b | 2023-05-16 08:32:36 | 2023-05-16 08:32:39 |
Judging History
answer
#include <iostream>
#include <cstdio>
using namespace std;
int t,n;
int a[1000010];
int s[1000010],minn[1000010];
int gcd(int x,int y)
{
while (x ^= y ^= x ^= y %= x);
return y;
}
int main()
{
scanf("%d",&t);
while (t --)
{
int A = 1,B = 1;
bool fl = true;
scanf("%d",&n);
for (int i = 1;i <= n;i ++) scanf("%d",a + i);
minn[n + 1] = s[n + 1] = 0;
for (int i = n;i >= 1;i --)
minn[i] = min(minn[i + 1] + a[i],s[i + 1] + a[i]),s[i] = s[i + 1] + a[i];
int nw = 0;
for (int i = 1;i <= n;i ++)
{
// printf("%d %d %d\n",nw,minn[i],s[i]);
if (a[i] != 0) nw += a[i];
else
{
// printf("cmp %d %d\n",nw,minn[i]);
if (nw > -minn[i]) a[i] = -1,nw --;
else a[i] = 1,nw ++;
}
if (nw < 0)
{
printf("-1\n");
fl = false;
break;
}
}
if (!fl) continue;
for (int i = 1;i <= n;i ++)
if (a[i] > 0) A ++,B ++;
else B --;
int g = gcd(A,B);
printf("%d %d\n",A / g,B / g);
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3532kb
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: 194ms
memory: 3568kb
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 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