QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575134#5562. Jesting JabberwockyV-ioleTAC ✓470ms11372kbC++201.9kb2024-09-19 10:49:322024-09-19 10:49:33

Judging History

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

  • [2024-09-19 10:49:33]
  • 评测
  • 测评结果:AC
  • 用时:470ms
  • 内存:11372kb
  • [2024-09-19 10:49:32]
  • 提交

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, INF));
        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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

hccdhcd

output:

2

result:

ok single line: '2'

Test #2:

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

input:

cchhdshcdshdcsh

output:

7

result:

ok single line: '7'

Test #3:

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

input:

c

output:

0

result:

ok single line: '0'

Test #4:

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

input:

cchhhddss

output:

0

result:

ok single line: '0'

Test #5:

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

input:

chchchch

output:

3

result:

ok single line: '3'

Test #6:

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

input:

cccchhccddcccccsscccc

output:

6

result:

ok single line: '6'

Test #7:

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

input:

shhssdsddsddcddhchss

output:

8

result:

ok single line: '8'

Test #8:

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

input:

cshhscshdscscchssshs

output:

9

result:

ok single line: '9'

Test #9:

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

input:

hchdschhdhchhdcssccs

output:

8

result:

ok single line: '8'

Test #10:

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

input:

chchcsdcchdhdcsdssdh

output:

9

result:

ok single line: '9'

Test #11:

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

input:

shhdhchcdhcssdcssdss

output:

8

result:

ok single line: '8'

Test #12:

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

input:

ddcdsdsddhshdshhchdh

output:

8

result:

ok single line: '8'

Test #13:

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

input:

sdhsccsshchsshsshshs

output:

8

result:

ok single line: '8'

Test #14:

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

input:

cdddccdssdhhhshdcchh

output:

7

result:

ok single line: '7'

Test #15:

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

input:

ddcddhdshdhdcdcshcss

output:

8

result:

ok single line: '8'

Test #16:

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

input:

csddhhshhddsdccdcsds

output:

8

result:

ok single line: '8'

Test #17:

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

input:

hdcshcscdhddhhdshchc

output:

10

result:

ok single line: '10'

Test #18:

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

input:

hchshdcdshddshshshdc

output:

9

result:

ok single line: '9'

Test #19:

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

input:

ccddhsddccdshdcddddd

output:

7

result:

ok single line: '7'

Test #20:

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

input:

ssdssccdhdsdsdccshcc

output:

8

result:

ok single line: '8'

Test #21:

score: 0
Accepted
time: 429ms
memory: 10504kb

input:

schhchsshscsdschhshddsdhchchshddhddchchdsdchcddddshcscsdhscsddchdcscshdsdddhsdhdchcdcdcsdhhshcsccdchhschshhsdschhhcdchsshdcdhschhdchcddcccchdhcchshhcshdshdssdddhcchdccddhcsshhcdddcdhcchdhddchdshshcscdsdcchchdhcshhscsdchhsdcdhdshdcsdhhhdcddcscdddssccdddccscsdcscchdcsdccdscdshhccchdsscdhhsccsssdcdcsdc...

output:

67475

result:

ok single line: '67475'

Test #22:

score: 0
Accepted
time: 410ms
memory: 9912kb

input:

hsccchcdssddsschddchdcdhdhshccchddcshdcsdcdcccshscccchhhdccshhhsdhcchddhdshssdsccdshdshdcccccchsdhhsdhdscdccdscddcccsssdddshsdhcdcsshhdsshssshdhhhsdcshcccdcsscdhdddhsdsshhddchsdhsssdscddcsccsshccccccshhchdhhhchcccsddchhdhhcschssdccshdscdhhhdsdshdhssdsshdhddcchhhhddchhsssdsdchshscccschcdchchhdcdhscdh...

output:

62915

result:

ok single line: '62915'

Test #23:

score: 0
Accepted
time: 165ms
memory: 5884kb

input:

hshhcsshsdsdchsshdssdchdcsdshccdsshdchsshhcssshcshshhcddhshsdhdcsdhchshdhchhsschhscdhccdcschcsdhddddchchddhhscssccdhhhhhcdchhhhshhdchchcchcshdhdhcddcdhschddsssdcsdhhdsccddcdhcccsshdshshcchschddchshshsdhdhcsdchdchdsssscdschccssdhschcccssddsshhdchhsscdsshcdssdssscsscdhchcsdcchscdsdhhsdshhhccddhsshhdds...

output:

24067

result:

ok single line: '24067'

Test #24:

score: 0
Accepted
time: 4ms
memory: 3692kb

input:

sssdsdchhshdcsccdhdsddsdshchhschdhsschhsshchdcsscdchsshschhsscdshschcddshdsdddshcdhhsscsdchcshddchsdschhdhhdscscsdsdhcdsccdhhshhchshshccccshdcdddddddshsdchchcsddhcchchhsdhcddcsshcsshdhdhscsdhsdshhcdddcshsdhshhssddcdchdsdhcdshsschdschdhdccdhshcdhhhhddcchddchsdhhsccddsdcsscdhhsdscshccssschdsdchccdcdhh...

output:

638

result:

ok single line: '638'

Test #25:

score: 0
Accepted
time: 441ms
memory: 11208kb

input:

hdhccsdhdddcddcdccddddsssdccchshhcchshhschcdsdcdssscshdsschdhshdsdhsschccshscchcddcdhdchsdccdsshdsdchddsccddcsddhcsdchdccsccddshhdchsdddscsdhcccshhdscscshsssscdcschdhscssddscshcddccchsddcchcdhsscdchdhdchsccschcdsdscdhddcdssdddhhsdsdccdshshdschdhhhscshssccdhsddhsdhshchhhhcschdssdddhcdddhdshhcdhhsschd...

output:

74459

result:

ok single line: '74459'

Test #26:

score: 0
Accepted
time: 416ms
memory: 11084kb

input:

dhdssscccshcdhhcsdhhdcschhshcchdcsddshshchhhchddhsshcdddsssdsshscscshdsdccshdscschsdscdhhshhdhhhhdhshhdhsdhhccchccchhhcschshdcddhssdsdsddccdsshdchcsdhhdcsdddcshhcdhchcscsdhchhhcdsdddsdccdddhdhddsscsddsddschshdssccchcshhscshddhdhdsddcdddsscdcsdhsdddhscdsshcscdcdhdssdhdscdchcsdhscshcdsshcdchcsdhsdhddd...

output:

74427

result:

ok single line: '74427'

Test #27:

score: 0
Accepted
time: 444ms
memory: 11368kb

input:

hcdchhsdcshhhhcsscsdsdcshchdhhdcchccdchsdsddchcdchdcssshhcdhchsdccsschshcssshdshcdchdshhhcchscshccsshdddcshsccddsshchhsddshccsshsddcdscccddhcsddssccdchsshccshsdsscsdcdssdhhddcccchhsssdhscdhshccsshddcsdshcdddshdshhddchdscscdhhhhddcsddchhcccdshcdcccddscscdsccchhccdddcscscdhsdhhhchcccdccddsdhhchhchdcsh...

output:

74431

result:

ok single line: '74431'

Test #28:

score: 0
Accepted
time: 470ms
memory: 11156kb

input:

cdcdshhhhdsshdsdchhccdcsshsdsshdhshdshhddsdshdchsccsccdhcdshsdscdcdcsshhsdchsscdsshcshssdddshcdsscchhddhchsdsshccdhchdhhhcchdhccscshcchcchddhccscdhsdhsshsssddddcchdchssddhchsdhhdsccsdsdhchchhcchdchhscddcsdcdsddcddchdcshchschdhdhchddccchchcshccsdcccdcdcdhsddddchchshchdhsshhdhccsdhhcdscsscsshchcdhcdhc...

output:

74497

result:

ok single line: '74497'

Test #29:

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

input:

dcshshcdschdschdhscdcdshhdcsdhcsshdcshdcchsddhcshcsdsdchdchshcsdscdhhdsccsdhhdcsshdchscddshcsdchsdhc

output:

72

result:

ok single line: '72'

Test #30:

score: 0
Accepted
time: 453ms
memory: 11188kb

input:

chdsdhcscdhscdhsdcshsdchshdcdhcssdchhcdsdchsdchsschdhcsdchsddschcshdcsdhhcsddchssdhcchsdscdhschdchdsdchsdshcshcdcshdscdhhsdchcsdhdschdscshcddschhcdsdschhscddshcshdcshcdschdhcsdcdshshdchdschdcsdchscshddcshscdhcdshdshcchsdshdchcsddcshschddschcdshdshcdshcsdhcchdsdschsdchhdscchsddschdhsccdshhsdcdschhdcs...

output:

74997

result:

ok single line: '74997'

Test #31:

score: 0
Accepted
time: 470ms
memory: 11372kb

input:

cccccccccccscccccccccccccccccccccccccccsccccccccccccccccccccccccccccccccccccccccccccccsccccccccccccccccsccccccccccccccsccccccsccccsccchcsccsccccccccsccccccccccccccccsccccccscccccssscccccccccccccccscccccccccsccccccscccccccccsccsccccccccccccccccsccscchccccscccccccsccscccccccscccccccccccsccsccccccscccc...

output:

57178

result:

ok single line: '57178'

Test #32:

score: 0
Accepted
time: 408ms
memory: 11212kb

input:

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccchhcccccchcccccccccccccccccccchccccccccccccccchccccccccccccccccccccccchccccccccccccccccccccccchcccccccchccccccccccccccccccccccccccccccccchcccchcccccccccccccccccccccccccchcccccccccccchccccccchcccccccccccc...

output:

35623

result:

ok single line: '35623'

Test #33:

score: 0
Accepted
time: 390ms
memory: 11168kb

input:

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

23657

result:

ok single line: '23657'

Test #34:

score: 0
Accepted
time: 36ms
memory: 4028kb

input:

dddcdddddddddddddddcdddddddddddddddddhddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsddddddddddddddddddddddddd...

output:

69

result:

ok single line: '69'

Test #35:

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

input:

cccccccccchccccccccccccccccccccccccccccccccccccchhshhhhhhhhshhhhhhhhdhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdddddddddddddddddddddddddddddddddddcddddddddddddddssssssssshssscssssssssscssssshssssssssssssssssssssss

output:

9

result:

ok single line: '9'

Test #36:

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

input:

cchhdhssdcddchccddhsdsshcdhhdhdccshcssss

output:

21

result:

ok single line: '21'