QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134674#5420. InscryptionheaksicnTL 1ms5568kbC++171.2kb2023-08-04 14:15:452023-08-04 14:15:46

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:15:46]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5568kb
  • [2023-08-04 14:15:45]
  • 提交

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);
}
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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5568kb

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: