QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#99717 | #5420. Inscryption | krito2023# | WA | 255ms | 3464kb | C++20 | 999b | 2023-04-23 15:39:26 | 2023-04-23 15:39:39 |
Judging History
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;
}
}
vector<int> pre(n+1);
pre[0]=1;
int ans=1,cnt=1;
for(int i = 1; i <= n; i++){
if(b[i]==1){
ans++,cnt++;
}
else{
cnt--;
}
pre[i] = pre[i-1]+b[i];
if(cnt<=0){
cout<<"-1\n";
return ;
}
}
// cout<<"cha:"<<cha<<"\n";
int cha=0;
for(int i=n;i;--i){
if(a[i]==0&&cha+pre[i-1]>1){
b[i] = -1;
cha-=2;
}
cha += b[i];
// cout<<b[i]<<" ";
}
// cout<<endl;
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: 2ms
memory: 3424kb
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: 255ms
memory: 3364kb
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 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