QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373129 | #3665. Watch Later | KareemEssam | AC ✓ | 1406ms | 124392kb | C++14 | 1.7kb | 2024-04-01 03:17:21 | 2024-04-01 03:17:22 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long double ld;
#define lmao ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5+5 , M = 1e4+5 , MOD = 1e9+7 , LOG = 20 , Msk = 21;
int MaskValues[1 << Msk][25];
ll dp[1 << Msk];
ll actualMsk , n , k , cnt = 0;
ll slv(ll curMask){
if(curMask == actualMsk)
return 0;
ll &ret = dp[curMask];
if(~ret)
return ret;
ret = 1e9;
for(int i = 0 ; i < k ; i++){
if(curMask & (1 << i))
continue;
ret = min(ret , slv(curMask | (1 << i)) + MaskValues[curMask][i]);
}
return ret;
}
void testCase() {
string s;
cin >> n >> k >> s;
memset(dp , -1, sizeof dp);
for(int i = 0 ; i < k ; i++)
actualMsk |= (1 << i);
map<char,char>visited;
for(auto &it:s){
if(visited.count(it))
it = visited[it];
else
visited[it] = (cnt + 'a'), it = (cnt + 'a') , cnt++;
}
for(int i = 0 ; i < (1 << k) ; i++){
char prev = '?';
for(int j = 0 ; j < n ; j++){
if((1 << (s[j]-'a') & i))
continue;
MaskValues[i][s[j] - 'a'] += (s[j] != prev);
prev = s[j];
}
}
cout << slv(0);
}
signed main() {
lmao
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: 20380kb
input:
4 2 abba
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 4ms
memory: 21524kb
input:
4 2 rtrt
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 21540kb
input:
10 3 abcbacabac
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 19920kb
input:
9 3 abcbcacab
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 4ms
memory: 21600kb
input:
9 3 dbccdbbcd
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 0ms
memory: 21356kb
input:
10 3 acbcabacab
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 1338ms
memory: 124296kb
input:
400 20 efgfmadpiijgaamlemgqhdnpihlkagkmjkigtmbhafjnedhebthrmlklmbojbkosqhtrslisecfisltebghpnctnjfdbecanrrtileddokkhoocgkaqnctoogdsrqtafehonofcbktacaaercsslcgaroeatplntboornbgkrnchlrgplrbnjnfjqmtcbekcqtlepcqfiaqqffftkpgsdlhahoddrppibscjhtnfncpglhknnicsqqrkmjnfpomeikpckgqlpidftitjpmjqgeamsgjpfsssqgmpq...
output:
308
result:
ok single line: '308'
Test #8:
score: 0
Accepted
time: 1387ms
memory: 124152kb
input:
400 20 otoatqdklbjrgeogbqknqtdrjimhjnodcgmkbjgobqaiisstokecnqrkrettplnnhfegldifqtabgbfsttahakkflhikrebpqhlnjnnmacnambslrmdkirdhcjfagsomidrhjrejaegketercespnssprcpthqldcpqgcilftparljlngmrdmatoshbfhjjsadebljklfmfjqcqkkltqossooiaqehgtosmqaspdkkhfikdhebmprtjhpqcfmpbdndbmkjgrdforerrannibgacqfkigpmthcdjpi...
output:
312
result:
ok single line: '312'
Test #9:
score: 0
Accepted
time: 1367ms
memory: 124372kb
input:
400 20 grfstbcpbeqqnplbeinsleiffhlmaeqmjfnemclngttnsndfollqrfsjcaajesbjspcegjthpolkiptqhcrposnsdklfsksmarqhdncjdlkhrrjrtipbetaorpmcdgkmfcaqnngjapdjsclbmpjcibqnookfaqicrmgsnnoanspdsmgtarcqoehindmmcehaijjgpbaflbkbkoltpbaqaifhjdtmidtakaqilhbjjnnfqnhhqjcqtiohqagjrhdekesftcetdkgmgklidgoemlmiefrfebfokdcrk...
output:
314
result:
ok single line: '314'
Test #10:
score: 0
Accepted
time: 1237ms
memory: 123220kb
input:
400 20 jbjdcsnehpthnmqtbkjsaspnemkohfkgfskdrqqiapgsijcsdadksplhaelanirjodskjpntlconcjihgjegqelmhralrstfskmrsgpompddeonjqekfchmshclpfhssehfnkrmedfrmncsppaeimtcciggprcqchqdfciggotjbpintihbbtaksnnocsklfbmgiccbgopkpdptaerqtjrhenocaqdprgjgogtqlrdimollehipmsbqabiqjfnibgtjltqfhemmlfjkoslhikjsncefmthcdbhogt...
output:
310
result:
ok single line: '310'
Test #11:
score: 0
Accepted
time: 1360ms
memory: 124392kb
input:
400 20 sbballopdokiilpcolsbkmqogsmsnlpnehlscmbnekseniggjgqqhfnlcngakiptpmflrjrbdihltrktrtbbjeaptkphmasfcficoinrracjfqaalrtochjdaeaejgolqrdlhenaidjekjdooosgsqhgjptdhediondbphrptlcrffmepqbjohgitsptemqrsqcmcgpffshfkqammhrckgibnffisfjkepjrbseetddlhgpfqdchdmtcirhfcbdbhkfjosofmiaknjthborrknlokptlbetqknkqg...
output:
309
result:
ok single line: '309'
Test #12:
score: 0
Accepted
time: 1360ms
memory: 122936kb
input:
400 20 dsfqhngaajtlpdbhfbmfqemchqrbpjokodgjdjtsotgecrenmtcnbjbbpgonbrgjionqltdoshcdsiktbkialkisptktnpkslihfaarskrlnfittbdgaifqjgqraqfaclnofthbsafpadsesmjbcrheonkkfnjogdoieppifdpgksmagpinqjlkprqmhmisfmremefhfshiccmeeqlskmebnjkfdhpgclhdeeltnnalbqshhieeipnkpoimbgejeboahmadqqbtldcnfqfcmkpcrilmistatabjgr...
output:
308
result:
ok single line: '308'
Test #13:
score: 0
Accepted
time: 1406ms
memory: 122568kb
input:
400 20 bdagjhnmhjekhsmacdapjkpirienarbljtnfprnegtsspoipqdanbslepjlqhihsefotgojsqckbmbhmdfgfslrolaldjjhgnmkoomehncriifmgebtpopkqcpddnhtscrjkarnrbftgfctacmbjgtsdigsrinlfagkphgmtfthncgqfnbeeidpqnlssoksocrqnacscklqdmiobrjimhsbhaancnmlfiepaiokdrkaekqfgfstbphdcigktklmcmrqppjsqfolcjcjlnrndntpijjfkdqilqtokb...
output:
313
result:
ok single line: '313'
Test #14:
score: 0
Accepted
time: 1346ms
memory: 122496kb
input:
400 20 ddsjfdtthnqeenlmjdoremmhqplolgrpklnrpjtbqpprlffiqphgkfddigkokaorqnogclgbdpnqsbtngjohhqrndbolktgfapifdtakothcqgmlkboqienisgbcddbkannnamredpcgmopjekkpiisohdrciidcfbmqpbqibfsbrfoskcthjhastepokcrcmhqtarsafbgraaeiseljlhlmgsriqemrdmeosmjnppminglsqckllthjribhfreanfsfsfkqmjbkcbkdtemprpksaligiderjcamt...
output:
308
result:
ok single line: '308'
Test #15:
score: 0
Accepted
time: 1363ms
memory: 122728kb
input:
400 20 slamsdgqsgigjadjdhmpmltpqpppjacjedconpkcskmopkamsfmshkicrefgotmnrhkofnleptkbtdchgdfciancdtfllafihkiqpbkkfgnpaslefmnioegqpmphphojkaciscaebnnaejirkdotbhknqtbmethnrbjmiggqjfopbnomdelpgpjtqdkbrimoglrbmrqdtenitfkhnakohnkhmseccooflrehrlcbsblnqfqftaispdshlqihrfmacgjeojdrbcaibesbopnfstdfeoabktghloqsm...
output:
314
result:
ok single line: '314'
Test #16:
score: 0
Accepted
time: 1305ms
memory: 122820kb
input:
400 20 fllnojkpaneaebnikktlmtdpcntsioegtrndbmqjctorbassdrlcfqrqhiisjndgcqghkffdmrrskgmknsgkotqlbmajpajassjriaojdcphookphkpnghankrsggdcfiapcbkjhmofsofqsoborncdcaiepgsbtoiclaljceiqelbclbqgdelfotkhltsdghtrhctoppeidhhabkrmplpninmisrrqergbkpmrbabokgmgbtpmltetoejkftfrcitfefshmtodpemdfkjfglsperljofegdiqqhj...
output:
308
result:
ok single line: '308'