QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733396#5420. InscryptionwantsthWA 324ms3780kbC++23911b2024-11-10 18:35:022024-11-10 18:35:05

Judging History

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

  • [2024-11-10 18:35:05]
  • 评测
  • 测评结果:WA
  • 用时:324ms
  • 内存:3780kb
  • [2024-11-10 18:35:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;
	cin>>n;
	vector<int>a(n+1);
	int x=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int num=1;
	int k=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)
		{
			x+=1;
			num+=1;
		}
	    else if(a[i]==-1)
		{
			num-=1;
		}
		else
		{
			k+=1;
		}
		if(num==0)
		{
			if(k>0)
			{
				k-=1;
				x+=1;
				num+=1;
			}
			else
			{
				cout<<-1<<endl;
				return;
			}
		}
	}
//	cout<<x<<" "<<num<<" "<<k<<endl;
	if(k>0)
	{
		if(num>k)
		{
			num-=k;
		}
		else
		{
			int shu=num;
			num=1;
			k-=(shu-1);
			if(k%2==0)
			{
				x+=k/2;
			}
			else
			{
				x+=k/2+1;
				num+=1;
			}
		}
	}
	int gg=__gcd(x,num);
	cout<<x/gg<<" "<<num/gg<<endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	 } 
 } 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 324ms
memory: 3564kb

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