QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394701 | #1369. Longest Common Subsequence | MahmoudBassem | AC ✓ | 9ms | 4136kb | C++17 | 1.4kb | 2024-04-20 18:04:21 | 2024-04-20 18:04:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ld long double
#define el '\n'
#define fi first
#define se second
#define Nine_seconds ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 1e9;
bool relax(int &a, int b) {
if (a >= b) return false;
a = b;
return true;
}
void run_case(int tc) {
int n, k;
cin >> n >> k;
vector<string> a(n);
vector<vector<bool>> ok(26, vector<bool>(26, true));
for (int i = 0; i < n; i++) {
cin >> a[i];
for (auto &c: a[i])
c = tolower(c);
for (int j = k - 1; j >= 0; j--)
for (int o = j - 1; o >= 0; o--)
ok[a[i][j] - 'a'][a[i][o] - 'a'] = false;
}
vector<vector<int>> dp(k + 1, vector<int>(26, -INF));
dp[0] = vector<int>(26, 0);
string &s = a[0];
for (int i = 0; i < k; i++) {
for (int prv = 0; prv < 26; prv++) {
relax(dp[i + 1][prv], dp[i][prv]);
if (ok[prv][s[i] - 'a'])
relax(dp[i + 1][s[i] - 'a'], dp[i][prv] + 1);
}
}
cout << *max_element(dp[k].begin(), dp[k].end()) << el;
}
int32_t main() {
Nine_seconds /*Turn Off for Interactive Problems*/
int _t = 1;
//cin >> _t;
for (int i = 1; i <= _t; i++) {
run_case(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3632kb
input:
6113 13 DALIBKGHEMJFC DAHLIBKGEMJFC DALIBKGEMJFHC DAHLIBKGEMJFC DALIBHKGEMJFC DALHIBKGEMJFC DHALIBKGEMJFC DALIBKGEHMJFC DAHLIBKGEMJFC DALIHBKGEMJFC DALIBKHGEMJFC DALIHBKGEMJFC DALHIBKGEMJFC DALIBKGEMJFCH DALIBKGEMJHFC DAHLIBKGEMJFC DALIBKGEMJFHC DALIBKGEMHJFC DALIBHKGEMJFC DALIBKHGEMJFC DALIBKGEMHJF...
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
3041 4 DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DACB DAC...
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3856kb
input:
2958 22 NSRIBATQJPGELDKFVCHMUO MHNSDRUKBAFTCQJPIGELVO NSRKIUBATMQJCPHGLFVEOD NSREUBATQKJFHPGLMDVOCI UFNSRBEDATCQKJPGHMLVIO NSRBAKEMCITHQJUPGLFVDO NSKCRBUATFDQHJPMGLIVEO MNSKFRHBAETQJPDIGUCLVO NMSRBHACTDEKUQJFPIGLVO KNSRBMACTQUIJPFGDLVEHO NSMDRBACTKHIQJPFGLEVOU NSCRBEATQDJPGLKVOMUFHI UINSRCBEFKATDQJP...
output:
13
result:
ok single line: '13'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
4135 23 VBHFGJNLEDPKCTIWQUORSMA VJBHFGNLEDPKCTIWQUORSMA VBHFGNLEDJPKCTIWQUORSMA VBHFGNLEDPKCTIWQUORSMAJ VBHFGNLEDPKCTIJWQUORSMA VBHFGNLEDPJKCTIWQUORSMA VBHFGNLEDPKCTIWQUJORSMA VBHFGNLEDPKCTIWQUJORSMA VBHFGNLEDPKCTIWQUORSJMA VBHFGNLEDPKCTIWQUORSMAJ VJBHFGNLEDPKCTIWQUORSMA VBHFGNLEDPKCTIWQUOJRSMA VBHF...
output:
22
result:
ok single line: '22'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
1204 22 HKOETNMUFJSLGVRABIDCQP RIKUNMLJAFVHPEGOSBDCQT KSBRCTEJUNOIMHLPFAGDVQ KBNOMLVACUGTFRSDEPJQIH HKGJNVMLFSOTIARPEDBCQU VRBSFKNOCGMTHILJPAEDUQ JCKSERGNFPBOMIHVLAUDQT THKECNGIMPRLUFOSABDJQV FKCSNTGPEVBMLJIOHRAUDQ KNHSFCTVBORIMEGLUAJDQP KNIFHGMROLUSPECABVTDJQ IBKFUEJNHVSOCPGMLADRQT KHNRUMBIGELATSDC...
output:
7
result:
ok single line: '7'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
8807 13 CBFJLDIKAEMHG CFJLDIBAEKMHG CFBJLDKIAMHEG KCFJLDIABEMHG CBKFJLDIAMHGE ECBFJKLDIAMHG CFJLDIAMBKHGE CFJKLDIBAMEHG CFBJLEDIAMHGK CFJLEDBIAMKHG CBFJLDIAMKHEG CFJLDEIAKMBHG BCFJLEDIKAMHG CEFBKJLDIAMHG ECKFJLDBIAMHG CFKJELDBIAMHG CFJBLDKIEAMHG ECFJLDIBAMHKG KCFEBJLDIAMHG CFKJLDEBIAMHG CBFJLDIKAMHE...
output:
10
result:
ok single line: '10'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
9495 2 BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA...
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 9ms
memory: 4104kb
input:
9360 26 YTUSFHBJZRQWKNCLDMAPVXEGOI YUEFHJSMZRQKCWLDAPTVXGOBNI BYUFHSTJZRNWQKCLDAPVXGOIEM YUSFBHJZNWRQKCMLDEAPTVXGOI YUFHJZERBQTKCLDMAWNPVXSGOI YUNTMFHJZRQKCLDSBAPEWVXGOI YUFNEHJZWRSQKCMLDTAPBVXGOI MYUFHBJZRQTKCLDWSAPVXGONIE YWUFHJZNERQKMCLDBSAPVXGOTI SYUFHJNZRQKCLDAPVXMWGEOITB YUTFHJZRQKCLDBEAPVXGWO...
output:
19
result:
ok single line: '19'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1869 24 CUPLKEBMFTNWVSJHAIRXGODQ ODEUPXCKBWSTMNVLIFQJHRAG UPEBTLIONWDQAXVKJSFHCMRG AUXKPOBTNVIWSLJMHEQRCDFG FUOPDBQTNCLVJHMEXKAISRGW WCMULIAPBTNESOQFKVXJDHRG UAWPFMKBSXTNEVLJCHRQGDOI IEUXSCPWABTNMVJFQKOHDRGL WXCUPBMTKNVJFOEHQLRADGIS UPABTNMVWSIKCDXFJHREOLQG IUPQEFBSXWTMNKDCOAVJLHRG OUPDBXATCNWIFVKLJ...
output:
10
result:
ok single line: '10'
Test #10:
score: 0
Accepted
time: 3ms
memory: 4136kb
input:
6641 25 NBDJWKSGTYVECRXILAHMPUOQF MNLFDRJQYKXWHOIEVCAPSTBGU DICTHLGSBWOMQRNEUXFKVAYJP TUKOSJCEIMDLBRXGWYANVHPQF LDMBHRVJCWXQUYESTAPFINGOK DBSUOQJRHYWXFNMAVGCPILEKT DROFXAGYSVHKMEPIJNBLQUCWT VLOGDNRCBIKSJWTXQEUYFAHMP ODJTRFQLIVWBXGEAHYPUNSKCM VIOGFUDNKBTRYHCSEXMLAJWPQ GHFLDMIJOYVUQNKBTRXAWCSEP HKDBRV...
output:
5
result:
ok single line: '5'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
9529 2 AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB...
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 4ms
memory: 3956kb
input:
7625 20 DSMPGROAEIFBCTQLHNKJ DTKAPBLGREQIMCJNHOSF FIAGMHLQJRBTEDNPKOSC SAQLKCGBJTNEFMODIPHR HIKNRDQJGBPTEAFLSMCO NDACRFPKSGLIQHOETBJM IHLBONDQCSFAKTGEJRPM PCKTARIOENDMJGQSHFLB RNGJTKSPMBEOFLAQICDH KIBPASJFHTCQRNGMLDOE MJGDBOQRTNHKFSIALCEP CAIGLKNBFHEOPQMRTSDJ QTJFBGNISCADOPHMKLER TKSJCIBOQMNLREPGHAD...
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
300 26 ABCDTFGHIJKLMNOPQRSEUVWXYZ ABCDEFGNIJKLMHOPQRSTUVWXYZ ABCDEFIHGJKLMNOPQRSTUVWXYZ IBCDEFGHAJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLTNOPQRSMUVWXYZ ABCDEFGKIJHLMNOPQRSTUVWXYZ ABCDEFGKIJHLMNOPQRSTUVWXYZ ABCDEFGHIJLKMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRTSUVWXYZ ABRDEFGHIJKLMNOPQCSTUVWXYZ ABVDEFGHIJKLMNOPQRSTUCW...
output:
1
result:
ok single line: '1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
300 26 ABCDEFGHIJTLMNOPQRSKUVWXYZ ABCDEFGHIJKLMNSPQROTUVWXYZ ABCDEFGHIJKLMYOPQRSTUVWXNZ MBCDEFGHIJKLANOPQRSTUVWXYZ ABCDEFGHIZKLMNOPQRSTUVWXYJ ABCDEFGHIJLKMNOPQRSTUVWXYZ ABCDEKGHIJFLMNOPQRSTUVWXYZ AFCDEBGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSVUTWXYZ ABCDEFGHIJKLMNOQPRSTUVWXYZ AHCDEFGBIJKLMNOPQRSTUVW...
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
30 26 ABCDEFGHIJPLMNOKQRSTUVWXYZ ABCDEFGHSJKLMNOPQRITUVWXYZ ABCDEFGHIJKLMNOPQRSTUVXWYZ ABCDEFGHIJKLMNOPQRSTUVWXZY LBCDEFGHIJKAMNOPQRSTUVWXYZ ASCDEFGHIJKLMNOPQRBTUVWXYZ ABCNEFGHIJKLMDOPQRSTUVWXYZ ABCDEFGHIJNLMKOPQRSTUVWXYZ WBCDEFGHIJKLMNOPQRSTUVAXYZ APCDEFGHIJKLMNOBQRSTUVWXYZ ABJDEFGHICKLMNOPQRSTUVWX...
output:
8
result:
ok single line: '8'