QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356862#5420. InscryptionInexhaustible#TL 0ms9696kbC++141.6kb2024-03-18 14:24:212024-03-18 14:24:22

Judging History

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

  • [2024-03-18 14:24:22]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:9696kb
  • [2024-03-18 14:24:21]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? (-1) : (f),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

const int N = 1e6 + 10;
int T,n,a[N],s[N],cnt[N],res[N];

void solve(){
	n = read();
	for (int i = 1;i <= n;i++) a[i] = read();
	int c1 = 0;
	for (int i = 1;i <= n;i++){
		s[i] = s[i - 1] + a[i],cnt[i] = cnt[i - 1] + (a[i] == 0);
		if (a[i] == 1) ++c1;
	}
	memset(res,63,sizeof(res));
	int mn = 0;
	for (int i = n;i >= 0;i--){
		if (s[i] + cnt[i] >= -(mn - cnt[n] + cnt[i])) res[i] = cnt[i];
		mn = min(mn,s[i]);
	}
	int ss = 0,ans = res[0];
	for (int i = 1;i <= n;i++){
		ss += a[i];
		if (a[i] == 0) ++ss;
		if (ss < 0) break;
		ans = min(ans,res[i]);
	}
	if (ans == 0x3f3f3f3f) {puts("-1");return ;}
	int t = s[n] + ans - (cnt[n] - ans) + 1;
	ans = ans + c1 + 1;
	int d = __gcd(ans,t);
	t /= d,ans /= d;
	printf("%d %d\n",ans,t);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	T = read();
	while (T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: