#include <bits/stdc++.h>
#define rep(i, p, k) for (int i = (p); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define fi first
#define sc second
#ifndef DEBUG
#define debug(...)
#else
#include "debug.h"
#endif
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
mt19937_64 gen(0xbeeeeeeeee);
vector<int> v;
int n;
{
string a, b, c;
cin >> a >> b >> c;
n = (int)a.size();
v.resize(n);
rep(i, 0, n) v[i] = a[i] + b[i] - c[i] - '0';
}
vector<uint64_t> h(n + 1);
enum st {
NONE,
NINES,
};
enum st state = NONE;
uint64_t p = 0;
rep(i, 0, n) {
if (v[i])
h[i + 1] = gen();
if (v[i] == -1) {
state = NINES;
p = h[i + 1];
} else if (v[i] == 9) {
if (state == NINES)
p ^= h[i + 1];
} else if (v[i] == 10) {
if (state == NINES)
h[i + 1] = p;
state = NONE;
p = 0;
} else {
state = NONE;
p = 0;
}
}
rep(i, 0, n) h[i + 1] ^= h[i];
unordered_map<uint64_t, int> cnt;
cnt[0] = 1;
ll res = 0;
rep(i, 1, n + 1) {
res += cnt[h[i]];
cnt[h[i]]++;
}
cout << res << endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <bits/stdc++.h> #define rep(i, p, k) for (int i = (p); i < (k); ++i) #define all(v) (v).begin(), (v).end() #define ll long long #define fi first #define sc second #ifndef DEBUG #define debug(...) #else #include "debug.h" #endif using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); mt19937_64 gen(0xbeeeeeeeee); vector<int> v; int n; { string a, b, c; cin >> a >> b >> c; n = (int)a.size(); v.resize(n); rep(i, 0, n) v[i] = a[i] + b[i] - c[i] - '0'; } vector<uint64_t> h(n + 1); enum st { NONE, NINES, }; enum st state = NONE; uint64_t p = 0; rep(i, 0, n) { if (v[i]) h[i + 1] = gen(); if (v[i] == -1) { state = NINES; p = h[i + 1]; } else if (v[i] == 9) { if (state == NINES) p ^= h[i + 1]; } else if (v[i] == 10) { if (state == NINES) h[i + 1] = p; state = NONE; p = 0; } else { state = NONE; p = 0; } } rep(i, 0, n) h[i + 1] ^= h[i]; unordered_map<uint64_t, int> cnt; cnt[0] = 1; ll res = 0; rep(i, 1, n + 1) { res += cnt[h[i]]; cnt[h[i]]++; } cout << res << endl; return 0; } |
English