QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719294#5420. Inscryptionfieldchaser#WA 168ms3752kbC++201.1kb2024-11-07 00:04:392024-11-07 00:04:39

Judging History

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

  • [2024-11-07 00:04:39]
  • 评测
  • 测评结果:WA
  • 用时:168ms
  • 内存:3752kb
  • [2024-11-07 00:04:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define pb push_back

void solve(){
    int n; cin>>n;
    vector<int> a(n);
    vector<int> pos;
    for (int i=0;i<n;i++){
        cin>>a[i];
        if (a[i]==0){
            pos.pb(i);
            a[i]=1;
        }
    }
    vector<int> pre(n);
    for (int i=0;i<n;i++){
        if (i==0) pre[i]=a[i];
        else pre[i]=a[i]+pre[i-1];
    }
    int tmp=1;
    for (int i=0;i<n;i++){
        tmp+=a[i];
        if (tmp<=0){
            cout<<-1<<"\n";
            return;
        }
    }
    int cur=count(a.begin(),a.end(),1)+1-count(a.begin(),a.end(),-1);
    int j=0;
    int mo=cur,so=count(a.begin(),a.end(),1)+1;
    while (mo>2&&j<pos.size()){
        mo-=2;
        so--;
        if (pre[pos[pos.size()-j-1]]<=1){
            j++;
            mo+=2,so++;
            continue;
        }
        j++;
    }
    cout<<so/__gcd(so,mo)<<" "<<mo/__gcd(so,mo)<<"\n";
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin>>t;
    while (t--) solve();
    return 0;
}

詳細信息

Test #1:

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

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: 168ms
memory: 3628kb

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
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
-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 71st lines differ - expected: '5 4', found: '2 1'