QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744283#5420. InscryptionMocic1WA 134ms3680kbC++141.7kb2024-11-13 21:26:132024-11-13 21:26:14

Judging History

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

  • [2024-11-13 21:26:14]
  • 评测
  • 测评结果:WA
  • 用时:134ms
  • 内存:3680kb
  • [2024-11-13 21:26:13]
  • 提交

answer

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

#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
typedef pair<int, int> PII;
const int N = 300007;
const int inf = 1e18;
const int mod = 1e9+7;

mt19937_64 rng(time(0));

int a[N];
void solve() {
    int n;
    cin>>n;
    int cnt=1;
    priority_queue<PII,vector<PII>,greater<PII>>qu;
    int tmp=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]==1||a[i]==0)cnt++;
        else{
            cnt--;
            qu.push({cnt,i});
        }
        if(cnt<=0)tmp=1;
    }
    if(tmp==1)
    {
        cout<<-1<<'\n';
        return ;
    }
    int p=1,q=1,nu=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==1)
        {
            p++;
            q++;
        }
        else if(a[i]==-1)q--;
        else
        {
            while(qu.size()&&qu.top().ss<i)qu.pop();
            if(qu.size())
            {
                int t=qu.top().ff;
                if(t-(nu+1)*2<=0)
                {
                    q++;
                    p++;
                }
                else
                {
                    q--;
                    nu++;
                }
            }
            else
            {
                if(q==1)
                {
                    p++;
                    q++;
                }
                else q--;
            }
        }
    }
    int g=__gcd(p,q);
    p/=g;
    q/=g;
    cout<<p<<' '<<q<<'\n';
}
signed main() {
    ios;
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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: 134ms
memory: 3656kb

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: 69ms
memory: 3624kb

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
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
5 4
-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'