QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650919#5420. InscryptionlshhslWA 320ms5688kbC++172.4kb2024-10-18 17:07:462024-10-18 17:07:46

Judging History

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

  • [2024-10-18 17:07:46]
  • 评测
  • 测评结果:WA
  • 用时:320ms
  • 内存:5688kb
  • [2024-10-18 17:07:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 1e6 + 5;
int a[maxn],num0[maxn],num1[maxn],num2[maxn];
int n;

void solve()
{
    cin >> n;
    int sum = 1;
    int cnt = 0;
    int cnt0 = 0;
    int cnt1 = 1;
    int cnt2 = 0;
    int num_0 = 0;
    int num_1 = 1;
    int num_2 = 0;
    int flag = 1;
    int id = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] == -1)
        {
            cnt2++;
            id = i;
        }
        else if (a[i] == 0)
        {
            cnt0++;
        }
        else
        {
            cnt1++;
        }
        if (cnt1 + cnt0 - cnt2 < 1)
        {
            flag = 0;
        }
    }
    if (flag == 0)
    {
        cout << -1 << endl;
        return ;
    }

    for(int i = 1;i <= n;i++) {
        num0[i] = num0[i - 1];
        num1[i] = num1[i - 1];
        num2[i] = num2[i - 1];
        if(a[i] == 0) {
            num0[i]++;
        } else if(a[i] == 1) {
            num1[i]++;
        } else if(a[i] == -1){
            num2[i]++;
        }
    }

    int res = 0;

    for(int i = 1;i <= n;i++) {
        if(a[i] == -1) { 
            int a = num0[i],b = num1[i],c = num2[i] - 1;
            int x = 1 + b - c,y = a;
            int z;
            if(x >= y + 1) {
                z = 0;
            } else {
                z = (y - x + 2 + 1) / 2;
            }
            if(z > y) {
                //cout << "hh" << endl;
                cout << -1 << endl;
                return ;
            }
            res = max(res,z);
        }
        if(i == id) {
            break;
        }
    }

    int sum1 = 1 + num1[id] - num2[id] + res - (num0[id] - res);

    for(int i = id + 1;i <= n;i++) {
        if(a[i] == 1) {
            sum1++;
        } else if(a[i] == 0) {
            if(sum1 >= 2) {
                sum1--;
            } else {
                sum1++;
                res++;
            }
        }
    }

    int a = 1 + num1[n] + res;
    int b = 1 + num1[n] - num2[n] + res - (num0[n] - res);

    cout << a / __gcd(a,b) << " " << b / __gcd(a,b) << endl;

    return ;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5628kb

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: 320ms
memory: 5688kb

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
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
0
1
0
1
-1
1
0
1
-1
1
0
1
0
1
0
1
0
1
0
1
-1
1
1
1
0
1
0
1
1
1
0
1
-1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
...

output:

1 1
-1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
-1
-1
-1
1 1
1 1
-1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 ...

result:

ok 1000000 lines

Test #3:

score: -100
Wrong Answer
time: 99ms
memory: 5644kb

input:

181249
6
1 0 -1 0 1 0
4
1 -1 -1 -1
8
-1 0 0 0 1 -1 1 1
3
0 1 0
6
1 0 -1 1 -1 0
4
1 -1 -1 -1
9
0 1 0 -1 -1 0 -1 0 1
1
-1
3
0 -1 1
5
0 0 1 -1 1
3
1 -1 0
6
-1 0 0 -1 0 1
8
1 -1 -1 -1 0 1 -1 0
2
0 0
3
-1 1 0
3
0 -1 -1
10
0 1 0 -1 1 1 0 -1 1 0
3
1 0 0
9
1 -1 1 -1 0 -1 0 0 0
3
0 1 0
3
-1 0 0
7
-1 0 -1 -1 ...

output:

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

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'