Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(pref) pref.begin(), pref.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- const ll inf = 1e18;
- ll t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- vector<string> a(2);
- cin >> a[0];
- cin >> a[1];
- pll f, l;
- for (ll i = 0; i < n; i++) {
- bool fl = false;
- for (ll j = 0; j < 2; j++) {
- if (a[j][i] == '*') {
- f = { j,i };
- fl = true;
- break;
- }
- }
- if (fl)break;
- }
- for (ll i = n-1; i>=0; i--) {
- bool fl = false;
- for (ll j = 0; j < 2; j++) {
- if (a[j][i] == '*') {
- l = { j,i };
- fl = true;
- break;
- }
- }
- if (fl)break;
- }
- vector<vector<ll>> dp(2, vector<ll>(n, 0));
- for (ll i = f.second; i <= l.second; i++) {
- if (i > 0 && i!=f.second) {
- dp[1][i] = dp[1][i - 1] + 1;
- dp[0][i] = dp[0][i - 1] + 1;
- dp[1][i] = min(dp[1][i], dp[0][i] + 1);
- dp[0][i] = min(dp[0][i], dp[1][i] + 1);
- }
- if (a[0][i] == '*') {
- if (a[1][i] == '*') {
- dp[0][i] = min(dp[1][i] + 1, dp[0][i] + 1);
- dp[1][i] = dp[0][i];
- }
- else {
- dp[1][i]++;
- }
- }
- else if (a[1][i] == '*') {
- dp[0][i]++;
- }
- }
- cout << dp[l.first][l.second] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement