QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#4229 | #305. 最长公共相似子序列问题 | Qingyu | 100 ✓ | 195ms | 8964kb | C++11 | 2.0kb | 2020-06-05 14:41:05 | 2021-12-19 04:56:47 |
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
char s[SZ],t[SZ],g[SZ];
int n,an,bn;
map<int,int> rec;
#define S 200
int ans,lis[2333][S+S+5];
const int sb=200;
inline int gans(int x)
{
if(rec.count(x)) return rec[x];
for(int i=0;i<n;++i)
g[i]=s[(i+x)%n];
int r;
for(int i=1;i<=n;++i)
memset(lis[i],0,sizeof(int)*(sb+sb+3));
for(int i=1;i<=n;++i)
{
int u=min(i+sb,n),*th=lis[i]-(i-sb-1),
*ls=lis[i-1]-(i-1-sb-1),l=max(i-sb,1);
for(int j=l;j<=u;++j)
th[j]=(g[i-1]==t[j-1])?(ls[j-1]+1):((ls[j]<th[j-1])?th[j-1]:ls[j]);
}
r=lis[n][n-(n-sb-1)];
ans=max(ans,r); return rec[x]=r;
}
ld K;
inline void go(int l,int r)
{
int fl=gans(l),fr=gans(r);
if(r-l<=1) return;
if(ans-fl+ans-fr>=min(r-l,int((r-l)*K))+2) return;
int m=(l+r)>>1;
if(fl>fr) go(l,m),go(m,r);
else go(m,r),go(l,m);
}
ld ks[]={0.01,0.02,0.03,0.05,0.1,0.3,0.5,0.65,1};
int main()
{
scanf("%d%s%s",&n,s,t);
for(unsigned _=0;_<sizeof(ks)/sizeof(ld);++_)
K=ks[_], go(0,n-1);
cout<<ans<<"\n";
cerr<<clock()<<"ms\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 1ms
memory: 5616kb
input:
10 TACCAAAAGC ATTCTTCTAT
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 10
Accepted
time: 9ms
memory: 6060kb
input:
300 AAGGTTCCTGTATTCATTGCATTGCTGAACTACGACCGAGAAATGCAGGCCCGTGGTGAATACATTGCCAGCACACAGTATAAGGTTACCAGCGGTACATGTTTCTAGAAGGCACATTGGGCGGCCCCGACTGGCGGAGACGACGATAACTCTTCGCTCACGTTTACAATGTCTACCGTAGCACTGATGAGGTTTTGTCCCGGGGCTCATAACAAGACTGTAATATACAAACCCACGGTATGCACGGACTACCGATGAGACACACAGCTTACCTGCGCACAAAGCAGTATGGAAACAGCG GATAGGCCCAGTTACCTCACCAGGACTCAAAGGTGTGGTAAAACTAAATCGCCCATTCAGACAAAGTAAGGCGCTAATAAATTGAAATCTCCGCTTGACAGGCCCCAGCCAACAGCTGGGTATTTGCACTTACCGAGCCGCCTGATTATCGCTCTCTGGCACCATTCGAAGCCACTAGAGAGATGTTGCACAATA...
output:
197
result:
ok 1 number(s): "197"
Test #3:
score: 10
Accepted
time: 3ms
memory: 6080kb
input:
300 AGGAGTTATCGTTAGAGGTTTCCCAATTGGACGCCTAGATTAGGAAGGGCACCGACAACAGCTGTCCTAAAGCTACGGGCGCCTATAATGAACACTGAACGTTGCGCCAGTGTCGCGCCCTACCCTGTCCGCGCCGTAGGATTGTCTCAGTCCTTTATGTAAGACTTGCGAAGTCCGTATCCGACAACATATTAGAAACAGATAAGTCGACGGCGAGCGTTGGAACAATCTATCGCGCCTGCCTTAATCCAGCCTGCGTATAAGGTACACGCCCGTTTGATCGCGTTTGTTTATCGTTGC CACGAATTAATTGATTTTTCCCCTCGCACAGCAGGACCGTGGCGCCACGACACATCTAATGCTATCTCTAACGATTACCCTATACGCCCCTAGTTGCGCAATGCAATAGGCAACTAGCATACCGTGTTCTGTGTCTCAGTTTTCGAGTCTTCATACAGCTTCTGGTATCAGGGGTCGCAGTGACCGTATATCTTT...
output:
202
result:
ok 1 number(s): "202"
Test #4:
score: 10
Accepted
time: 8ms
memory: 6100kb
input:
300 TCATAAGTTCCTTGTTTAAGAACAAAGATCAAGGTTCTCCTCCCTGCGACAGGCTGTGACCCCGAACACCTATAGCGTCTTGGCGGAGCGGCTGTTTACACAGGGGCGCTGTTCAATCGATCGATCTCTCGCCGAGTCTGAGTAGCTACTCAAGTCCTTGGTTAGGGAGTCCAACAGAGGACCTGTTGTGACAGATCCTGGTGGAGCTATTAACAGAGTTGCACGTCTCCTATCCTCATCCAAAGTCTGCCCGGGTGGATTGCATGCTGTCCCTAGATAGACGACGTCGCCTACGCTCTT GACTGACAACCCTCTGAAGTGACTCGGGCGTAAATCGGGGGAGACTCCCTTTGAATCTCTCACTTGTCGCTAACGACGCCTAAGCGATTTGGCATGTATGCAGCATACCGGCTAGGGGTAACAAACGAGCACCGGACGCGTATGTCCCGTCGGGCGTTGTGTAGTCGACATCCATATTCTGAGCAGCATCTGAGG...
output:
199
result:
ok 1 number(s): "199"
Test #5:
score: 10
Accepted
time: 88ms
memory: 7184kb
input:
1000 ATTTAGCAGCAGGGAAGTTCAATGGACTCGGGCCGAAACCCGGGTGCGCGTCGCCCGAATACAACGTATCCAGCTGAACAGCCGCCCTACGCACGGTCATGTTGGCACCGGAAGCAATGAATACGGGTCCTAGGTGCCATCGTCACAGGTAAAGATATAGGTCTGACGGGTGGACCTGGGTTTCCCTCGGTGCGATCCCAAGAGCGAATATGCATTGCTTTACGCTCCCTATGTTTAAGCTACGTCCTGACCAAGAGACCCTATCGTTGGTGGCATCGCGAATTACTCTGCTCATATAATACACGGGCAGATTGGCGCGGAAGTTAACCTCGAACGTTACACCTCGTGTGCCTCTGGTGGAAAGTATCTTAGTCATGGCTAGGAATACAGTCATGCTTCCTACCACAAGAAGATTACCCGATCTCTGCTACCGCCAGGTGAGTCGACGTAACAGGTAGGGGTTCCGTGTCAGCCGCAAGAAAACTCCGCCGTAGC...
output:
657
result:
ok 1 number(s): "657"
Test #6:
score: 10
Accepted
time: 66ms
memory: 7264kb
input:
1000 TCTGCTTTGTGCCAATATCTGACAAGAACACGCCGTGGCGGGTCTTCATATTCGCCCGGACCCATCACGGTATCTTACTGTAGACCGAGATTTGTACATTTCAACCTATACAGGGTCTGGGACGCACTCGTGACTAAAATTTCGTACTTTAGTCAGCACGGGACGCGAGGAGAACATCAAATAATCCTTGATGCAGGCATCTCATCCTTGTCTCCATCTGCGATAAGAGCAATGGGAACATTCCTCCTAAGCGCCGAGTTAAAACGGACAAAAGCCTCCCCGGTCAGTATTGGTGTGTCGTCTTGGGGCCGCTAAGGTGTTTACAACATTACATTTAGTCTACATCTTGCGGGGAACAGTAGAACTGAGTAGGACCCTCGCCCTCTAAGCGTGTTAGCTTGTGAGTGGAGGCCACCTACCAACCACTGGATGACTCAAAGTCACGTTTTTCGGGCGCATGTCATCTCGCAACACGAATTAGACTTACAACTCATA...
output:
653
result:
ok 1 number(s): "653"
Test #7:
score: 10
Accepted
time: 67ms
memory: 8228kb
input:
1000 GTGTGGGCGTGGGTAGTGCTATCCTCATCCACGATTTCTGCCGGCTCGTTTGTACGCCGGCGTTCGCAGATATTCCGGGTATCGAACTATCATTGATAATCATACGTAAACGCAAGAGCTGGAGTCTTCTTAGAAGGATACGGATGGTGGGGGGTGCCCTCGTGCCAACGGTTTGTGTCACAACACACGTTTTCGACGTCCTCTGAGGGCATTACTGATTGACGGATCATTCTCGTCAACGGCCAGCGCAGGGGACCTACTTAGGGACTTGCCGATCCTGTAGAACTTCGGATCTTCCATTAAGCGTTGTTATGGAGGCGGGGGAGCCAATGAAACGTGGACATAAGCGCTGATGTATGTTATTAACCGTGACTGCCAACGTCCTTTGGCCAAAATGGCCCGGATAGCTTGTCTAATCCTTTTTAGATGGTAGACCGGGAGCCATTCAGAATATGTATTTGTAGGACTCCTGTTCGATAAATTAGCAGCCAATTA...
output:
656
result:
ok 1 number(s): "656"
Test #8:
score: 10
Accepted
time: 160ms
memory: 7240kb
input:
2000 TTCATGCGCTCAGCCTGGCTTGAGGCACACGGAGGTGCGCCGCAAACACCTGTTGACTCAAGGGAGCCGACTGCTTGCTGATTCAAATATAATATCTGGGTGAGTTTAACAGTCTCTGTATTAGCGGTGCGGCCTTGTTCAAAGTTACTCGTGATAACCCCACGCTGAAAGACTTCGTACTTTCCCAAGGTTTTGATAGACTCTGAGGGAACTCGGACCAGCCTTTTTCCCTCTGGCGAGGAGAGGCCGGACTCTTTTTGGGAGGCACCTCTTAGCTTCGCCTTCTACGCACCAACAATGTAGTGATTATCTCCTGAAAGAAGGTTTTAGAAACAATACCGGTAGAGAATATGTGGGGGTTTCATAGCCACTGCTTCCGGGGTTGAAGAGGACCCCATCTGGTCGCTAAGGATACTGAAAGTCTTAGATGACCAGGAGCTGTTAAGAAGCTACGCTTACCGTGTGCTTCGACCGCACCTGTGGCTCGAGGGACCG...
output:
1307
result:
ok 1 number(s): "1307"
Test #9:
score: 10
Accepted
time: 191ms
memory: 7876kb
input:
2000 AGTACTCACTAGAGAATCCCCGACCACCCAAGTATTACAAACGAATGGAGATTTCTCTTTGTTACCGCTGCGATGCAGCGGCCACCCGATTTGTTGCTCTGGCCACTATTGGAGTTACAGTGTGGAGCACGCTAGACCGTGGCCTGTGGAAGCGTGCTGCCCCAAACGTAAGAACGAACTTATTCGGCTGCAATTCATCGGGCAGGGCGTTACGGCGTACGAGGGCAAGACAAGGTAGGTCCCGCGGACACACTTGCCTATGCCGTAGGAACATGACAATATGAAGATCGGTACCATCGATGTTTGGTCGGTAAGTGCCTTCCCCGTCCTACCACGCTAACAGCATCGGACTTTAACGAACGTTGCAGCAGCCAGACGGTTGCTTGAAGTGCTAAAGTCTTGAAGCAGTGCCTAGCGCATTGGACGATCCCGAACTCCCTAGTTAGTGCCATCGGGCTGTCCGTGCCATCGAATGTTCAGCGCTTTCAGGTTGCC...
output:
1311
result:
ok 1 number(s): "1311"
Test #10:
score: 10
Accepted
time: 195ms
memory: 8964kb
input:
2000 GACAACCCCCGTCCATCGGCCTCATAATAAGGGGTGCTGATTTGAAAGTTTTTTCCACTACTGCAGTGAAGCTCTTAGCTGCCGTGTTGACCGCCGCCCTACCAAAGCGAATACAAGCTACTAAACTTCGGACAATAGGATTGCATTCCAGCCAGTGAACGTACGGCACTGTCAGAGTTGCCGACTGATGTCGCGTTGAGTTAGGGCCATGGTCTCGATCTAGCAAGACGGTCACTTTCTTATCTTTCGTGACGGCTAATGTATTTTTGTACAGTGGTCTAAGAAACTTAGTTAGTCATCACACAAGCGGGGTATAGCCAACTCTGTTACGATCATTCTTCTTGCTGTGTGCATAACATCAGCAGAGAAACCTCGAGGTCGGACCGCTAAAGACGCAACATAATCGGCAGCAAAACTAAGTAAACGAGGGCCGAGCATACAAAGAGTTGAGACTAACACCTCGATTGTAACACTAGATCCTGGTCGTAGAAGTCC...
output:
1316
result:
ok 1 number(s): "1316"