QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725416#5420. InscryptionhelloccclWA 129ms7872kbC++202.0kb2024-11-08 17:35:322024-11-08 17:35:34

Judging History

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

  • [2024-11-08 17:35:34]
  • 评测
  • 测评结果:WA
  • 用时:129ms
  • 内存:7872kb
  • [2024-11-08 17:35:32]
  • 提交

answer

//ALL IN
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#define double long double
const int N=2e6+7;
const int mod=1e9+7;
const int inf=4e18;
mt19937 rnd(time(0));
clock_t start,over;// start=clock(); last=(final-over)*1.0/1000
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}return x*f;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');return;}
int a[N];
int b[N];
int pre[N];
int n;
bool check(int x){
	int t=x;
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			if(t>0){
				t--;
				b[i]=1;
			}else{
				b[i]=-1;
			}
		}
	}
	int c1=1;
	int c2=0;
	for(int i=1;i<=n;i++){
		if(b[i]==1){
			c1++;
		}else{
			c2++;
			if(c2>=c1){
				return 0;
			}
		}
	}
	return 1;
}
void solve(){
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++){
		pre[i]=0;
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==0)cnt++;
		pre[i]=pre[i-1];
		if(a[i]==0 or a[i]==1)pre[i]++;
	}
	int c=0;
	for(int i=1;i<=n;i++){
		if(a[i]==-1){
			c++;
			if(c>=pre[i]){
				cout<<-1<<'\n';
				return;
			}
		}
	}
	int l=-1,r=cnt+1;
	while(l+1!=r){
		int mid=l+r>>1;
		for(int i=1;i<=n;i++){
			b[i]=a[i];
		}
		if(check(mid)){
			r=mid;
		}else{
			l=mid;
		}
	}
	// cout<<check(2)<<'\n';
	// cout<<cnt<<'\n';
	// cout<<l<<" "<<r<<'\n';

	for(int i=1;i<=n;i++){
		if(a[i]==0){
			if(r>0){
				r--;
				a[i]=1;
			}else{
				a[i]=-1;
			}
		}
	}
	int ans1=1,ans2=1;
	for(int i=1;i<=n;i++){
		if(a[i]==1)ans1++,ans2++;
		else {
			ans2--;
		}
	}
	int g=__gcd(ans1,ans2);
	cout<<ans1/g<<' '<<ans2/g<<'\n';
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _=1;
	cin>>_;
	while(_--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7872kb

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: 129ms
memory: 7764kb

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: 68ms
memory: 7796kb

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:

4 1
-1
-1
3 2
4 1
-1
3 1
-1
-1
2 1
-1
-1
-1
2 1
-1
-1
6 1
3 2
-1
3 2
-1
-1
-1
-1
2 1
5 3
-1
5 4
2 1
-1
3 2
-1
1 1
-1
3 2
-1
1 1
-1
-1
1 1
-1
1 1
-1
1 1
3 2
-1
-1
-1
-1
3 2
5 2
1 1
-1
3 1
-1
-1
1 1
-1
6 1
3 2
-1
-1
4 3
-1
-1
-1
3 1
6 1
-1
-1
5 4
-1
1 1
-1
-1
-1
-1
5 3
1 1
2 1
-1
-1
3 1
-1
3 2
-1
-1
3...

result:

wrong answer 9th lines differ - expected: '3 2', found: '-1'