QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674077#5420. Inscryptionyumingsk#WA 133ms3712kbC++201.6kb2024-10-25 13:39:462024-10-25 13:39:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 13:39:47]
  • 评测
  • 测评结果:WA
  • 用时:133ms
  • 内存:3712kb
  • [2024-10-25 13:39:46]
  • 提交

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--;
            }
        }
        else
        {
            sum++;
        }
    }
    if (flag == 0)
    {
        return;
    }
    if (sum != 0)
    {
        if (dow > sum)
        {
            dow -= sum;
        }
        else
        {
            sum -= dow - 1;
            dow = 1;
            to += sum / 2;
            if (sum % 2 == 1)
            {
                to++;
                dow++;
            }
        }
    }
    int igcd = gcd(to, dow);
    cout << to / igcd << " " << dow / igcd << "\n";
}
int main()
{
    IOS;
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

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: 133ms
memory: 3712kb

input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2
3 2
-1
-1
-1
-1
-1
-1
2 1
5 3
-1
2 1
2 1
-1
-1
3 2
5 1
1 1
-1
3 2
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
1 1
-1
-1
-1
-1
3 2
5 2
1 1
-1
5 2
-1
-1
1 1
-1
5 1
3 2
-1
1 1
4 3
1 1
-1
-1
5 3
3 1
6 1
-1
1 1
2 1
-1
1 1
-1
2 1
-1
-1
3 1
1 1
2 1
2 ...

result:

wrong answer 7th lines differ - expected: '3 1', found: '2 1'