QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99698#5420. Inscryptionkrito2023#WA 230ms3360kbC++20846b2023-04-23 15:13:212023-04-23 15:13:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 15:13:25]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:3360kb
  • [2023-04-23 15:13:21]
  • 提交

answer

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

void solve() {
	int n;
	cin >> n;
	vector<int> a(n + 1),b(n+1);
	int cnt1 = 0, cnt0 = 0;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		b[i]=a[i];
		if(a[i]==0){
			b[i]=1;
		}
	}
	int ans=1,cnt=1,cha=1;
	for(int i = 1; i <= n; i++){
		if(b[i]==1){
			ans++,cnt++;
			cha++;
		}
		else{
			cha--;
			cnt--;
		}
		if(cnt<=0){
			cout<<"-1\n";
			return ;
		}
	}
	for(int i=n;i;--i){
		if(a[i]==0&&cha>2){
			b[i] = -1;
			cha-=2;
		}
	}
	ans=1,cnt=1;
	for(int i=1;i<=n;++i){
		if(b[i]==1){
			ans++;cnt++;
		}
		else{
			cnt--;
		}
	}
	int tmp = __gcd(ans, cnt);
	ans /= tmp, cnt /= tmp;
	cout << ans << " " << cnt << "\n";
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while(t --) {
		solve();
	}
	
}

详细

Test #1:

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

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: 230ms
memory: 3360kb

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

result:

wrong answer 28th lines differ - expected: '5 4', found: '2 1'