QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575136 | #5562. Jesting Jabberwocky | V-ioleT | AC ✓ | 488ms | 11328kb | C++20 | 1.9kb | 2024-09-19 10:50:13 | 2024-09-19 10:50:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define ull unsigned long long
typedef long long ll;
#define lowbit(x) ((x) & -(x))
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5, M = 1e5 + 10;
typedef pair<int, int> PII;
double T = 1 >> 30;
// double PI = acos(-1);
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b)
{
return a / gcd(a, b) * b;
}
void solve()
{
int i, j;
string s;
cin >> s;
int n = s.size();
s = '?' + s;
vector<int> v;
v.push_back(0);
for (i = 1; i <= n;i++)
{
if(s[i]=='h')
{
v.push_back(1);
}else if(s[i]=='c')
{
v.push_back(2);
}else if(s[i]=='d')
{
v.push_back(3);
}else{
v.push_back(4);
}
}
vector<int> p;
for (i = 0; i <= 4;i++)
{
p.push_back(i);
}
int res = 1e5 + 5;
do
{
vector<vector<int>> f(n + 1, vector<int>(5, 1e6));
f[0][0] = 0;
for (i = 1; i <= n;i++)
{
int t = p[v[i]];
for (j = 0; j <= 4;j++)
{
if(j!=t)
f[i][j] = f[i - 1][j] + 1;
}
for (j = 0; j <= t;j++)
{
f[i][t] = min(f[i][t], f[i - 1][j]);
}
}
for (i = 0; i <= 4;i++)
{
res = min(res, f[n][i]);
}
} while (next_permutation(p.begin(), p.end()));
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
{
// Case++;
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
input:
hccdhcd
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
cchhdshcdshdcsh
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
c
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
cchhhddss
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
chchchch
output:
3
result:
ok single line: '3'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
cccchhccddcccccsscccc
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
shhssdsddsddcddhchss
output:
8
result:
ok single line: '8'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
cshhscshdscscchssshs
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
hchdschhdhchhdcssccs
output:
8
result:
ok single line: '8'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
chchcsdcchdhdcsdssdh
output:
9
result:
ok single line: '9'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
shhdhchcdhcssdcssdss
output:
8
result:
ok single line: '8'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
ddcdsdsddhshdshhchdh
output:
8
result:
ok single line: '8'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
sdhsccsshchsshsshshs
output:
8
result:
ok single line: '8'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
cdddccdssdhhhshdcchh
output:
7
result:
ok single line: '7'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
ddcddhdshdhdcdcshcss
output:
8
result:
ok single line: '8'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
csddhhshhddsdccdcsds
output:
8
result:
ok single line: '8'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
hdcshcscdhddhhdshchc
output:
10
result:
ok single line: '10'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
hchshdcdshddshshshdc
output:
9
result:
ok single line: '9'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
ccddhsddccdshdcddddd
output:
7
result:
ok single line: '7'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
ssdssccdhdsdsdccshcc
output:
8
result:
ok single line: '8'
Test #21:
score: 0
Accepted
time: 434ms
memory: 10396kb
input:
schhchsshscsdschhshddsdhchchshddhddchchdsdchcddddshcscsdhscsddchdcscshdsdddhsdhdchcdcdcsdhhshcsccdchhschshhsdschhhcdchsshdcdhschhdchcddcccchdhcchshhcshdshdssdddhcchdccddhcsshhcdddcdhcchdhddchdshshcscdsdcchchdhcshhscsdchhsdcdhdshdcsdhhhdcddcscdddssccdddccscsdcscchdcsdccdscdshhccchdsscdhhsccsssdcdcsdc...
output:
67475
result:
ok single line: '67475'
Test #22:
score: 0
Accepted
time: 374ms
memory: 10136kb
input:
hsccchcdssddsschddchdcdhdhshccchddcshdcsdcdcccshscccchhhdccshhhsdhcchddhdshssdsccdshdshdcccccchsdhhsdhdscdccdscddcccsssdddshsdhcdcsshhdsshssshdhhhsdcshcccdcsscdhdddhsdsshhddchsdhsssdscddcsccsshccccccshhchdhhhchcccsddchhdhhcschssdccshdscdhhhdsdshdhssdsshdhddcchhhhddchhsssdsdchshscccschcdchchhdcdhscdh...
output:
62915
result:
ok single line: '62915'
Test #23:
score: 0
Accepted
time: 144ms
memory: 5680kb
input:
hshhcsshsdsdchsshdssdchdcsdshccdsshdchsshhcssshcshshhcddhshsdhdcsdhchshdhchhsschhscdhccdcschcsdhddddchchddhhscssccdhhhhhcdchhhhshhdchchcchcshdhdhcddcdhschddsssdcsdhhdsccddcdhcccsshdshshcchschddchshshsdhdhcsdchdchdsssscdschccssdhschcccssddsshhdchhsscdsshcdssdssscsscdhchcsdcchscdsdhhsdshhhccddhsshhdds...
output:
24067
result:
ok single line: '24067'
Test #24:
score: 0
Accepted
time: 4ms
memory: 3652kb
input:
sssdsdchhshdcsccdhdsddsdshchhschdhsschhsshchdcsscdchsshschhsscdshschcddshdsdddshcdhhsscsdchcshddchsdschhdhhdscscsdsdhcdsccdhhshhchshshccccshdcdddddddshsdchchcsddhcchchhsdhcddcsshcsshdhdhscsdhsdshhcdddcshsdhshhssddcdchdsdhcdshsschdschdhdccdhshcdhhhhddcchddchsdhhsccddsdcsscdhhsdscshccssschdsdchccdcdhh...
output:
638
result:
ok single line: '638'
Test #25:
score: 0
Accepted
time: 484ms
memory: 11328kb
input:
hdhccsdhdddcddcdccddddsssdccchshhcchshhschcdsdcdssscshdsschdhshdsdhsschccshscchcddcdhdchsdccdsshdsdchddsccddcsddhcsdchdccsccddshhdchsdddscsdhcccshhdscscshsssscdcschdhscssddscshcddccchsddcchcdhsscdchdhdchsccschcdsdscdhddcdssdddhhsdsdccdshshdschdhhhscshssccdhsddhsdhshchhhhcschdssdddhcdddhdshhcdhhsschd...
output:
74459
result:
ok single line: '74459'
Test #26:
score: 0
Accepted
time: 439ms
memory: 11152kb
input:
dhdssscccshcdhhcsdhhdcschhshcchdcsddshshchhhchddhsshcdddsssdsshscscshdsdccshdscschsdscdhhshhdhhhhdhshhdhsdhhccchccchhhcschshdcddhssdsdsddccdsshdchcsdhhdcsdddcshhcdhchcscsdhchhhcdsdddsdccdddhdhddsscsddsddschshdssccchcshhscshddhdhdsddcdddsscdcsdhsdddhscdsshcscdcdhdssdhdscdchcsdhscshcdsshcdchcsdhsdhddd...
output:
74427
result:
ok single line: '74427'
Test #27:
score: 0
Accepted
time: 456ms
memory: 11120kb
input:
hcdchhsdcshhhhcsscsdsdcshchdhhdcchccdchsdsddchcdchdcssshhcdhchsdccsschshcssshdshcdchdshhhcchscshccsshdddcshsccddsshchhsddshccsshsddcdscccddhcsddssccdchsshccshsdsscsdcdssdhhddcccchhsssdhscdhshccsshddcsdshcdddshdshhddchdscscdhhhhddcsddchhcccdshcdcccddscscdsccchhccdddcscscdhsdhhhchcccdccddsdhhchhchdcsh...
output:
74431
result:
ok single line: '74431'
Test #28:
score: 0
Accepted
time: 443ms
memory: 11200kb
input:
cdcdshhhhdsshdsdchhccdcsshsdsshdhshdshhddsdshdchsccsccdhcdshsdscdcdcsshhsdchsscdsshcshssdddshcdsscchhddhchsdsshccdhchdhhhcchdhccscshcchcchddhccscdhsdhsshsssddddcchdchssddhchsdhhdsccsdsdhchchhcchdchhscddcsdcdsddcddchdcshchschdhdhchddccchchcshccsdcccdcdcdhsddddchchshchdhsshhdhccsdhhcdscsscsshchcdhcdhc...
output:
74497
result:
ok single line: '74497'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
dcshshcdschdschdhscdcdshhdcsdhcsshdcshdcchsddhcshcsdsdchdchshcsdscdhhdsccsdhhdcsshdchscddshcsdchsdhc
output:
72
result:
ok single line: '72'
Test #30:
score: 0
Accepted
time: 439ms
memory: 11128kb
input:
chdsdhcscdhscdhsdcshsdchshdcdhcssdchhcdsdchsdchsschdhcsdchsddschcshdcsdhhcsddchssdhcchsdscdhschdchdsdchsdshcshcdcshdscdhhsdchcsdhdschdscshcddschhcdsdschhscddshcshdcshcdschdhcsdcdshshdchdschdcsdchscshddcshscdhcdshdshcchsdshdchcsddcshschddschcdshdshcdshcsdhcchdsdschsdchhdscchsddschdhsccdshhsdcdschhdcs...
output:
74997
result:
ok single line: '74997'
Test #31:
score: 0
Accepted
time: 488ms
memory: 11120kb
input:
cccccccccccscccccccccccccccccccccccccccsccccccccccccccccccccccccccccccccccccccccccccccsccccccccccccccccsccccccccccccccsccccccsccccsccchcsccsccccccccsccccccccccccccccsccccccscccccssscccccccccccccccscccccccccsccccccscccccccccsccsccccccccccccccccsccscchccccscccccccsccscccccccscccccccccccsccsccccccscccc...
output:
57178
result:
ok single line: '57178'
Test #32:
score: 0
Accepted
time: 422ms
memory: 11148kb
input:
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccchhcccccchcccccccccccccccccccchccccccccccccccchccccccccccccccccccccccchccccccccccccccccccccccchcccccccchccccccccccccccccccccccccccccccccchcccchcccccccccccccccccccccccccchcccccccccccchccccccchcccccccccccc...
output:
35623
result:
ok single line: '35623'
Test #33:
score: 0
Accepted
time: 390ms
memory: 11036kb
input:
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
23657
result:
ok single line: '23657'
Test #34:
score: 0
Accepted
time: 38ms
memory: 4000kb
input:
dddcdddddddddddddddcdddddddddddddddddhddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsddddddddddddddddddddddddd...
output:
69
result:
ok single line: '69'
Test #35:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
cccccccccchccccccccccccccccccccccccccccccccccccchhshhhhhhhhshhhhhhhhdhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdddddddddddddddddddddddddddddddddddcddddddddddddddssssssssshssscssssssssscssssshssssssssssssssssssssss
output:
9
result:
ok single line: '9'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
cchhdhssdcddchccddhsdsshcdhhdhdccshcssss
output:
21
result:
ok single line: '21'