QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#478043 | #8832. Daily Disinfection | Milan | WA | 4ms | 3832kb | C++23 | 1.6kb | 2024-07-14 16:00:11 | 2024-07-14 16:00:11 |
Judging History
answer
#include <bits/stdc++.h>
#define MULTI int _; cin >> _; while (_--)
#define fi first
#define se second
#define pb(a) push_back(a)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n, m) for (int i = n; i <= m; i++)
#define repsv(i, n, m) for (int i = n; i >= m; i--)
#define vsz(a) (int)(a.size())
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
#ifdef LOCAL
#include "debugs.hpp"
#else
#define dbg(...) 0
#endif
void solve(){
int n;
cin >> n;
string s;
cin >> s;
vi pos;
rep(i, n)
if(s[i] == '0')
pos.pb(i);
int ans = INT_MAX;
// go left
int cur = 0;
reps(i, 0, vsz(pos)-2){
int p = pos[i];
while(--p >= 0 && s[p] != '0')
cur++;
}
int l = pos.back()-(vsz(pos) == 1 ? 0 : pos[vsz(pos)-2]+1);
int r = n-1-pos.back();
dbg(cur, l, r);
cur += 2*min(l, r)+max(l, r);
// dbg(cur);
ans = min(ans, cur);
// go right
cur = 0;
reps(i, 1, vsz(pos)-1){
int p = pos[i];
while(++p < n && s[p] != '0')
cur++;
}
l = pos[0];
r = (vsz(pos) == 1 ? n-1-pos[0] : pos[1]-pos[0]-1);
dbg(cur, l, r);
cur += 2*min(l, r)+max(l, r);
// dbg(cur);
ans = min(ans, cur);
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
MULTI
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 2 01 5 00110 9 101010101
output:
1 2 6
result:
ok 3 number(s): "1 2 6"
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3832kb
input:
10000 15 010111111011011 10 1000101111 10 0011111101 1 0 3 110 4 1000 8 10000111 20 00000101000100001110 13 1101110110110 13 0111100011010 17 00001001111110101 1 0 20 10001010011000111100 11 00100110101 11 10110101000 15 001011110011000 16 1110111110000111 15 011110110110010 1 0 20 10110001101100010...
output:
11 6 7 0 2 1 4 6 9 7 9 0 9 5 5 7 11 9 0 9 8 7 3 6 0 6 2 5 4 8 10 4 6 1 8 2 1 8 1 8 11 9 13 4 12 13 16 6 4 4 5 1 1 7 7 5 3 0 0 11 8 5 6 7 6 4 9 1 4 5 12 0 2 10 4 3 7 7 3 7 4 3 7 9 15 2 6 6 9 8 6 1 2 6 2 11 10 5 0 0 4 7 4 7 0 4 7 9 3 3 10 3 6 12 8 1 8 6 5 2 4 9 7 1 5 7 8 3 5 11 6 10 8 8 9 16 2 7 6 4 3...
result:
wrong answer 35th numbers differ - expected: '7', found: '8'