QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356863#5420. InscryptionInexhaustible#WA 72ms5904kbC++141.6kb2024-03-18 14:25:002024-03-18 14:25:00

Judging History

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

  • [2024-03-18 14:25:00]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:5904kb
  • [2024-03-18 14:25:00]
  • 提交

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;
	}
	for (int i = 0;i <= n;i++) res[i] = 0x3f3f3f3f;
	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: 1ms
memory: 5868kb

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: 72ms
memory: 5832kb

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: 28ms
memory: 5904kb

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
7 4
-1
3 2
2 1
1 0
-1
-1
2 1
-1
-1
7 3
3 2
3 1
3 2
-1
-1
-1
-1
2 1
5 3
-1
5 4
2 1
-1
3 2
5 1
1 1
-1
3 2
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
3 2
-1
-1
-1
-1
3 2
5 2
1 1
-1
1 0
-1
-1
1 1
-1
6 1
3 2
-1
3 2
4 3
2 1
-1
5 3
1 0
6 1
-1
2 1
2 1
-1
1 1
-1
4 3
-1
-1
5 3
1 1
2 1
5 2
-1
3 1
4 3...

result:

wrong answer 7th lines differ - expected: '3 1', found: '7 4'