QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87660 | #3665. Watch Later | Zuqa# | AC ✓ | 1314ms | 7624kb | C++20 | 1.8kb | 2023-03-13 23:47:12 | 2023-03-13 23:47:16 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;
template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// mt19937_64 for long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int n, k;
int arr[500];
int dp[1 << 20];
int solve(int msk)
{
if(msk == (1 << k) - 1)
return 0;
int &ret = dp[msk];
if(~ret)
return ret;
int lst = -1;
vector<int> c(k, 0);
for(int i = 0; i < n; i++)
{
if(msk >> arr[i] & 1)
continue;
if(lst != arr[i])
c[arr[i]]++;
lst = arr[i];
}
ret = 1e7;
for(int i = 0; i < k; i++)
{
if(msk >> i & 1)
continue;
ret = min(ret, solve(msk | (1 << i)) + c[i]);
}
return ret;
}
void doWork()
{
string s;
cin >> n >> k >> s;
::memset(dp, -1, sizeof dp);
int id = 0;
map<char, int> vis;
for(int i = 0; i < s.length(); i++)
{
if(!vis.count(s[i]))
vis[s[i]] = id++;
arr[i] = vis[s[i]];
}
cout << solve(0);
}
signed main()
{
FIO
int T = 1;
// cin >> T;
for(int i = 1; i <= T; i++)
doWork();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7536kb
input:
4 2 abba
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 4ms
memory: 7456kb
input:
4 2 rtrt
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 4ms
memory: 7528kb
input:
10 3 abcbacabac
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7464kb
input:
9 3 abcbcacab
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 0ms
memory: 7500kb
input:
9 3 dbccdbbcd
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 2ms
memory: 7540kb
input:
10 3 acbcabacab
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 1283ms
memory: 7500kb
input:
400 20 efgfmadpiijgaamlemgqhdnpihlkagkmjkigtmbhafjnedhebthrmlklmbojbkosqhtrslisecfisltebghpnctnjfdbecanrrtileddokkhoocgkaqnctoogdsrqtafehonofcbktacaaercsslcgaroeatplntboornbgkrnchlrgplrbnjnfjqmtcbekcqtlepcqfiaqqffftkpgsdlhahoddrppibscjhtnfncpglhknnicsqqrkmjnfpomeikpckgqlpidftitjpmjqgeamsgjpfsssqgmpq...
output:
308
result:
ok single line: '308'
Test #8:
score: 0
Accepted
time: 1289ms
memory: 7516kb
input:
400 20 otoatqdklbjrgeogbqknqtdrjimhjnodcgmkbjgobqaiisstokecnqrkrettplnnhfegldifqtabgbfsttahakkflhikrebpqhlnjnnmacnambslrmdkirdhcjfagsomidrhjrejaegketercespnssprcpthqldcpqgcilftparljlngmrdmatoshbfhjjsadebljklfmfjqcqkkltqossooiaqehgtosmqaspdkkhfikdhebmprtjhpqcfmpbdndbmkjgrdforerrannibgacqfkigpmthcdjpi...
output:
312
result:
ok single line: '312'
Test #9:
score: 0
Accepted
time: 1290ms
memory: 7620kb
input:
400 20 grfstbcpbeqqnplbeinsleiffhlmaeqmjfnemclngttnsndfollqrfsjcaajesbjspcegjthpolkiptqhcrposnsdklfsksmarqhdncjdlkhrrjrtipbetaorpmcdgkmfcaqnngjapdjsclbmpjcibqnookfaqicrmgsnnoanspdsmgtarcqoehindmmcehaijjgpbaflbkbkoltpbaqaifhjdtmidtakaqilhbjjnnfqnhhqjcqtiohqagjrhdekesftcetdkgmgklidgoemlmiefrfebfokdcrk...
output:
314
result:
ok single line: '314'
Test #10:
score: 0
Accepted
time: 1314ms
memory: 7464kb
input:
400 20 jbjdcsnehpthnmqtbkjsaspnemkohfkgfskdrqqiapgsijcsdadksplhaelanirjodskjpntlconcjihgjegqelmhralrstfskmrsgpompddeonjqekfchmshclpfhssehfnkrmedfrmncsppaeimtcciggprcqchqdfciggotjbpintihbbtaksnnocsklfbmgiccbgopkpdptaerqtjrhenocaqdprgjgogtqlrdimollehipmsbqabiqjfnibgtjltqfhemmlfjkoslhikjsncefmthcdbhogt...
output:
310
result:
ok single line: '310'
Test #11:
score: 0
Accepted
time: 1307ms
memory: 7468kb
input:
400 20 sbballopdokiilpcolsbkmqogsmsnlpnehlscmbnekseniggjgqqhfnlcngakiptpmflrjrbdihltrktrtbbjeaptkphmasfcficoinrracjfqaalrtochjdaeaejgolqrdlhenaidjekjdooosgsqhgjptdhediondbphrptlcrffmepqbjohgitsptemqrsqcmcgpffshfkqammhrckgibnffisfjkepjrbseetddlhgpfqdchdmtcirhfcbdbhkfjosofmiaknjthborrknlokptlbetqknkqg...
output:
309
result:
ok single line: '309'
Test #12:
score: 0
Accepted
time: 1233ms
memory: 7600kb
input:
400 20 dsfqhngaajtlpdbhfbmfqemchqrbpjokodgjdjtsotgecrenmtcnbjbbpgonbrgjionqltdoshcdsiktbkialkisptktnpkslihfaarskrlnfittbdgaifqjgqraqfaclnofthbsafpadsesmjbcrheonkkfnjogdoieppifdpgksmagpinqjlkprqmhmisfmremefhfshiccmeeqlskmebnjkfdhpgclhdeeltnnalbqshhieeipnkpoimbgejeboahmadqqbtldcnfqfcmkpcrilmistatabjgr...
output:
308
result:
ok single line: '308'
Test #13:
score: 0
Accepted
time: 1272ms
memory: 7556kb
input:
400 20 bdagjhnmhjekhsmacdapjkpirienarbljtnfprnegtsspoipqdanbslepjlqhihsefotgojsqckbmbhmdfgfslrolaldjjhgnmkoomehncriifmgebtpopkqcpddnhtscrjkarnrbftgfctacmbjgtsdigsrinlfagkphgmtfthncgqfnbeeidpqnlssoksocrqnacscklqdmiobrjimhsbhaancnmlfiepaiokdrkaekqfgfstbphdcigktklmcmrqppjsqfolcjcjlnrndntpijjfkdqilqtokb...
output:
313
result:
ok single line: '313'
Test #14:
score: 0
Accepted
time: 1265ms
memory: 7556kb
input:
400 20 ddsjfdtthnqeenlmjdoremmhqplolgrpklnrpjtbqpprlffiqphgkfddigkokaorqnogclgbdpnqsbtngjohhqrndbolktgfapifdtakothcqgmlkboqienisgbcddbkannnamredpcgmopjekkpiisohdrciidcfbmqpbqibfsbrfoskcthjhastepokcrcmhqtarsafbgraaeiseljlhlmgsriqemrdmeosmjnppminglsqckllthjribhfreanfsfsfkqmjbkcbkdtemprpksaligiderjcamt...
output:
308
result:
ok single line: '308'
Test #15:
score: 0
Accepted
time: 1271ms
memory: 7548kb
input:
400 20 slamsdgqsgigjadjdhmpmltpqpppjacjedconpkcskmopkamsfmshkicrefgotmnrhkofnleptkbtdchgdfciancdtfllafihkiqpbkkfgnpaslefmnioegqpmphphojkaciscaebnnaejirkdotbhknqtbmethnrbjmiggqjfopbnomdelpgpjtqdkbrimoglrbmrqdtenitfkhnakohnkhmseccooflrehrlcbsblnqfqftaispdshlqihrfmacgjeojdrbcaibesbopnfstdfeoabktghloqsm...
output:
314
result:
ok single line: '314'
Test #16:
score: 0
Accepted
time: 1287ms
memory: 7624kb
input:
400 20 fllnojkpaneaebnikktlmtdpcntsioegtrndbmqjctorbassdrlcfqrqhiisjndgcqghkffdmrrskgmknsgkotqlbmajpajassjriaojdcphookphkpnghankrsggdcfiapcbkjhmofsofqsoborncdcaiepgsbtoiclaljceiqelbclbqgdelfotkhltsdghtrhctoppeidhhabkrmplpninmisrrqergbkpmrbabokgmgbtpmltetoejkftfrcitfefshmtodpemdfkjfglsperljofegdiqqhj...
output:
308
result:
ok single line: '308'