QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#777846#5420. InscryptionShallowMapleWA 157ms3596kbC++141.0kb2024-11-24 10:16:232024-11-24 10:16:23

Judging History

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

  • [2024-11-24 10:16:23]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:3596kb
  • [2024-11-24 10:16:23]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

const int N = 2e5 + 5;
int n, m, k, x, y, T;

void solve()
{
	cin >> n;
	vector<int> a(n + 1);
	vector<int> suf(n + 2);
	for(int i = 1; i <= n; i ++) cin >> a[i];
	
	// 1 1 0 -1 1 1 1 1 0 -1 -1 -1
	for(int i = n; i >= 1; i --){
		if(a[i] == -1) suf[i] = suf[i + 1] + 1;
		else if(a[i] == 0) suf[i] = suf[i + 1];
		else suf[i] = 0;
	}
	
	//0 0 0 -1 -1
	int cnt = 1, sum = 1;
	for(int i = 1; i <= n; i ++){
		if(a[i] == 1) sum ++, cnt ++;
		else if(a[i] == -1){
			cnt --;
			if(cnt <= 0){
				cout << -1 << endl;
				return;
			}
		}
		else if(a[i] == 0){
			if(cnt > suf[i + 1] + 1){
				cnt --;
			}
			else sum ++, cnt ++;
		}
		else sum ++, cnt ++;
		//cout << sum << ' ' << cnt << endl;
	}
	
	cout << sum / __gcd(sum, cnt) << ' ' << cnt / __gcd(sum, cnt) << endl;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	
	cin >> T;
	while(T--) solve();
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 157ms
memory: 3596kb

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

result:

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