QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#14755 | #305. 最长公共相似子序列问题 | HalifaX | 100 ✓ | 52ms | 63852kb | C++20 | 1.8kb | 2021-10-11 16:48:30 | 2022-05-17 00:59:56 |
Judging History
answer
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
#define S 2003
char a[SZ],b[SZ];
int n,an,bn;
short p[S][S+S],q[S][S+S],f[S+S][S+S];
bool app[233];
char s[S+S],t[S+S];
void work()
{
memset(app,0,sizeof app);
for(int i=1;i<=an;++i) app[a[i]]=1;
for(int i=0;i<=bn+1;++i) p[0][i]=i;
for(int i=1;i<=an;++i)
for(int j=1;j<=bn;++j)
if(a[i]!=b[j]&&q[i][j-1]<=p[i-1][j])
p[i][j]=p[i-1][j],q[i][j]=q[i][j-1];
else p[i][j]=q[i][j-1],q[i][j]=p[i-1][j];
ll ans=0;
for(int i=1;i<=bn;++i)
for(int j=i;j<=bn;++j)
{
if(i==j) f[i][j]=app[b[i]];
else f[i][j]=f[i][j-1]+(p[an][j]<i);
}
}
int main()
{
scanf("%d%s%s",&n,s,t);
an=bn=0; int aa=0;
for(int i=0;i<n;++i) a[++an]=s[i];
for(int i=0;i<n*2;++i) b[++bn]=t[i%n];
work();
for(int i=1;i+n-1<=bn;++i)
aa=max(aa,(int)f[i][i+n-1]);
printf("%d\n",aa);
}
詳細信息
Test #1:
score: 10
Accepted
time: 2ms
memory: 7968kb
input:
10 TACCAAAAGC ATTCTTCTAT
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 10
Accepted
time: 4ms
memory: 17564kb
input:
300 AAGGTTCCTGTATTCATTGCATTGCTGAACTACGACCGAGAAATGCAGGCCCGTGGTGAATACATTGCCAGCACACAGTATAAGGTTACCAGCGGTACATGTTTCTAGAAGGCACATTGGGCGGCCCCGACTGGCGGAGACGACGATAACTCTTCGCTCACGTTTACAATGTCTACCGTAGCACTGATGAGGTTTTGTCCCGGGGCTCATAACAAGACTGTAATATACAAACCCACGGTATGCACGGACTACCGATGAGACACACAGCTTACCTGCGCACAAAGCAGTATGGAAAC...
output:
197
result:
ok 1 number(s): "197"
Test #3:
score: 10
Accepted
time: 2ms
memory: 17528kb
input:
300 AGGAGTTATCGTTAGAGGTTTCCCAATTGGACGCCTAGATTAGGAAGGGCACCGACAACAGCTGTCCTAAAGCTACGGGCGCCTATAATGAACACTGAACGTTGCGCCAGTGTCGCGCCCTACCCTGTCCGCGCCGTAGGATTGTCTCAGTCCTTTATGTAAGACTTGCGAAGTCCGTATCCGACAACATATTAGAAACAGATAAGTCGACGGCGAGCGTTGGAACAATCTATCGCGCCTGCCTTAATCCAGCCTGCGTATAAGGTACACGCCCGTTTGATCGCGTTTGTTTATCG...
output:
202
result:
ok 1 number(s): "202"
Test #4:
score: 10
Accepted
time: 2ms
memory: 18816kb
input:
300 TCATAAGTTCCTTGTTTAAGAACAAAGATCAAGGTTCTCCTCCCTGCGACAGGCTGTGACCCCGAACACCTATAGCGTCTTGGCGGAGCGGCTGTTTACACAGGGGCGCTGTTCAATCGATCGATCTCTCGCCGAGTCTGAGTAGCTACTCAAGTCCTTGGTTAGGGAGTCCAACAGAGGACCTGTTGTGACAGATCCTGGTGGAGCTATTAACAGAGTTGCACGTCTCCTATCCTCATCCAAAGTCTGCCCGGGTGGATTGCATGCTGTCCCTAGATAGACGACGTCGCCTACGC...
output:
199
result:
ok 1 number(s): "199"
Test #5:
score: 10
Accepted
time: 4ms
memory: 35420kb
input:
1000 ATTTAGCAGCAGGGAAGTTCAATGGACTCGGGCCGAAACCCGGGTGCGCGTCGCCCGAATACAACGTATCCAGCTGAACAGCCGCCCTACGCACGGTCATGTTGGCACCGGAAGCAATGAATACGGGTCCTAGGTGCCATCGTCACAGGTAAAGATATAGGTCTGACGGGTGGACCTGGGTTTCCCTCGGTGCGATCCCAAGAGCGAATATGCATTGCTTTACGCTCCCTATGTTTAAGCTACGTCCTGACCAAGAGACCCTATCGTTGGTGGCATCGCGAATTACTCTGCTCAT...
output:
657
result:
ok 1 number(s): "657"
Test #6:
score: 10
Accepted
time: 8ms
memory: 36140kb
input:
1000 TCTGCTTTGTGCCAATATCTGACAAGAACACGCCGTGGCGGGTCTTCATATTCGCCCGGACCCATCACGGTATCTTACTGTAGACCGAGATTTGTACATTTCAACCTATACAGGGTCTGGGACGCACTCGTGACTAAAATTTCGTACTTTAGTCAGCACGGGACGCGAGGAGAACATCAAATAATCCTTGATGCAGGCATCTCATCCTTGTCTCCATCTGCGATAAGAGCAATGGGAACATTCCTCCTAAGCGCCGAGTTAAAACGGACAAAAGCCTCCCCGGTCAGTATTGGTG...
output:
653
result:
ok 1 number(s): "653"
Test #7:
score: 10
Accepted
time: 16ms
memory: 35240kb
input:
1000 GTGTGGGCGTGGGTAGTGCTATCCTCATCCACGATTTCTGCCGGCTCGTTTGTACGCCGGCGTTCGCAGATATTCCGGGTATCGAACTATCATTGATAATCATACGTAAACGCAAGAGCTGGAGTCTTCTTAGAAGGATACGGATGGTGGGGGGTGCCCTCGTGCCAACGGTTTGTGTCACAACACACGTTTTCGACGTCCTCTGAGGGCATTACTGATTGACGGATCATTCTCGTCAACGGCCAGCGCAGGGGACCTACTTAGGGACTTGCCGATCCTGTAGAACTTCGGATCT...
output:
656
result:
ok 1 number(s): "656"
Test #8:
score: 10
Accepted
time: 37ms
memory: 63852kb
input:
2000 TTCATGCGCTCAGCCTGGCTTGAGGCACACGGAGGTGCGCCGCAAACACCTGTTGACTCAAGGGAGCCGACTGCTTGCTGATTCAAATATAATATCTGGGTGAGTTTAACAGTCTCTGTATTAGCGGTGCGGCCTTGTTCAAAGTTACTCGTGATAACCCCACGCTGAAAGACTTCGTACTTTCCCAAGGTTTTGATAGACTCTGAGGGAACTCGGACCAGCCTTTTTCCCTCTGGCGAGGAGAGGCCGGACTCTTTTTGGGAGGCACCTCTTAGCTTCGCCTTCTACGCACCAA...
output:
1307
result:
ok 1 number(s): "1307"
Test #9:
score: 10
Accepted
time: 52ms
memory: 63484kb
input:
2000 AGTACTCACTAGAGAATCCCCGACCACCCAAGTATTACAAACGAATGGAGATTTCTCTTTGTTACCGCTGCGATGCAGCGGCCACCCGATTTGTTGCTCTGGCCACTATTGGAGTTACAGTGTGGAGCACGCTAGACCGTGGCCTGTGGAAGCGTGCTGCCCCAAACGTAAGAACGAACTTATTCGGCTGCAATTCATCGGGCAGGGCGTTACGGCGTACGAGGGCAAGACAAGGTAGGTCCCGCGGACACACTTGCCTATGCCGTAGGAACATGACAATATGAAGATCGGTACC...
output:
1311
result:
ok 1 number(s): "1311"
Test #10:
score: 10
Accepted
time: 45ms
memory: 63536kb
input:
2000 GACAACCCCCGTCCATCGGCCTCATAATAAGGGGTGCTGATTTGAAAGTTTTTTCCACTACTGCAGTGAAGCTCTTAGCTGCCGTGTTGACCGCCGCCCTACCAAAGCGAATACAAGCTACTAAACTTCGGACAATAGGATTGCATTCCAGCCAGTGAACGTACGGCACTGTCAGAGTTGCCGACTGATGTCGCGTTGAGTTAGGGCCATGGTCTCGATCTAGCAAGACGGTCACTTTCTTATCTTTCGTGACGGCTAATGTATTTTTGTACAGTGGTCTAAGAAACTTAGTTAG...
output:
1316
result:
ok 1 number(s): "1316"