結果

問題 No.2209 Flip and Reverse
ユーザー kztasakztasa
提出日時 2023-02-10 21:25:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 4,295 bytes
コンパイル時間 3,699 ms
コンパイル使用メモリ 232,988 KB
実行使用メモリ 7,192 KB
最終ジャッジ日時 2023-09-21 22:26:39
合計ジャッジ時間 6,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 40 ms
7,020 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 45 ms
6,964 KB
testcase_15 AC 45 ms
7,032 KB
testcase_16 AC 45 ms
7,024 KB
testcase_17 AC 45 ms
6,904 KB
testcase_18 AC 45 ms
6,976 KB
testcase_19 AC 45 ms
6,928 KB
testcase_20 AC 45 ms
7,036 KB
testcase_21 AC 45 ms
6,968 KB
testcase_22 AC 45 ms
6,928 KB
testcase_23 AC 45 ms
6,960 KB
testcase_24 AC 44 ms
7,024 KB
testcase_25 AC 44 ms
6,904 KB
testcase_26 AC 44 ms
6,964 KB
testcase_27 AC 45 ms
6,932 KB
testcase_28 AC 40 ms
6,904 KB
testcase_29 AC 41 ms
7,192 KB
testcase_30 AC 41 ms
7,052 KB
testcase_31 AC 41 ms
7,032 KB
testcase_32 AC 41 ms
6,980 KB
testcase_33 AC 40 ms
6,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
#include <atcoder/all>

#define pub push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;


using namespace atcoder;
using mint = modint998244353;
using mint2 = modint1000000007;

constexpr long long INF = (1LL << 60);
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589;


template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
T sq(T x) {
    return x * x;
}

std::string zfill(int n, const int width)
{
    std::stringstream ss;
    ss << std::setw(width) << std::setfill('0') << n;
    return ss.str();
}


//多倍長整数を(string→vector)に変換
vector<ll> digit(string s) {
    ll n = s.size();
    vector<ll> d(n);
    rep(i, n) {
        d[i] = s[i] - '0';
    }
    return d;
}


//多倍長整数の足し算
vector<ll> adds(vector<ll> s, vector<ll> t) {
    ll n = s.size();
    ll m = t.size();
    if (n > m) { swap(s, t); n = s.size(); m = t.size(); }
    reverse(ALL(s));
    reverse(ALL(t));
    rep(i, m - n) {
        s.pub(0);
    }
    bool kuriage = false;
    rep(i, m) {
        ll a = s[i];
        ll b = t[i];
        ll c = a + b;
        if (kuriage) {
            c++;
        }
        if (c >= 10) {
            c -= 10; kuriage = true;
        }
        else {
            kuriage = false;
        }
        t[i] = c;
    }
    if (kuriage) {
        t.pub(1);
    }
    reverse(ALL(t));
    return t;
}


vector<ll> carry_and_fix(vector<ll> digit) {
    int N = digit.size();

    for (int i = 0; i < N - 1; ++i) {
        // 繰り上がり処理 (K は繰り上がりの回数)
        if (digit[i] >= 10) {
            int K = digit[i] / 10;
            digit[i] -= K * 10;
            digit[i + 1] += K;
        }
        // 繰り下がり処理 (K は繰り下がりの回数)
        if (digit[i] < 0) {
            int K = (-digit[i] - 1) / 10 + 1;
            digit[i] += K * 10;
            digit[i + 1] -= K;
        }
    }
    // 一番上の桁が 10 以上なら、桁数を増やすことを繰り返す
    while (digit.back() >= 10) {
        int K = digit.back() / 10;
        digit.back() -= K * 10;
        digit.push_back(K);
    }
    // 1 桁の「0」以外なら、一番上の桁の 0 (リーディング・ゼロ) を消す
    while (digit.size() >= 2 && digit.back() == 0) {
        digit.pop_back();
    }
    reverse(ALL(digit));
    return digit;
}


//多倍長整数の掛け算(s × t) 計算量は N(|s||t|)?
vector<ll> mul(vector<ll> s, vector<ll> t) {
    reverse(ALL(s));
    reverse(ALL(t));
    ll NA = s.size();
    ll NB = t.size();
    vector<ll> res(NA + NB - 1);
    for (int i = 0; i < NA; ++i) {
        for (int j = 0; j < NB; ++j) {
            res[i + j] += s[i] * t[j];
        }
    }
    return carry_and_fix(res);
}


/*  make_is_prime(N)
    入力:整数 N
    出力:N までの数字が素数か判定したベクトル(i番目がtrueならiは素数)
    計算量:O(nloglogn)
*/
vector< bool > prime_table(int n) {
    vector< bool > prime(n + 1, true);
    if (n >= 0) prime[0] = false;
    if (n >= 1) prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!prime[i]) continue;
        for (int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}

int main() {
    //cout << fixed << setprecision(10);
    ll N; cin >> N;
    string S, T; cin >> S >> T;
    ll a = 0, b = 0;
    ll ans = INF;
    rep(i, N) {
        if (S[i] != T[i]) {
            a++;
        }
    }
    if (a % 2 == 0) {
        chmin(ans, a);
    }
    rep(i, N) {
        if (S[N - 1 - i] != T[i]) {
            b++;
        }
    }
    if (b % 2 == 1) {
        chmin(ans, b);
    }
    cout << ans << endl;
}







0