QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321715 | #5577. Alchemy | frankmd2# | WA | 0ms | 3840kb | C++14 | 2.2kb | 2024-02-05 09:54:08 | 2024-02-05 09:54:09 |
Judging History
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-1) {
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: 0ms
memory: 3568kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
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: 0ms
memory: 3632kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3800kb
input:
ic
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'