QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686703#5420. Inscryptionwangxiaorui#WA 388ms3716kbC++141.4kb2024-10-29 15:13:462024-10-29 15:13:49

Judging History

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

  • [2024-10-29 15:13:49]
  • 评测
  • 测评结果:WA
  • 用时:388ms
  • 内存:3716kb
  • [2024-10-29 15:13:46]
  • 提交

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 << sum << " " << cnt << "\n";
    }
    if (c0 < cnt - 1) cnt -= c0;
    else
    {
        c0 -= cnt - 1;
        sum += 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
*/

詳細信息

Test #1:

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

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: 388ms
memory: 3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 1
3 1
2 1
-1
-1
-1
-1
3 1
5 3
-1
2 1
3 1
-1
2 1
6 1
1 1
-1
2 1
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
3 2
-1
-1
-1
-1
3 2
7 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
7 2
6 1
-1
2 1
2 1
-1
1 1
-1
3 1
-1
-1
5 1
1 1
2 1
5 2
-1
4 1
4 3...

result:

wrong answer 1st lines differ - expected: '4 1', found: '5 1'