QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#497785 | #8832. Daily Disinfection | kmiao | WA | 2ms | 3608kb | C++20 | 2.3kb | 2024-07-29 17:53:21 | 2024-07-29 17:53:22 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/kmiao/codes/debugtemplate.cpp"
#else
#define debug(...)
#endif
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define endl '\n'
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const ll INF = (ll)1e18;
class HashedString {
private:
// change M and B if you want
static const ll M = (1LL << 61) - 1;
static const ll B;
// pow[i] contains B^i % M
static vector<ll> pow;
// p_hash[i] is the hash of the first i characters of the given string
vector<ll> p_hash;
__int128 mul(ll a, ll b) { return (__int128)a * b; }
ll mod_mul(ll a, ll b) { return mul(a, b) % M; }
public:
HashedString(const string &s) : p_hash(s.size() + 1) {
while (pow.size() < s.size()) { pow.push_back(mod_mul(pow.back(), B)); }
p_hash[0] = 0;
for (int i = 0; i < s.size(); i++) {
p_hash[i + 1] = (mul(p_hash[i], B) + s[i]) % M;
}
}
ll get_hash(int start, int end) {
ll raw_val =
p_hash[end + 1] - mod_mul(p_hash[start], pow[end - start + 1]);
return (raw_val + M) % M;
}
};
mt19937 RNG((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
vector<ll> HashedString::pow = {1};
const ll HashedString::B = uniform_int_distribution<ll>(0, M - 1)(RNG);
void solve() {
int n;
string s;
cin >> n >> s;
int grp = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') continue;
grp++;
int j = i;
while (j < n && s[j] == '1') {
j++;
ans++;
}
i = j-1;
}
if (grp > 1) {
cout << ans+1 << endl;
} else {
cout << ans << endl;
}
}
int main() {
// read read read
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
// read the thing at the bottom
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 2ms
memory: 3600kb
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:
12 7 8 0 2 1 5 7 10 8 10 0 10 6 6 8 12 10 0 10 9 8 3 7 0 7 2 6 5 9 11 5 7 1 8 2 1 9 1 8 12 10 14 5 12 14 16 7 4 5 6 1 1 8 8 6 4 0 0 12 9 5 7 8 7 5 10 1 5 6 13 0 3 11 4 4 8 8 4 8 5 4 8 10 16 3 7 7 10 9 7 1 3 5 2 12 11 6 0 0 5 8 5 8 0 5 8 10 3 4 11 4 7 12 9 1 8 7 5 2 5 10 8 1 6 8 9 4 6 12 7 11 9 9 10 ...
result:
wrong answer 1st numbers differ - expected: '11', found: '12'