QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#4227 | #305. 最长公共相似子序列问题 | Qingyu | 100 ✓ | 56ms | 63660kb | C++11 | 1.8kb | 2020-06-05 14:40:29 | 2021-12-19 04:56:42 |
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: 7876kb
input:
10 TACCAAAAGC ATTCTTCTAT
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 10
Accepted
time: 3ms
memory: 20188kb
input:
300 AAGGTTCCTGTATTCATTGCATTGCTGAACTACGACCGAGAAATGCAGGCCCGTGGTGAATACATTGCCAGCACACAGTATAAGGTTACCAGCGGTACATGTTTCTAGAAGGCACATTGGGCGGCCCCGACTGGCGGAGACGACGATAACTCTTCGCTCACGTTTACAATGTCTACCGTAGCACTGATGAGGTTTTGTCCCGGGGCTCATAACAAGACTGTAATATACAAACCCACGGTATGCACGGACTACCGATGAGACACACAGCTTACCTGCGCACAAAGCAGTATGGAAACAGCG GATAGGCCCAGTTACCTCACCAGGACTCAAAGGTGTGGTAAAACTAAATCGCCCATTCAGACAAAGTAAGGCGCTAATAAATTGAAATCTCCGCTTGACAGGCCCCAGCCAACAGCTGGGTATTTGCACTTACCGAGCCGCCTGATTATCGCTCTCTGGCACCATTCGAAGCCACTAGAGAGATGTTGCACAATA...
output:
197
result:
ok 1 number(s): "197"
Test #3:
score: 10
Accepted
time: 2ms
memory: 16668kb
input:
300 AGGAGTTATCGTTAGAGGTTTCCCAATTGGACGCCTAGATTAGGAAGGGCACCGACAACAGCTGTCCTAAAGCTACGGGCGCCTATAATGAACACTGAACGTTGCGCCAGTGTCGCGCCCTACCCTGTCCGCGCCGTAGGATTGTCTCAGTCCTTTATGTAAGACTTGCGAAGTCCGTATCCGACAACATATTAGAAACAGATAAGTCGACGGCGAGCGTTGGAACAATCTATCGCGCCTGCCTTAATCCAGCCTGCGTATAAGGTACACGCCCGTTTGATCGCGTTTGTTTATCGTTGC CACGAATTAATTGATTTTTCCCCTCGCACAGCAGGACCGTGGCGCCACGACACATCTAATGCTATCTCTAACGATTACCCTATACGCCCCTAGTTGCGCAATGCAATAGGCAACTAGCATACCGTGTTCTGTGTCTCAGTTTTCGAGTCTTCATACAGCTTCTGGTATCAGGGGTCGCAGTGACCGTATATCTTT...
output:
202
result:
ok 1 number(s): "202"
Test #4:
score: 10
Accepted
time: 6ms
memory: 19136kb
input:
300 TCATAAGTTCCTTGTTTAAGAACAAAGATCAAGGTTCTCCTCCCTGCGACAGGCTGTGACCCCGAACACCTATAGCGTCTTGGCGGAGCGGCTGTTTACACAGGGGCGCTGTTCAATCGATCGATCTCTCGCCGAGTCTGAGTAGCTACTCAAGTCCTTGGTTAGGGAGTCCAACAGAGGACCTGTTGTGACAGATCCTGGTGGAGCTATTAACAGAGTTGCACGTCTCCTATCCTCATCCAAAGTCTGCCCGGGTGGATTGCATGCTGTCCCTAGATAGACGACGTCGCCTACGCTCTT GACTGACAACCCTCTGAAGTGACTCGGGCGTAAATCGGGGGAGACTCCCTTTGAATCTCTCACTTGTCGCTAACGACGCCTAAGCGATTTGGCATGTATGCAGCATACCGGCTAGGGGTAACAAACGAGCACCGGACGCGTATGTCCCGTCGGGCGTTGTGTAGTCGACATCCATATTCTGAGCAGCATCTGAGG...
output:
199
result:
ok 1 number(s): "199"
Test #5:
score: 10
Accepted
time: 7ms
memory: 36644kb
input:
1000 ATTTAGCAGCAGGGAAGTTCAATGGACTCGGGCCGAAACCCGGGTGCGCGTCGCCCGAATACAACGTATCCAGCTGAACAGCCGCCCTACGCACGGTCATGTTGGCACCGGAAGCAATGAATACGGGTCCTAGGTGCCATCGTCACAGGTAAAGATATAGGTCTGACGGGTGGACCTGGGTTTCCCTCGGTGCGATCCCAAGAGCGAATATGCATTGCTTTACGCTCCCTATGTTTAAGCTACGTCCTGACCAAGAGACCCTATCGTTGGTGGCATCGCGAATTACTCTGCTCATATAATACACGGGCAGATTGGCGCGGAAGTTAACCTCGAACGTTACACCTCGTGTGCCTCTGGTGGAAAGTATCTTAGTCATGGCTAGGAATACAGTCATGCTTCCTACCACAAGAAGATTACCCGATCTCTGCTACCGCCAGGTGAGTCGACGTAACAGGTAGGGGTTCCGTGTCAGCCGCAAGAAAACTCCGCCGTAGC...
output:
657
result:
ok 1 number(s): "657"
Test #6:
score: 10
Accepted
time: 7ms
memory: 36852kb
input:
1000 TCTGCTTTGTGCCAATATCTGACAAGAACACGCCGTGGCGGGTCTTCATATTCGCCCGGACCCATCACGGTATCTTACTGTAGACCGAGATTTGTACATTTCAACCTATACAGGGTCTGGGACGCACTCGTGACTAAAATTTCGTACTTTAGTCAGCACGGGACGCGAGGAGAACATCAAATAATCCTTGATGCAGGCATCTCATCCTTGTCTCCATCTGCGATAAGAGCAATGGGAACATTCCTCCTAAGCGCCGAGTTAAAACGGACAAAAGCCTCCCCGGTCAGTATTGGTGTGTCGTCTTGGGGCCGCTAAGGTGTTTACAACATTACATTTAGTCTACATCTTGCGGGGAACAGTAGAACTGAGTAGGACCCTCGCCCTCTAAGCGTGTTAGCTTGTGAGTGGAGGCCACCTACCAACCACTGGATGACTCAAAGTCACGTTTTTCGGGCGCATGTCATCTCGCAACACGAATTAGACTTACAACTCATA...
output:
653
result:
ok 1 number(s): "653"
Test #7:
score: 10
Accepted
time: 8ms
memory: 38496kb
input:
1000 GTGTGGGCGTGGGTAGTGCTATCCTCATCCACGATTTCTGCCGGCTCGTTTGTACGCCGGCGTTCGCAGATATTCCGGGTATCGAACTATCATTGATAATCATACGTAAACGCAAGAGCTGGAGTCTTCTTAGAAGGATACGGATGGTGGGGGGTGCCCTCGTGCCAACGGTTTGTGTCACAACACACGTTTTCGACGTCCTCTGAGGGCATTACTGATTGACGGATCATTCTCGTCAACGGCCAGCGCAGGGGACCTACTTAGGGACTTGCCGATCCTGTAGAACTTCGGATCTTCCATTAAGCGTTGTTATGGAGGCGGGGGAGCCAATGAAACGTGGACATAAGCGCTGATGTATGTTATTAACCGTGACTGCCAACGTCCTTTGGCCAAAATGGCCCGGATAGCTTGTCTAATCCTTTTTAGATGGTAGACCGGGAGCCATTCAGAATATGTATTTGTAGGACTCCTGTTCGATAAATTAGCAGCCAATTA...
output:
656
result:
ok 1 number(s): "656"
Test #8:
score: 10
Accepted
time: 55ms
memory: 63248kb
input:
2000 TTCATGCGCTCAGCCTGGCTTGAGGCACACGGAGGTGCGCCGCAAACACCTGTTGACTCAAGGGAGCCGACTGCTTGCTGATTCAAATATAATATCTGGGTGAGTTTAACAGTCTCTGTATTAGCGGTGCGGCCTTGTTCAAAGTTACTCGTGATAACCCCACGCTGAAAGACTTCGTACTTTCCCAAGGTTTTGATAGACTCTGAGGGAACTCGGACCAGCCTTTTTCCCTCTGGCGAGGAGAGGCCGGACTCTTTTTGGGAGGCACCTCTTAGCTTCGCCTTCTACGCACCAACAATGTAGTGATTATCTCCTGAAAGAAGGTTTTAGAAACAATACCGGTAGAGAATATGTGGGGGTTTCATAGCCACTGCTTCCGGGGTTGAAGAGGACCCCATCTGGTCGCTAAGGATACTGAAAGTCTTAGATGACCAGGAGCTGTTAAGAAGCTACGCTTACCGTGTGCTTCGACCGCACCTGTGGCTCGAGGGACCG...
output:
1307
result:
ok 1 number(s): "1307"
Test #9:
score: 10
Accepted
time: 56ms
memory: 63660kb
input:
2000 AGTACTCACTAGAGAATCCCCGACCACCCAAGTATTACAAACGAATGGAGATTTCTCTTTGTTACCGCTGCGATGCAGCGGCCACCCGATTTGTTGCTCTGGCCACTATTGGAGTTACAGTGTGGAGCACGCTAGACCGTGGCCTGTGGAAGCGTGCTGCCCCAAACGTAAGAACGAACTTATTCGGCTGCAATTCATCGGGCAGGGCGTTACGGCGTACGAGGGCAAGACAAGGTAGGTCCCGCGGACACACTTGCCTATGCCGTAGGAACATGACAATATGAAGATCGGTACCATCGATGTTTGGTCGGTAAGTGCCTTCCCCGTCCTACCACGCTAACAGCATCGGACTTTAACGAACGTTGCAGCAGCCAGACGGTTGCTTGAAGTGCTAAAGTCTTGAAGCAGTGCCTAGCGCATTGGACGATCCCGAACTCCCTAGTTAGTGCCATCGGGCTGTCCGTGCCATCGAATGTTCAGCGCTTTCAGGTTGCC...
output:
1311
result:
ok 1 number(s): "1311"
Test #10:
score: 10
Accepted
time: 48ms
memory: 63336kb
input:
2000 GACAACCCCCGTCCATCGGCCTCATAATAAGGGGTGCTGATTTGAAAGTTTTTTCCACTACTGCAGTGAAGCTCTTAGCTGCCGTGTTGACCGCCGCCCTACCAAAGCGAATACAAGCTACTAAACTTCGGACAATAGGATTGCATTCCAGCCAGTGAACGTACGGCACTGTCAGAGTTGCCGACTGATGTCGCGTTGAGTTAGGGCCATGGTCTCGATCTAGCAAGACGGTCACTTTCTTATCTTTCGTGACGGCTAATGTATTTTTGTACAGTGGTCTAAGAAACTTAGTTAGTCATCACACAAGCGGGGTATAGCCAACTCTGTTACGATCATTCTTCTTGCTGTGTGCATAACATCAGCAGAGAAACCTCGAGGTCGGACCGCTAAAGACGCAACATAATCGGCAGCAAAACTAAGTAAACGAGGGCCGAGCATACAAAGAGTTGAGACTAACACCTCGATTGTAACACTAGATCCTGGTCGTAGAAGTCC...
output:
1316
result:
ok 1 number(s): "1316"