QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#674111 | #5420. Inscryption | yumingsk# | WA | 132ms | 3624kb | C++20 | 1.6kb | 2024-10-25 13:59:20 | 2024-10-25 13:59:20 |
Judging History
answer
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
int n;
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
void solve()
{
cin >> n;
int to = 1, dow = 1;
int sum = 0;
int flag = 1;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (x == 1)
{
to += 1;
dow += 1;
}
else if (x == -1)
{
dow -= 1;
if (dow == 0)
{
dow = 1;
if (sum == 0)
{
cout << "-1" << "\n";
flag = 0;
// break;
}
sum--;
dow++;
to++;
}
else
{
}
}
else
{
if (dow != 1)
{
//-1
sum++;
dow--;
}
else
{
to++;
dow++;
}
}
}
if (flag == 0)
{
return;
}
int igcd = gcd(to, dow);
cout << to / igcd << " " << dow / igcd << "\n";
}
int main()
{
IOS;
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 132ms
memory: 3520kb
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 -1 1 0 1 1 1 1 1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