QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134673#5420. InscryptionheaksicnTL 2ms5508kbC++141.2kb2023-08-04 14:14:202023-08-04 14:14:23

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 14:14:23]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:5508kb
  • [2023-08-04 14:14:20]
  • 提交

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[1000001];
int q[1000001],cnt;
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	int T=read();
	while(T--){
		int n=read();
		for(int i=1;i<=n;i++) a[i]=read();
		bool flag=1;
		cnt=1;
		q[1]=1;
		int tp=0;
		for(int i=1;i<=n;i++){
			if(a[i]==1){
				q[++cnt]=1;
			}else if(a[i]==-1){
				if(cnt<=1){
					if(tp==0){
						flag=0;
					 	break;
					}
					q[++cnt]=1;
					tp--;
				}
				q[1]++;
				cnt--;
			}else{
				tp++;
			}
		}
		if(!flag){
			puts("-1");
			continue;
		}
//		cout<<cnt<<endl;
//		for(int i=1;i<=cnt;i++) cout<<q[i]<<" ";
//		puts("");

		for(int i=1;i<=tp;i++){
			if(cnt>1) q[1]++,cnt--;
			else q[++cnt]=1;
		}
		int x=0;
		for(int i=1;i<=cnt;i++) x+=q[i];
		int tpp=gcd(x,cnt);
		x/=tpp,cnt/=tpp;
		cout<<x<<" "<<cnt<<endl;
	}
	return 0;
}

詳細信息

Test #1:

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

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: