QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673027#5420. InscryptionztttttWA 495ms7732kbC++141.1kb2024-10-24 20:20:442024-10-24 20:20:45

Judging History

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

  • [2024-10-24 20:20:45]
  • 评测
  • 测评结果:WA
  • 用时:495ms
  • 内存:7732kb
  • [2024-10-24 20:20:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1e6 + 10;

int T, n, x, y;
int a[N], g[N], v[N];

int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}

signed main()
{
	cin >> T;
	int T1=T;
	while (T--){
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i];
		
		if(T1!=1000000&&T==181195){
			cout<<n<<endl;
			for(int i=1;i<=n;i++)cout<<a[i]<<" ";
			puts("");
			continue;
		}
		int pos = 0;
		for (int i = n; i >= 1; i--)
			if (a[i] == -1) {
				pos = i;
				break;
			}
		for (int i = pos + 1; i <= n + 1; i++) g[i] = 1;
		for (int i = pos; i >= 1; i--) {
			if (a[i] == -1) g[i] = g[i + 1] + 1;
			else g[i] = g[i + 1] - 1;
		}
		
		x = y = 1;
		int flag = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] == 1) x++, y++;
			else if (a[i] == -1) y--;
			else {
				if (y == 1) x++, y++;
				else if (y - 1 >= g[i + 1]) y--;
				else x++, y++;
			}
			if (y <= 0) {
				flag = 1;
				break;
			}
		}
		
		if (flag) puts("-1");
		else {
			int g = gcd(x, y);
			cout << x / g << ' ' << y / g << endl;
		}
	}
	return 0;
}
/*
1
2
0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7712kb

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: 495ms
memory: 7732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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
9
1 0 -1 1 0 0 -1 -1 0 
-1
-1
1 1
-1
-1
3 2
-1
3 2
4 3
2 1
-1
5 3
3 1
6 1
-1
2 1
5 4
-1
1 1
-1
3 1
-1
-1
5 3
1 1...

result:

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