alg2025/src/7/26/T640604d.cpp
Zengtudor cfd99025a7 Add input and output files for typer1 and typer2, and paint2 output
- Created `paint2.out` with a single output value.
- Added `typer1.in` and `typer1.out` for the first typing problem with multiple queries.
- Introduced `typer2.in` and `typer2.out` for the second typing problem, containing extensive input data and corresponding outputs.
2025-07-26 11:57:35 +08:00

45 lines
1.0 KiB
C++

#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = int64_t;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string S, T;
cin >> S >> T;
ll m;
cin >> m;
ll lenT = T.size();
while (m--) {
ll l, r;
cin >> l >> r;
ll lenA = r - l + 1;
ll start = l - 1;
vector<ll> dp(lenT + 1);
for (ll j = 0; j <= lenT; j++) {
dp[j] = j;
}
for (ll i = 0; i < lenA; i++) {
vector<ll> ndp(lenT + 1);
ndp[0] = i + 1;
char c = S[start + i];
for (ll j = 1; j <= lenT; j++) {
ll cost = (c == T[j-1]) ? 0 : 1;
ll op1 = dp[j] + 1;
ll op2 = ndp[j-1] + 1;
ll op3 = dp[j-1] + cost;
ndp[j] = min({op1, op2, op3});
}
dp = std::move(ndp);
}
cout << dp[lenT] << '\n';
}
return 0;
}