QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395646 | #1369. Longest Common Subsequence | zedanov | WA | 0ms | 12344kb | C++20 | 1.2kb | 2024-04-21 16:53:33 | 2024-04-21 16:53:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define zedanov \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define el "\n"
const int N = 1e5 + 5;
int n, k;
string a[N];
int appear[28][N], mem[28];
int solve(int cur, int cnt = 0)
{
if (cnt == k)
return 0;
int &ret = mem[cur];
if (~ret)
return cur;
ret = 0;
for (int c = 0; c < k; c++)
{
if (c == cur)
continue;
bool can = 1;
for (int i = 0; i < n; i++)
{
if (appear[c][i] < appear[cur][i])
can = 0;
}
if (can)
ret = max(ret, 1 + solve(c, cnt + 1));
}
return ret;
}
void doWork()
{
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < k; j++)
appear[a[i][j] - 'A'][i] = j;
}
memset(mem, -1, sizeof mem);
cout << solve(27);
}
signed main()
{
zedanov int t = 1;
// cin >> t;
while (t--)
doWork();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 12344kb
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:
16
result:
wrong answer 1st lines differ - expected: '12', found: '16'