QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321714#5577. Alchemyfrankmd2#WA 1ms3804kbC++142.2kb2024-02-05 09:52:002024-02-05 09:52:01

Judging History

你现在查看的是最新测评结果

  • [2024-02-05 09:52:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2024-02-05 09:52:00]
  • 提交

answer

#include <bits/stdc++.h>
#define forn(i,n) for (int i = 0; i < n; i ++)
#define forse(i,s,e) for (int i = s; i <= e; i ++)
#define forseb(i,s,e) for (int i = s; i >= e; i --)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(x) (x).size()
using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef vector<long long> vll;
typedef vector<int> vi;
const int maxl = 1e5+5;
const int inf = 1e9;
const int modn = 1e9 + 7;

int main() {

#ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int size = sz(s);
    int n = (size + 1) /2;

    if (size == 3) {
        if (s[0] == s[2]) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    if (size == 2) {
        cout << 0 << endl;
        return 0;
    }
    if (size == 4) {
        if (s[0] == s[3]) {
            if (s[1] == s[2]) cout << 0 << endl;
            else cout << 1 << endl;
            return 0;
        }
        else {
            if (s[1] == s[2]) cout << 2 << endl;
            else cout << 1 << endl;
            return 0;
        }
    }

    vector<bool> sb;
    forn(i,n) sb.pb(s[i] == s[size-i-1]);
    vector<pi> dp(n); // first = same,  second = not
    dp[0].first = 0;
    dp[0].second = 0;

    if (sb[0] && sb[1]) dp[1].first = 0, dp[1].second = 2;
    else if (sb[0] && !sb[1]) dp[1].first = 2, dp[1].second = 0;
    else if (!sb[0] & !sb[1]) dp[1].first = 1, dp[1].second = 1;
    else dp[1].first = 2, dp[1].second = 1;

    forse(i,2,n) {
        if (sb[i]) {
            dp[i].first = min(dp[i-1].first, dp[i-1].second + 2);
            dp[i].second = min(dp[i-1].first + 2, dp[i-1].second + 1);
        }
        else {
            dp[i].first = min(dp[i-1].first + 2, dp[i-1].second + 1);
            dp[i].second = min(dp[i-1].first, dp[i-1].second + 1);
        }
    }

    int ans;
    if (size % 2 == 0) ans = dp.rbegin()->first;
    else ans = min(dp.rbegin()->first, dp.rbegin()->second);
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3516kb

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

ctsc

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

fool

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

vetted

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

aa

output:

0

result:

ok single line: '0'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3592kb

input:

ic

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'