QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673019#5420. InscryptionztttttWA 572ms7776kbC++141.1kb2024-10-24 20:19:312024-10-24 20:19:32

Judging History

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

  • [2024-10-24 20:19:32]
  • 评测
  • 测评结果:WA
  • 用时:572ms
  • 内存:7776kb
  • [2024-10-24 20:19:31]
  • 提交

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;
	while (T--){
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i];
		
		if(T==181195){
			cout<<n<<endl;
			for(int i=1;i<=n;i++)cout<<a[i]<<" ";
			puts("");
		}
		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
*/

詳細信息

Test #1:

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

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
Wrong Answer
time: 572ms
memory: 7776kb

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:

wrong answer 818805th lines differ - expected: '1 1', found: '1'