QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87663 | #3665. Watch Later | Beevo | AC ✓ | 1386ms | 7608kb | C++23 | 1.2kb | 2023-03-14 00:07:10 | 2023-03-14 00:07:12 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
typedef long long ll;
typedef long double ld;
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 400 + 5, INF = 1e9;
int n, k;
int a[N], dp[1 << 20];
int solve(int msk) {
if (msk == (1 << k) - 1)
return 0;
int &ret = dp[msk];
if (~ret)
return ret;
vector<int> cst(k);
for (int i = 0, lst = -1; i < n; i++) {
if (msk & (1 << a[i]))
continue;
if (a[i] != lst)
cst[a[i]]++;
lst = a[i];
}
ret = INF;
for (int bit = 0; bit < k; bit++) {
if (msk & (1 << bit))
continue;
ret = min(ret, solve(msk | (1 << bit)) + cst[bit]);
}
return ret;
}
void testCase() {
string s;
cin >> n >> k >> s;
int id = 0;
vector<int> ids(26, -1);
for (int i = 0; i < n; i++) {
if (ids[s[i] - 'a'] == -1)
ids[s[i] - 'a'] = id++;
a[i] = ids[s[i] - 'a'];
}
memset(dp, -1, sizeof dp);
cout << solve(0);
}
signed main() {
Beevo
int t = 1;
// cin >> t;
while (t--)
testCase();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 7540kb
input:
4 2 abba
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7604kb
input:
4 2 rtrt
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 4ms
memory: 7584kb
input:
10 3 abcbacabac
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 2ms
memory: 7504kb
input:
9 3 abcbcacab
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 2ms
memory: 7544kb
input:
9 3 dbccdbbcd
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 4ms
memory: 7500kb
input:
10 3 acbcabacab
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 1296ms
memory: 7492kb
input:
400 20 efgfmadpiijgaamlemgqhdnpihlkagkmjkigtmbhafjnedhebthrmlklmbojbkosqhtrslisecfisltebghpnctnjfdbecanrrtileddokkhoocgkaqnctoogdsrqtafehonofcbktacaaercsslcgaroeatplntboornbgkrnchlrgplrbnjnfjqmtcbekcqtlepcqfiaqqffftkpgsdlhahoddrppibscjhtnfncpglhknnicsqqrkmjnfpomeikpckgqlpidftitjpmjqgeamsgjpfsssqgmpq...
output:
308
result:
ok single line: '308'
Test #8:
score: 0
Accepted
time: 1309ms
memory: 7592kb
input:
400 20 otoatqdklbjrgeogbqknqtdrjimhjnodcgmkbjgobqaiisstokecnqrkrettplnnhfegldifqtabgbfsttahakkflhikrebpqhlnjnnmacnambslrmdkirdhcjfagsomidrhjrejaegketercespnssprcpthqldcpqgcilftparljlngmrdmatoshbfhjjsadebljklfmfjqcqkkltqossooiaqehgtosmqaspdkkhfikdhebmprtjhpqcfmpbdndbmkjgrdforerrannibgacqfkigpmthcdjpi...
output:
312
result:
ok single line: '312'
Test #9:
score: 0
Accepted
time: 1386ms
memory: 7468kb
input:
400 20 grfstbcpbeqqnplbeinsleiffhlmaeqmjfnemclngttnsndfollqrfsjcaajesbjspcegjthpolkiptqhcrposnsdklfsksmarqhdncjdlkhrrjrtipbetaorpmcdgkmfcaqnngjapdjsclbmpjcibqnookfaqicrmgsnnoanspdsmgtarcqoehindmmcehaijjgpbaflbkbkoltpbaqaifhjdtmidtakaqilhbjjnnfqnhhqjcqtiohqagjrhdekesftcetdkgmgklidgoemlmiefrfebfokdcrk...
output:
314
result:
ok single line: '314'
Test #10:
score: 0
Accepted
time: 1363ms
memory: 7592kb
input:
400 20 jbjdcsnehpthnmqtbkjsaspnemkohfkgfskdrqqiapgsijcsdadksplhaelanirjodskjpntlconcjihgjegqelmhralrstfskmrsgpompddeonjqekfchmshclpfhssehfnkrmedfrmncsppaeimtcciggprcqchqdfciggotjbpintihbbtaksnnocsklfbmgiccbgopkpdptaerqtjrhenocaqdprgjgogtqlrdimollehipmsbqabiqjfnibgtjltqfhemmlfjkoslhikjsncefmthcdbhogt...
output:
310
result:
ok single line: '310'
Test #11:
score: 0
Accepted
time: 1348ms
memory: 7608kb
input:
400 20 sbballopdokiilpcolsbkmqogsmsnlpnehlscmbnekseniggjgqqhfnlcngakiptpmflrjrbdihltrktrtbbjeaptkphmasfcficoinrracjfqaalrtochjdaeaejgolqrdlhenaidjekjdooosgsqhgjptdhediondbphrptlcrffmepqbjohgitsptemqrsqcmcgpffshfkqammhrckgibnffisfjkepjrbseetddlhgpfqdchdmtcirhfcbdbhkfjosofmiaknjthborrknlokptlbetqknkqg...
output:
309
result:
ok single line: '309'
Test #12:
score: 0
Accepted
time: 1300ms
memory: 7476kb
input:
400 20 dsfqhngaajtlpdbhfbmfqemchqrbpjokodgjdjtsotgecrenmtcnbjbbpgonbrgjionqltdoshcdsiktbkialkisptktnpkslihfaarskrlnfittbdgaifqjgqraqfaclnofthbsafpadsesmjbcrheonkkfnjogdoieppifdpgksmagpinqjlkprqmhmisfmremefhfshiccmeeqlskmebnjkfdhpgclhdeeltnnalbqshhieeipnkpoimbgejeboahmadqqbtldcnfqfcmkpcrilmistatabjgr...
output:
308
result:
ok single line: '308'
Test #13:
score: 0
Accepted
time: 1353ms
memory: 7480kb
input:
400 20 bdagjhnmhjekhsmacdapjkpirienarbljtnfprnegtsspoipqdanbslepjlqhihsefotgojsqckbmbhmdfgfslrolaldjjhgnmkoomehncriifmgebtpopkqcpddnhtscrjkarnrbftgfctacmbjgtsdigsrinlfagkphgmtfthncgqfnbeeidpqnlssoksocrqnacscklqdmiobrjimhsbhaancnmlfiepaiokdrkaekqfgfstbphdcigktklmcmrqppjsqfolcjcjlnrndntpijjfkdqilqtokb...
output:
313
result:
ok single line: '313'
Test #14:
score: 0
Accepted
time: 1342ms
memory: 7588kb
input:
400 20 ddsjfdtthnqeenlmjdoremmhqplolgrpklnrpjtbqpprlffiqphgkfddigkokaorqnogclgbdpnqsbtngjohhqrndbolktgfapifdtakothcqgmlkboqienisgbcddbkannnamredpcgmopjekkpiisohdrciidcfbmqpbqibfsbrfoskcthjhastepokcrcmhqtarsafbgraaeiseljlhlmgsriqemrdmeosmjnppminglsqckllthjribhfreanfsfsfkqmjbkcbkdtemprpksaligiderjcamt...
output:
308
result:
ok single line: '308'
Test #15:
score: 0
Accepted
time: 1342ms
memory: 7544kb
input:
400 20 slamsdgqsgigjadjdhmpmltpqpppjacjedconpkcskmopkamsfmshkicrefgotmnrhkofnleptkbtdchgdfciancdtfllafihkiqpbkkfgnpaslefmnioegqpmphphojkaciscaebnnaejirkdotbhknqtbmethnrbjmiggqjfopbnomdelpgpjtqdkbrimoglrbmrqdtenitfkhnakohnkhmseccooflrehrlcbsblnqfqftaispdshlqihrfmacgjeojdrbcaibesbopnfstdfeoabktghloqsm...
output:
314
result:
ok single line: '314'
Test #16:
score: 0
Accepted
time: 1351ms
memory: 7508kb
input:
400 20 fllnojkpaneaebnikktlmtdpcntsioegtrndbmqjctorbassdrlcfqrqhiisjndgcqghkffdmrrskgmknsgkotqlbmajpajassjriaojdcphookphkpnghankrsggdcfiapcbkjhmofsofqsoborncdcaiepgsbtoiclaljceiqelbclbqgdelfotkhltsdghtrhctoppeidhhabkrmplpninmisrrqergbkpmrbabokgmgbtpmltetoejkftfrcitfefshmtodpemdfkjfglsperljofegdiqqhj...
output:
308
result:
ok single line: '308'