QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686722#5420. Inscryptionwangxiaorui#WA 363ms3712kbC++141.4kb2024-10-29 15:21:242024-10-29 15:21:25

Judging History

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

  • [2024-10-29 15:21:25]
  • 评测
  • 测评结果:WA
  • 用时:363ms
  • 内存:3712kb
  • [2024-10-29 15:21:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T;
int n;
const int MAXN = 1e6 + 10;
int a[MAXN];
int sum, cnt, c0;
void solve()
{
    sum = cnt = 1;
    c0 = 0;
    for(int i = 1; i <= n; ++i)
    {
        if (a[i] == 1)
        {
            ++sum;
            ++cnt;
        }
        if (a[i] == 0) ++c0;
        if (a[i] == -1)
        {
            if (cnt == 1)
            {
                if (c0)
                {
                    ++sum;
                    --c0;
                }
                else
                {
                    cout << "-1\n";
                    return;
                }
            }
            else --cnt;
        }//cout << i << " " << sum << " " << cnt << "\n";
    }
    if (c0 < cnt - 1) cnt -= c0;
    else
    {
        c0 -= cnt - 1;
        sum += c0 >> 1;
        if (c0 & 1)
        {
            ++sum;
            cnt = 2;
        } 
        else cnt = 1;
    }
    int t = __gcd(cnt, sum);
    sum /= t;
    cnt /= t;
    cout << sum << ' ' << cnt << '\n';
}
int main()
{//freopen("1.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);
    cin >> T;
    while (T--)
    {
        cin >> n;
        for(int i = 1; i <= n; ++i) cin >> a[i];
        solve();
    }
    return 0;
}
/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: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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
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
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 2
-1
3 1
4 3...

result:

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