QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182341 | #5577. Alchemy | ytck | WA | 0ms | 3896kb | C++14 | 1.5kb | 2023-09-17 19:20:12 | 2023-09-17 19:20:13 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N = 110;
int f[N][N][2];//左边是位置i,右边是位置j,k是上一次有没有变
string s;
int dp(int l, int r, int is)
{
if (l >= r) return 0;
int& ans = f[l][r][is];
if (ans != -1) return ans;
ans = dp(l + 2, r - 2, 0) + 2;//每次左右往里面跳两格,因为我们变是一次变两个
//+2是因为我们最多两次就能转化,+2就不会影响我们后面的min
if (is && s[l] != s[r])//上一位我们转变了,这一位还是不相同,那么就代表我们两个都不一样,转一次就可以转出来了
ans = min(ans, dp(l + 1, r - 1, 0));//is=0,因为这一次我们不用转变
if (!is && s[l] == s[r])//我们没转变且这两位相等,这两位本来就构成回文,我们直接跳
ans = min(ans, dp(l + 1, r - 1, 0));
//if (is || s[l] != s[r])
// ans = min(ans, dp(l + 1, r - 1, 1) + 1);
if (is && s[l] == s[r])//上一次转变了但是这一位相等,我们需要再转变一次,因为我们转变不能和这两位相等
ans = min(ans, dp(l + 1, r - 1, 1) + 1);
if (!is && s[l] != s[r])//上一次没转变但是这一位不相等,我们肯定要转变
ans = min(ans, dp(l + 1, r - 1, 1) + 1);
return ans;
}
signed main()
{
cin >> s;
memset(f, -1, sizeof f);
cout << dp(0, s.size() - 1, 0) << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
12
result:
ok single line: '12'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
qrgld
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy
output:
26
result:
ok single line: '26'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
xcpccpcy
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
abpccpcp
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
ixpccpci
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
xcxccpci
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
xcpxcpci
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
ixxccpci
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
ixpxcpci
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
ixpxxycpci
output:
3
result:
ok single line: '3'
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 3736kb
input:
yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx
output:
21
result:
wrong answer 1st lines differ - expected: '19', found: '21'