QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134687#5420. InscryptionheaksicnTL 2ms5460kbC++171.0kb2023-08-04 15:15:502023-08-04 15:15:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-04 15:15:52]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:5460kb
  • [2023-08-04 15:15:50]
  • 提交

answer

//Man always remember love because of romance only!
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x){
	if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int a[1000010];
int q[1000010],cnt;
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
inline void out(int x,int y){
	if(!x)cout<<"0 1\n";
	else{
		int g=gcd(x,y);
		x/=g;y/=g;
		cout<<x<<' '<<y<<'\n';
	}
}
int main(){
	a[0]=1;
	int T=read();
	for(int i=1;i<=T;i++){
		int n=read();
		int x=0,fl=0;
		for(int j=1;j<=n;j++)cin>>a[j];
		for(int j=0;j<=n;j++){
			if(a[j]>=0)x++;
			else x--;
			if(x<=0)fl=1;
		}
		if(fl)cout<<"-1\n";
		else{
			int x=0,y=0;
			for(int j=0;j<=n;j++){
				if(a[j]==1)x++,y++;
				else x--;
				if(x<=0)x+=2,y++;
			}
			out(y,2*y-(n+1));
		}
	}
	return 0;
} 

詳細信息

Test #1:

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

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: -100
Time Limit Exceeded

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: