QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394824#1369. Longest Common SubsequenceKareemEssam#AC ✓3ms14484kbC++201.5kb2024-04-20 20:07:512024-04-20 20:07:53

Judging History

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

  • [2024-04-20 20:07:53]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:14484kb
  • [2024-04-20 20:07:51]
  • 提交

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 ll N = 1e5 + 5, M = 1e4 + 5, MOD = 998244353, LOG = 20, Msk = 21, pw1 = 31, pwe2 = 37;

int n , k;
int occur[28][N];
ll dp[28];

ll slv(ll last , int cnt = 0){
    if(cnt == k)
        return 0;
    ll &ret = dp[last];
    if(~ret)
        return ret;
    ret = 0;
    for(int i = 0  ; i < k ; i++){
        bool can = true;
        if(last == i)
            continue;
        for(int j = 0 ; j < n ; j++){
            if(occur[i][j] < occur[last][j])
                can = false;
        }
        if(can)
            ret = max(ret , slv(i , cnt + 1) + 1);
    }
    return ret;
}

void testCase() {
    cin >> n >> k;
    vector<string> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < k ; j++)
            occur[v[i][j] -'A'][i] = j;
    }
    memset(dp,-1,sizeof dp);
    cout << slv(27);
}

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: 2ms
memory: 9852kb

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: 1ms
memory: 3804kb

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: 12092kb

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: 12072kb

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: 11916kb

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: 2ms
memory: 8032kb

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: 1ms
memory: 5964kb

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: 0ms
memory: 12436kb

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: 2ms
memory: 11988kb

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: 0ms
memory: 14484kb

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: 1ms
memory: 3736kb

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: 3ms
memory: 10348kb

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: 13920kb

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: 1ms
memory: 11956kb

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: 2ms
memory: 13952kb

input:

30 26
ABCDEFGHIJPLMNOKQRSTUVWXYZ
ABCDEFGHSJKLMNOPQRITUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVXWYZ
ABCDEFGHIJKLMNOPQRSTUVWXZY
LBCDEFGHIJKAMNOPQRSTUVWXYZ
ASCDEFGHIJKLMNOPQRBTUVWXYZ
ABCNEFGHIJKLMDOPQRSTUVWXYZ
ABCDEFGHIJNLMKOPQRSTUVWXYZ
WBCDEFGHIJKLMNOPQRSTUVAXYZ
APCDEFGHIJKLMNOBQRSTUVWXYZ
ABJDEFGHICKLMNOPQRSTUVWX...

output:

8

result:

ok single line: '8'