QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#615095#5420. Inscryptionucup-team1769#WA 0ms3628kbC++201.9kb2024-10-05 17:36:392024-10-05 17:36:40

Judging History

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

  • [2024-10-05 17:36:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3628kb
  • [2024-10-05 17:36:39]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e6;
signed main()
{
    IOS;
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> v(n + 1);
        for (int i = 0; i < n; i++)
            cin >> v[i];
        int fz = 1, fm = 1, ff = 1;
        for (int i = 0; i < n; i++)
        {
            if (v[i] == 1 || v[i] == 0)
            {
                fz++;
                fm++;
            }
            else
            {
                fm--;
                if (fm < 1)
                    ff = 0;
            }
        }
        int fm1 = fm, fz1 = fz;
        if (!ff)
        {
            cout << "-1\n";
        }
        else
        {
            int cnt = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                if (v[i] == 1)
                {
                    if (cnt)
                        cnt--;
                    fz1--;
                    fm1--;
                }
                else if (v[i] == -1)
                {
                    cnt++;
                    fm1++;
                }
                else
                {
                    if (fm1 > cnt + 2)
                    {
                        cnt++;
                        fz -= 1;
                        fm -= 2;
                        fm1++;
                    }
                    else
                    {
                        if (cnt)
                            cnt--;
                        fz1--;
                        fm1--;
                    }
                }
            }

            int _ = gcd(fz, fm);
            cout << fz / _ << " " << fm / _ << endl;
        }
    }
}

详细

Test #1:

score: 0
Wrong Answer
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
2 -1
-1
1 1
1 -1
-1

result:

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