QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#674086#5420. Inscryptionyumingsk#WA 132ms3700kbC++201.6kb2024-10-25 13:44:242024-10-25 13:44:26

Judging History

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

  • [2024-10-25 13:44:26]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:3700kb
  • [2024-10-25 13:44:24]
  • 提交

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--;
                to++;
            }
        }
        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;
}

詳細信息

Test #1:

score: 100
Accepted
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
3 1
-1
1 1
2 1
-1

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 132ms
memory: 3700kb

input:

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

result:

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