QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#457650 | #8832. Daily Disinfection | ucup-team045# | WA | 0ms | 3524kb | C++20 | 1.2kb | 2024-06-29 13:33:25 | 2024-06-29 13:33:25 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n; string s;
cin >> n >> s;
int ans = count(s.begin(), s.end(), '1');
int mn = 1e9;
for(int i = 0; i < n; i++){
if (s[i] == '0') continue;
int j = i;
while(j + 1 < n and s[j + 1] == '1') j++;
mn = min(mn, j - i + 1);
i = j;
}
bool ok = false;
for(int i = 0; i < n; i++){
if (s[i] == '0') continue;
int j = i;
while(j + 1 < n and s[j + 1] == '1') j++;
if (i - 1 >= 0 and s[i - 1] == '0'){
swap(s[i - 1], s[j]);
}
else if (j + 1 < n and s[j + 1] == '0'){
swap(s[i], s[j + 1]);
}
else{
ok = true;
break;
}
i = j;
}
if (ok) ans += mn;
cout << ans << '\n';
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3524kb
input:
3 2 01 5 00110 9 101010101
output:
1 2 5
result:
wrong answer 3rd numbers differ - expected: '6', found: '5'