QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664815 | #6841. Occupy the Cities | HHAZ | WA | 1ms | 3836kb | C++20 | 2.3kb | 2024-10-21 22:31:42 | 2024-10-21 22:31:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef pair<ld,ld>pdd;
typedef pair<ll, pair<ll, ll> > plpair;
typedef vector<int> vi;
typedef vector<ll> vl;
#define endl '\n'
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for(ll i = (a); i >= (b); --i)
#define debug(x) cout<<#x<<": "<<x<<endl
#define lowbit(id) id & (-id)
#define fi first
#define sec second
#define lc id<<1
#define rc id<<1|1
#define sz(x) (int)(x).size()
#define all(t) (t).begin(), (t).end()
#define meh {cout<<"NO"<<endl;return;}
#define yay {cout<<"YES"<<endl;return;}
#define vin(v) for(auto&x:v)cin>>x;
#define print(v) for (auto x: v)cout<<x<<' ';cout<<endl;
#define sqrt(x) sqrtl(x)
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 3e5 + 10;
const int mod = 998244353;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
s = '|' + s;
int dp[n + 5][2];
int f = 0, zero;
rep(i, 1, n) {
if(s[i] == '1') {
if(f) {
zero = i - f - 1;
dp[i][0] = min(dp[f][0] + max(0, zero - max(0, dp[f][0] - 1) - dp[f][0]), dp[f][1] + max(0, zero - dp[f][1] - dp[f][1]));
dp[i][1] = min(dp[f][0] + max(0, zero - max(0, dp[f][0] - 1) + 1 - dp[f][0]), dp[f][1] + max(0, zero - dp[f][1] + 1 - dp[f][1]));
}
else {
dp[i][0] = i - 1;
dp[i][1] = i;
}
f = i;
}
}
zero = n - f;
cout << min(dp[f][0] + max(0, zero - max(0, dp[f][0] - 1)), dp[f][1] + max(0, zero - dp[f][1])) << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
// cout.flush();
// ofstream outfile("C:\\Users\\86187\\OneDrive\\桌面\\1.txt");
// outfile << "a[1]=0;a[2]=1;";
// ll l = 1e7 + 1;
// rep(i, 3, 1e9) {
// printf("%lld\n", i);
// ll x = (i - 1) * ((a[i - 1] + a[i - 2]) % mod);
// x %= mod;
// if(i == l) {
// outfile << "a[" << i << "]=" << x << ";";
// }
// if(i == l + 1) {
// outfile << "a[" << i << "]=" << x << ";";
// l += 1e7;
// }
// }
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
input:
5 3 010 4 0100 7 0001000 5 11111 6 010101
output:
2 2 4 0 1
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
2036 1 1 2 01 2 10 2 11 3 001 3 010 3 011 3 100 3 101 3 110 3 111 4 0001 4 0010 4 0011 4 0100 4 0101 4 0110 4 0111 4 1000 4 1001 4 1010 4 1011 4 1100 4 1101 4 1110 4 1111 5 00001 5 00010 5 00011 5 00100 5 00101 5 00110 5 00111 5 01000 5 01001 5 01010 5 01011 5 01100 5 01101 5 01110 5 01111 5 10000 5...
output:
0 1 1 0 2 2 1 2 1 1 0 3 2 2 2 1 1 1 3 1 1 1 2 1 1 0 4 3 3 3 2 2 2 3 2 2 1 2 1 1 1 4 2 2 1 2 1 1 1 3 1 1 1 2 1 1 0 5 4 4 3 3 3 3 3 2 2 2 2 2 2 2 4 2 2 2 2 1 1 1 3 1 1 1 2 1 1 1 5 3 2 2 2 1 1 1 3 1 1 1 2 1 1 1 4 2 2 1 2 1 1 1 3 1 1 1 2 1 1 0 6 5 5 4 4 4 4 4 3 3 3 3 3 3 3 4 2 2 2 2 2 2 2 3 2 2 2 2 2 2 ...
result:
wrong answer 90th lines differ - expected: '2', found: '3'