QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743972#5420. InscryptionHHSWA 0ms3556kbC++14958b2024-11-13 20:28:522024-11-13 20:28:52

Judging History

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

  • [2024-11-13 20:28:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3556kb
  • [2024-11-13 20:28:52]
  • 提交

answer

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

void solve(){
	ll n;
	cin>>n;
	ll cnt=0;
	ll res1=1,res2=1;
	ll s=0;
	vector<ll>a(n+10),minn(n+10);
	int flag=1;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
		{
			s++;
			cnt++;
			res1++;
			res2++;
			minn[i]=2*n;
		}
		else if(a[i]==-1)
		{
			s--;
			cnt--;
			res2--;
			minn[i]=cnt;
		}
		else minn[i]=2*n,s++;
		if(s<0&&flag)
		{
			cout<<-1<<endl;
			flag=0;
		}
	}
	if(!flag)
	{
		return ;
	}
	for(ll i=n-1;i>=1;i--)
	{
		minn[i]=min(minn[i],minn[i+1]);
	}
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]==0)
		{
			if(sum+1<=minn[i])
			{
				res2--;
				sum++;
			}
			else{
				res1++;res2++;
				sum--;
			}
		}
	}
	cout<<res1/__gcd(res1,res2)<<" "<<res2/__gcd(res1,res2)<<endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3556kb

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

result:

wrong answer 4th lines differ - expected: '1 1', found: '1 0'