QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373760 | #5562. Jesting Jabberwocky | kevinyang# | AC ✓ | 131ms | 11236kb | C++17 | 1.1kb | 2024-04-02 04:23:49 | 2024-04-02 04:23:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
s = " " + s;
vector<int>arr(n+1);
for(int i = 1; i<=n; i++){
if(s[i] == 'c')arr[i] = 0;
if(s[i] == 'd')arr[i] = 1;
if(s[i] == 'h')arr[i] = 2;
if(s[i] == 's')arr[i] = 3;
}
int ans = 0;
vector<int>perm = {0,1,2,3};
do{
vector<vector<int>>dp(n+1,vector<int>(4));
for(int i = 1; i<=n; i++){
for(int j = 0; j<4; j++){
for(int k = j; k<4; k++){
dp[i][k] = max(dp[i][k],dp[i-1][j]);
}
}
int idx = 0;
for(int j = 0; j<4; j++){
if(perm[j] == arr[i]){
idx = j;
break;
}
}
dp[i][idx]++;
}
/*
for(int nxt: perm){
cout << nxt << ' ';
}
cout << '\n';
cout << '\n';
for(int i = 1; i<=n; i++){
for(int j = 0; j<4; j++){
cout << dp[i][j] << ' ';
}
cout << '\n';
}
cout << '\n';
*/
ans = max({ans,dp[n][0],dp[n][1],dp[n][2],dp[n][3]});
}
while(next_permutation(perm.begin(),perm.end()));
cout << n-ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
hccdhcd
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
cchhdshcdshdcsh
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
c
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
cchhhddss
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
chchchch
output:
3
result:
ok single line: '3'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
cccchhccddcccccsscccc
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
shhssdsddsddcddhchss
output:
8
result:
ok single line: '8'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
cshhscshdscscchssshs
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
hchdschhdhchhdcssccs
output:
8
result:
ok single line: '8'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
chchcsdcchdhdcsdssdh
output:
9
result:
ok single line: '9'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
shhdhchcdhcssdcssdss
output:
8
result:
ok single line: '8'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
ddcdsdsddhshdshhchdh
output:
8
result:
ok single line: '8'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
sdhsccsshchsshsshshs
output:
8
result:
ok single line: '8'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
cdddccdssdhhhshdcchh
output:
7
result:
ok single line: '7'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
ddcddhdshdhdcdcshcss
output:
8
result:
ok single line: '8'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
csddhhshhddsdccdcsds
output:
8
result:
ok single line: '8'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
hdcshcscdhddhhdshchc
output:
10
result:
ok single line: '10'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
hchshdcdshddshshshdc
output:
9
result:
ok single line: '9'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
ccddhsddccdshdcddddd
output:
7
result:
ok single line: '7'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
ssdssccdhdsdsdccshcc
output:
8
result:
ok single line: '8'
Test #21:
score: 0
Accepted
time: 99ms
memory: 10404kb
input:
schhchsshscsdschhshddsdhchchshddhddchchdsdchcddddshcscsdhscsddchdcscshdsdddhsdhdchcdcdcsdhhshcsccdchhschshhsdschhhcdchsshdcdhschhdchcddcccchdhcchshhcshdshdssdddhcchdccddhcsshhcdddcdhcchdhddchdshshcscdsdcchchdhcshhscsdchhsdcdhdshdcsdhhhdcddcscdddssccdddccscsdcscchdcsdccdscdshhccchdsscdhhsccsssdcdcsdc...
output:
67475
result:
ok single line: '67475'
Test #22:
score: 0
Accepted
time: 93ms
memory: 9924kb
input:
hsccchcdssddsschddchdcdhdhshccchddcshdcsdcdcccshscccchhhdccshhhsdhcchddhdshssdsccdshdshdcccccchsdhhsdhdscdccdscddcccsssdddshsdhcdcsshhdsshssshdhhhsdcshcccdcsscdhdddhsdsshhddchsdhsssdscddcsccsshccccccshhchdhhhchcccsddchhdhhcschssdccshdscdhhhdsdshdhssdsshdhddcchhhhddchhsssdsdchshscccschcdchchhdcdhscdh...
output:
62915
result:
ok single line: '62915'
Test #23:
score: 0
Accepted
time: 35ms
memory: 5812kb
input:
hshhcsshsdsdchsshdssdchdcsdshccdsshdchsshhcssshcshshhcddhshsdhdcsdhchshdhchhsschhscdhccdcschcsdhddddchchddhhscssccdhhhhhcdchhhhshhdchchcchcshdhdhcddcdhschddsssdcsdhhdsccddcdhcccsshdshshcchschddchshshsdhdhcsdchdchdsssscdschccssdhschcccssddsshhdchhsscdsshcdssdssscsscdhchcsdcchscdsdhhsdshhhccddhsshhdds...
output:
24067
result:
ok single line: '24067'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3840kb
input:
sssdsdchhshdcsccdhdsddsdshchhschdhsschhsshchdcsscdchsshschhsscdshschcddshdsdddshcdhhsscsdchcshddchsdschhdhhdscscsdsdhcdsccdhhshhchshshccccshdcdddddddshsdchchcsddhcchchhsdhcddcsshcsshdhdhscsdhsdshhcdddcshsdhshhssddcdchdsdhcdshsschdschdhdccdhshcdhhhhddcchddchsdhhsccddsdcsscdhhsdscshccssschdsdchccdcdhh...
output:
638
result:
ok single line: '638'
Test #25:
score: 0
Accepted
time: 104ms
memory: 11076kb
input:
hdhccsdhdddcddcdccddddsssdccchshhcchshhschcdsdcdssscshdsschdhshdsdhsschccshscchcddcdhdchsdccdsshdsdchddsccddcsddhcsdchdccsccddshhdchsdddscsdhcccshhdscscshsssscdcschdhscssddscshcddccchsddcchcdhsscdchdhdchsccschcdsdscdhddcdssdddhhsdsdccdshshdschdhhhscshssccdhsddhsdhshchhhhcschdssdddhcdddhdshhcdhhsschd...
output:
74459
result:
ok single line: '74459'
Test #26:
score: 0
Accepted
time: 105ms
memory: 11072kb
input:
dhdssscccshcdhhcsdhhdcschhshcchdcsddshshchhhchddhsshcdddsssdsshscscshdsdccshdscschsdscdhhshhdhhhhdhshhdhsdhhccchccchhhcschshdcddhssdsdsddccdsshdchcsdhhdcsdddcshhcdhchcscsdhchhhcdsdddsdccdddhdhddsscsddsddschshdssccchcshhscshddhdhdsddcdddsscdcsdhsdddhscdsshcscdcdhdssdhdscdchcsdhscshcdsshcdchcsdhsdhddd...
output:
74427
result:
ok single line: '74427'
Test #27:
score: 0
Accepted
time: 131ms
memory: 11012kb
input:
hcdchhsdcshhhhcsscsdsdcshchdhhdcchccdchsdsddchcdchdcssshhcdhchsdccsschshcssshdshcdchdshhhcchscshccsshdddcshsccddsshchhsddshccsshsddcdscccddhcsddssccdchsshccshsdsscsdcdssdhhddcccchhsssdhscdhshccsshddcsdshcdddshdshhddchdscscdhhhhddcsddchhcccdshcdcccddscscdsccchhccdddcscscdhsdhhhchcccdccddsdhhchhchdcsh...
output:
74431
result:
ok single line: '74431'
Test #28:
score: 0
Accepted
time: 117ms
memory: 11116kb
input:
cdcdshhhhdsshdsdchhccdcsshsdsshdhshdshhddsdshdchsccsccdhcdshsdscdcdcsshhsdchsscdsshcshssdddshcdsscchhddhchsdsshccdhchdhhhcchdhccscshcchcchddhccscdhsdhsshsssddddcchdchssddhchsdhhdsccsdsdhchchhcchdchhscddcsdcdsddcddchdcshchschdhdhchddccchchcshccsdcccdcdcdhsddddchchshchdhsshhdhccsdhhcdscsscsshchcdhcdhc...
output:
74497
result:
ok single line: '74497'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
dcshshcdschdschdhscdcdshhdcsdhcsshdcshdcchsddhcshcsdsdchdchshcsdscdhhdsccsdhhdcsshdchscddshcsdchsdhc
output:
72
result:
ok single line: '72'
Test #30:
score: 0
Accepted
time: 105ms
memory: 11116kb
input:
chdsdhcscdhscdhsdcshsdchshdcdhcssdchhcdsdchsdchsschdhcsdchsddschcshdcsdhhcsddchssdhcchsdscdhschdchdsdchsdshcshcdcshdscdhhsdchcsdhdschdscshcddschhcdsdschhscddshcshdcshcdschdhcsdcdshshdchdschdcsdchscshddcshscdhcdshdshcchsdshdchcsddcshschddschcdshdshcdshcsdhcchdsdschsdchhdscchsddschdhsccdshhsdcdschhdcs...
output:
74997
result:
ok single line: '74997'
Test #31:
score: 0
Accepted
time: 117ms
memory: 11236kb
input:
cccccccccccscccccccccccccccccccccccccccsccccccccccccccccccccccccccccccccccccccccccccccsccccccccccccccccsccccccccccccccsccccccsccccsccchcsccsccccccccsccccccccccccccccsccccccscccccssscccccccccccccccscccccccccsccccccscccccccccsccsccccccccccccccccsccscchccccscccccccsccscccccccscccccccccccsccsccccccscccc...
output:
57178
result:
ok single line: '57178'
Test #32:
score: 0
Accepted
time: 107ms
memory: 11008kb
input:
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccchhcccccchcccccccccccccccccccchccccccccccccccchccccccccccccccccccccccchccccccccccccccccccccccchcccccccchccccccccccccccccccccccccccccccccchcccchcccccccccccccccccccccccccchcccccccccccchccccccchcccccccccccc...
output:
35623
result:
ok single line: '35623'
Test #33:
score: 0
Accepted
time: 126ms
memory: 11108kb
input:
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
23657
result:
ok single line: '23657'
Test #34:
score: 0
Accepted
time: 4ms
memory: 3992kb
input:
dddcdddddddddddddddcdddddddddddddddddhddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsddddddddddddddddddddddddd...
output:
69
result:
ok single line: '69'
Test #35:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
cccccccccchccccccccccccccccccccccccccccccccccccchhshhhhhhhhshhhhhhhhdhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdddddddddddddddddddddddddddddddddddcddddddddddddddssssssssshssscssssssssscssssshssssssssssssssssssssss
output:
9
result:
ok single line: '9'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
cchhdhssdcddchccddhsdsshcdhhdhdccshcssss
output:
21
result:
ok single line: '21'