QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725306#5420. InscryptionhelloccclWA 150ms8052kbC++202.2kb2024-11-08 17:04:152024-11-08 17:04:16

Judging History

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

  • [2024-11-08 17:04:16]
  • 评测
  • 测评结果:WA
  • 用时:150ms
  • 内存:8052kb
  • [2024-11-08 17:04:15]
  • 提交

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 pre[N];
int pre1[N];
void solve(){
	int n;cin>>n;
	pre[0]=1;
	vector<int>v0;
	vector<int>v_;
	for(int i=1;i<=n;i++){
		pre[i]=0;
		pre1[i]=0;
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
		pre[i]=pre[i-1];
		pre1[i]=pre1[i-1];
		if(a[i]==0 or a[i]==1)pre[i]++;
		if(a[i]==1)pre1[i]++;
		if(a[i]==0)v0.push_back(i);
		if(a[i]==-1)v_.push_back(i);
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]==-1){
			cnt++;
			if(cnt>=pre[i]){
				cout<<-1<<'\n';
				return;
			}
		}
	}
	int ccc=0;
	int now=1;
	int last=0;
	for(auto i:v_){
		ccc++;
		int x=pre1[i];
		if(ccc<now+x){
			continue;
		}else{
			int t=ccc-(now+x)+1;//需要的0的数量
			for(int j=last;j<last+t;j++){
				a[v0[j]]=1;
			}
			last=last+t;
			now+=t;
		}
	}
	
	int c1=0;
	int c2=0;
	int c3=0;
	for(int i=1;i<=n;i++){
		if(a[i]==1)c1++;
		if(a[i]==0)c2++;
		if(a[i]==-1)c3++;
	}
	c1++;
	int cc=c1-c3-1;
	int cnm=1;
	for(int i=1;i<=n;i++){
		if(a[i]==0 and cc>0){
			cc--;
			a[i]=-1;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			if(cnm&1)
				a[i]=1;
			else
				a[i]=-1;
			cnm++;
		}
	}
	// for(int i=1;i<=n;i++){
	// 	cout<<a[i]<<" ";
	// }
	// cout<<'\n';
	int ansx=1,ansy=1;
	for(int i=1;i<=n;i++){
		if(a[i]==1){
			ansx++;
			ansy++;
		}else if(a[i]==0){
			ansy--;
		}else{
			ansy--;
		}
	}
	int g=__gcd(ansx,ansy);
	cout<<ansx/g<<" "<<ansy/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: 7820kb

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: 150ms
memory: 7788kb

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
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ected: '5 4', found: '2 1'