QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372880#3665. Watch LaterWisdomCasual#AC ✓1256ms89184kbC++201.5kb2024-03-31 20:13:262024-03-31 20:13:27

Judging History

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

  • [2024-03-31 20:13:27]
  • 评测
  • 测评结果:AC
  • 用时:1256ms
  • 内存:89184kb
  • [2024-03-31 20:13:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ERROR ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fileIO();
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void fileIO(){
    #ifndef ONLINE_JUDGE
    freopen("io\\input.txt", "r", stdin);
    freopen("io\\output.txt", "w", stdout);
    #endif
}

const ll mod = 1e9 + 7, N = 2e5 + 5;

void TestCase(){
    
    int n, k;
    string s;
    cin >> n >> k >> s;
    int a[n];
    map<char, int> toInt;
    set<char> vals;
    for(int i = 0; i < n; i++)
        vals.insert(s[i]);

    int id = 0;

    for(auto ch : vals)
        toInt[ch] = id++;
    
    for(int i = 0; i < n; i++)
        a[i] = toInt[s[i]];

    int mxMask = 1 << k;

    int clicks[mxMask][k]{};

    for(int mask = 0; mask < mxMask; mask++){
        int prev = -1;
        for(int i = 0; i < n; i++){
            if(mask & (1 << a[i])) continue;
            clicks[mask][a[i]] += (a[i] != prev);
            prev = a[i];
        }
    }

    vector<int> dp(mxMask, 1e9);
    dp[0] = 0;

    for(int mask = 0; mask < mxMask; mask++){
        for(int type = 0; type < k; type++){
            if(mask & (1 << type)) continue;
            dp[mask | (1 << type)] = min(dp[mask | (1 << type)], dp[mask] + clicks[mask][type]);
        }
    }

    cout << dp[mxMask - 1] << '\n';

}

int main() {
    
    ERROR;

    int t = 1;
    //cin >> t;

    while(t--)
        TestCase();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
abba

output:

2

result:

ok single line: '2'

Test #2:

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

input:

4 2
rtrt

output:

3

result:

ok single line: '3'

Test #3:

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

input:

10 3
abcbacabac

output:

6

result:

ok single line: '6'

Test #4:

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

input:

9 3
abcbcacab

output:

6

result:

ok single line: '6'

Test #5:

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

input:

9 3
dbccdbbcd

output:

5

result:

ok single line: '5'

Test #6:

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

input:

10 3
acbcabacab

output:

6

result:

ok single line: '6'

Test #7:

score: 0
Accepted
time: 1169ms
memory: 89060kb

input:

400 20
efgfmadpiijgaamlemgqhdnpihlkagkmjkigtmbhafjnedhebthrmlklmbojbkosqhtrslisecfisltebghpnctnjfdbecanrrtileddokkhoocgkaqnctoogdsrqtafehonofcbktacaaercsslcgaroeatplntboornbgkrnchlrgplrbnjnfjqmtcbekcqtlepcqfiaqqffftkpgsdlhahoddrppibscjhtnfncpglhknnicsqqrkmjnfpomeikpckgqlpidftitjpmjqgeamsgjpfsssqgmpq...

output:

308

result:

ok single line: '308'

Test #8:

score: 0
Accepted
time: 1256ms
memory: 89116kb

input:

400 20
otoatqdklbjrgeogbqknqtdrjimhjnodcgmkbjgobqaiisstokecnqrkrettplnnhfegldifqtabgbfsttahakkflhikrebpqhlnjnnmacnambslrmdkirdhcjfagsomidrhjrejaegketercespnssprcpthqldcpqgcilftparljlngmrdmatoshbfhjjsadebljklfmfjqcqkkltqossooiaqehgtosmqaspdkkhfikdhebmprtjhpqcfmpbdndbmkjgrdforerrannibgacqfkigpmthcdjpi...

output:

312

result:

ok single line: '312'

Test #9:

score: 0
Accepted
time: 1214ms
memory: 89176kb

input:

400 20
grfstbcpbeqqnplbeinsleiffhlmaeqmjfnemclngttnsndfollqrfsjcaajesbjspcegjthpolkiptqhcrposnsdklfsksmarqhdncjdlkhrrjrtipbetaorpmcdgkmfcaqnngjapdjsclbmpjcibqnookfaqicrmgsnnoanspdsmgtarcqoehindmmcehaijjgpbaflbkbkoltpbaqaifhjdtmidtakaqilhbjjnnfqnhhqjcqtiohqagjrhdekesftcetdkgmgklidgoemlmiefrfebfokdcrk...

output:

314

result:

ok single line: '314'

Test #10:

score: 0
Accepted
time: 1126ms
memory: 89000kb

input:

400 20
jbjdcsnehpthnmqtbkjsaspnemkohfkgfskdrqqiapgsijcsdadksplhaelanirjodskjpntlconcjihgjegqelmhralrstfskmrsgpompddeonjqekfchmshclpfhssehfnkrmedfrmncsppaeimtcciggprcqchqdfciggotjbpintihbbtaksnnocsklfbmgiccbgopkpdptaerqtjrhenocaqdprgjgogtqlrdimollehipmsbqabiqjfnibgtjltqfhemmlfjkoslhikjsncefmthcdbhogt...

output:

310

result:

ok single line: '310'

Test #11:

score: 0
Accepted
time: 1221ms
memory: 89016kb

input:

400 20
sbballopdokiilpcolsbkmqogsmsnlpnehlscmbnekseniggjgqqhfnlcngakiptpmflrjrbdihltrktrtbbjeaptkphmasfcficoinrracjfqaalrtochjdaeaejgolqrdlhenaidjekjdooosgsqhgjptdhediondbphrptlcrffmepqbjohgitsptemqrsqcmcgpffshfkqammhrckgibnffisfjkepjrbseetddlhgpfqdchdmtcirhfcbdbhkfjosofmiaknjthborrknlokptlbetqknkqg...

output:

309

result:

ok single line: '309'

Test #12:

score: 0
Accepted
time: 1182ms
memory: 89172kb

input:

400 20
dsfqhngaajtlpdbhfbmfqemchqrbpjokodgjdjtsotgecrenmtcnbjbbpgonbrgjionqltdoshcdsiktbkialkisptktnpkslihfaarskrlnfittbdgaifqjgqraqfaclnofthbsafpadsesmjbcrheonkkfnjogdoieppifdpgksmagpinqjlkprqmhmisfmremefhfshiccmeeqlskmebnjkfdhpgclhdeeltnnalbqshhieeipnkpoimbgejeboahmadqqbtldcnfqfcmkpcrilmistatabjgr...

output:

308

result:

ok single line: '308'

Test #13:

score: 0
Accepted
time: 1255ms
memory: 89168kb

input:

400 20
bdagjhnmhjekhsmacdapjkpirienarbljtnfprnegtsspoipqdanbslepjlqhihsefotgojsqckbmbhmdfgfslrolaldjjhgnmkoomehncriifmgebtpopkqcpddnhtscrjkarnrbftgfctacmbjgtsdigsrinlfagkphgmtfthncgqfnbeeidpqnlssoksocrqnacscklqdmiobrjimhsbhaancnmlfiepaiokdrkaekqfgfstbphdcigktklmcmrqppjsqfolcjcjlnrndntpijjfkdqilqtokb...

output:

313

result:

ok single line: '313'

Test #14:

score: 0
Accepted
time: 1215ms
memory: 89184kb

input:

400 20
ddsjfdtthnqeenlmjdoremmhqplolgrpklnrpjtbqpprlffiqphgkfddigkokaorqnogclgbdpnqsbtngjohhqrndbolktgfapifdtakothcqgmlkboqienisgbcddbkannnamredpcgmopjekkpiisohdrciidcfbmqpbqibfsbrfoskcthjhastepokcrcmhqtarsafbgraaeiseljlhlmgsriqemrdmeosmjnppminglsqckllthjribhfreanfsfsfkqmjbkcbkdtemprpksaligiderjcamt...

output:

308

result:

ok single line: '308'

Test #15:

score: 0
Accepted
time: 1236ms
memory: 89164kb

input:

400 20
slamsdgqsgigjadjdhmpmltpqpppjacjedconpkcskmopkamsfmshkicrefgotmnrhkofnleptkbtdchgdfciancdtfllafihkiqpbkkfgnpaslefmnioegqpmphphojkaciscaebnnaejirkdotbhknqtbmethnrbjmiggqjfopbnomdelpgpjtqdkbrimoglrbmrqdtenitfkhnakohnkhmseccooflrehrlcbsblnqfqftaispdshlqihrfmacgjeojdrbcaibesbopnfstdfeoabktghloqsm...

output:

314

result:

ok single line: '314'

Test #16:

score: 0
Accepted
time: 1147ms
memory: 89044kb

input:

400 20
fllnojkpaneaebnikktlmtdpcntsioegtrndbmqjctorbassdrlcfqrqhiisjndgcqghkffdmrrskgmknsgkotqlbmajpajassjriaojdcphookphkpnghankrsggdcfiapcbkjhmofsofqsoborncdcaiepgsbtoiclaljceiqelbclbqgdelfotkhltsdghtrhctoppeidhhabkrmplpninmisrrqergbkpmrbabokgmgbtpmltetoejkftfrcitfefshmtodpemdfkjfglsperljofegdiqqhj...

output:

308

result:

ok single line: '308'