mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 18:52:07 +00:00
update
This commit is contained in:
parent
dc42ece1aa
commit
993b5c017b
@ -1,3 +1,63 @@
|
|||||||
int main(){
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
}
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <numeric>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using ll = int64_t;
|
||||||
|
|
||||||
|
static inline void solve() {
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
std::string s1, s2, t1, t2;
|
||||||
|
std::cin >> s1 >> s2 >> t1 >> t2;
|
||||||
|
|
||||||
|
ll ans = 0;
|
||||||
|
std::vector<bool> p(n, false);
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
if (t1[i] == '0' && t2[i] == '0') {
|
||||||
|
if (s1[i] == s2[i]) {
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
p[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < n) {
|
||||||
|
while (idx < n && (p[idx] || t1[idx] == '0' || t2[idx] == '0')) {
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
if (idx >= n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int s = idx;
|
||||||
|
int e = s;
|
||||||
|
while (e + 1 < n && !p[e + 1] && t1[e + 1] == '1' && t2[e + 1] == '1') {
|
||||||
|
e++;
|
||||||
|
}
|
||||||
|
int s10 = 0, s11 = 0;
|
||||||
|
int s20 = 0, s21 = 0;
|
||||||
|
for (int i = s; i <= e; ++i) {
|
||||||
|
if (s1[i] == '0') s10++;
|
||||||
|
else s11++;
|
||||||
|
|
||||||
|
if (s2[i] == '0') s20++;
|
||||||
|
else s21++;
|
||||||
|
}
|
||||||
|
ans += std::min(s10, s20) + std::min(s11, s21);
|
||||||
|
idx = e + 1;
|
||||||
|
}
|
||||||
|
std::cout << ans << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios_base::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
std::cout.tie(nullptr);
|
||||||
|
int T;
|
||||||
|
std::cin >> T;
|
||||||
|
while (T--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
84
src/8/11/P11362.cpp
Normal file
84
src/8/11/P11362.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using ll = long long;
|
||||||
|
using namespace std;
|
||||||
|
const int MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
ll p(ll b, ll e) {
|
||||||
|
ll res = 1;
|
||||||
|
b %= MOD;
|
||||||
|
while (e > 0) {
|
||||||
|
if (e % 2 == 1) res = (res * b) % MOD;
|
||||||
|
b = (b * b) % MOD;
|
||||||
|
e /= 2;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
ll n;
|
||||||
|
int m;
|
||||||
|
ll v;
|
||||||
|
cin >> n >> m >> v;
|
||||||
|
map<int, int> mc;
|
||||||
|
for (int i = 0; i < m; ++i) {
|
||||||
|
int c, d;
|
||||||
|
cin >> c >> d;
|
||||||
|
if (mc.count(c) && mc[c] != d) {
|
||||||
|
for (int j = i + 1; j < m; ++j) cin >> c >> d;
|
||||||
|
cout << 0 << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mc[c] = d;
|
||||||
|
}
|
||||||
|
if (m == 0) {
|
||||||
|
if (n == 1) {
|
||||||
|
cout << 1 << endl;
|
||||||
|
} else {
|
||||||
|
cout << p(v, (n - 1) * 2) << endl;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ll tot = 1;
|
||||||
|
ll vmod = v % MOD;
|
||||||
|
int lp = 0;
|
||||||
|
for (auto const& [idx, val] : mc) {
|
||||||
|
ll len = idx - lp;
|
||||||
|
if (len > 0) {
|
||||||
|
ll s;
|
||||||
|
if (lp == 0) {
|
||||||
|
s = p(vmod, (len - 1) * 2);
|
||||||
|
} else {
|
||||||
|
ll v2len = p(vmod, len * 2);
|
||||||
|
ll vlen = p(vmod, len);
|
||||||
|
ll vlenm1 = p(vmod, len - 1);
|
||||||
|
s = (v2len - vlen + vlenm1 + MOD) % MOD;
|
||||||
|
}
|
||||||
|
tot = (tot * s) % MOD;
|
||||||
|
}
|
||||||
|
lp = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (lp < n) {
|
||||||
|
ll len = n - lp;
|
||||||
|
|
||||||
|
|
||||||
|
ll s = p(vmod, len * 2);
|
||||||
|
tot = (tot * s) % MOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << tot << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ios_base::sync_with_stdio(false);
|
||||||
|
cin.tie(NULL);
|
||||||
|
cout.tie(nullptr);
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
while (t--) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user