QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#151894#5420. Inscryptionwind#WA 145ms7500kbC++201.2kb2023-08-27 15:04:132023-08-27 15:04:14

Judging History

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

  • [2023-08-27 15:04:14]
  • 评测
  • 测评结果:WA
  • 用时:145ms
  • 内存:7500kb
  • [2023-08-27 15:04:13]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
const int N=1e6+5;
int p[N];
bool st[N];
int qu[N];
void sol()
{
	int n;
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i],st[i]=0;
	for(int i=n;i>=1;i--)
	{
		int x=p[i];
		if(x==1)cnt++;
		else if(x==-1)cnt--;
		else
		{
			if(cnt<0)
			{
				cnt++;
				st[i]=1;
			}
		}
	}
//	for(int i=1;i<=n;i++)cout<<st[i]<<" ";
//	cout<<endl;
	int l=1,r=1;
	qu[r]=1;
	for(int i=1;i<=n;i++)
	{
		int x=p[i];
		if(x==1)
		{
			r++;
			qu[r]=1;
		}
		else if(x==-1)
		{
			if(r-l+1>=2)
			{
				int tmp=qu[r];
				r--;
				qu[l]+=tmp;
			}
			else
			{
				cout<<-1<<endl;
				return;
			}
		}
		else
		{
			if(st[i])
			{
				r++;
				qu[r]=1;
			}
			else
			{
				if(r-l+1>=2)
				{
					int tmp=qu[r];
					r--;
					qu[l]+=tmp;
				}
				else
				{
					r++;
					qu[r]=1;
				}
			}
		}
//		for(int i=l;i<=r;i++)cout<<qu[i]<<" ";
//		cout<<endl;
	}
	ll ans=0;
	for(int i=l;i<=r;i++)ans+=qu[i];
	ll a=ans,b=r-l+1;
	int q=__gcd(a,b);
	cout<<a/q<<" "<<b/q<<endl;


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

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7500kb

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: 145ms
memory: 5628kb

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: 67ms
memory: 5624kb

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:

-1
-1
-1
3 2
4 1
-1
-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
5 4
2 1
-1
3 2
2 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
-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
-1
-1
1 1
-1
3 1
-1
-1
-1
1 1
2 1
5 2
-1
3 1
4 3
3 2
...

result:

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