QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134673 | #5420. Inscryption | heaksicn | TL | 2ms | 5508kb | C++14 | 1.2kb | 2023-08-04 14:14:20 | 2023-08-04 14:14:23 |
Judging History
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 ...