ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201023 | #458. sequence | UperFicial | 100 | 235ms | 126496kb | C++11 | 1.1kb | 2024-01-18 09:35:26 | 2024-01-18 12:04:50 |
answer
#include<bits/stdc++.h>
#define N 4005
using namespace std;
int n,m,a[N],b[N],dp[N][N],jc[N][N],ah[N][2],bh[N][2],l[2];
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
char c[N];
signed main()
{
scanf("%s",c+1);
for(int i=1,len=strlen(c+1);i<=len;i++)a[++n]=c[i]-'0';
scanf("%s",c+1);
for(int i=1,len=strlen(c+1);i<=len;i++)b[++m]=c[i]-'0';
l[0]=n+1;l[1]=n+1;
ah[n+1][0]=ah[n+1][1]=n+1;
for(int i=n;i>=0;i--)
{
ah[i][0]=l[0];
ah[i][1]=l[1];
l[a[i]]=i;
}
l[0]=m+1;l[1]=m+1;
bh[m+1][0]=bh[m+1][1]=m+1;
for(int i=m;i>=0;i--)
{
bh[i][0]=l[0];
bh[i][1]=l[1];
l[b[i]]=i;
}
for(int i=0;i<=n+1;i++)
for(int j=0;j<=m+1;j++)
dp[i][j]=1e9;
dp[n+1][m+1]=0;
for(int i=n+1;i>=0;i--)for(int j=m+1-(i==n+1);j>=0;j--)
dp[i][j]=min(dp[ah[i][0]][bh[j][0]],dp[ah[i][1]][bh[j][1]])+1,(jc[i][j]=(dp[ah[i][0]][bh[j][0]]<=dp[ah[i][1]][bh[j][1]])?0:1);
for(int i=0,j=0,cc=jc[i][j];i!=n+1||j!=m+1;i=ah[i][cc],j=bh[j][cc],cc=jc[i][j])printf("%d",cc);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
011000100 0110110011
output:
000001
result:
ok single line: '000001'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1272kb
input:
10111011 111000110
output:
0100
result:
ok single line: '0100'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1980kb
input:
0110000001000011100110010010010110011100010111101000000110010011000101001101011011010100 11011000100...
output:
00110001110000110110111110000000010
result:
ok single line: '00110001110000110110111110000000010'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1984kb
input:
011001000111110000100000011101000001011011100000000000001101000011110101001000111011001 000011100000...
output:
101001001100100011011100010000000
result:
ok single line: '101001001100100011011100010000000'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1932kb
input:
011110011001111010001010110100110101001110001011100101101110011001001101101010010 101011111110101110...
output:
0000001100101100000110000010000000011
result:
ok single line: '0000001100101100000110000010000000011'
Test #6:
score: 10
Accepted
time: 53ms
memory: 125624kb
input:
0101100010010000110011110110100011111110010101101000101111101110010111101111000011100000101000101000...
output:
0001110000010000001000000010111011111100000101011111101011000000011100000001111110001111100010001111...
result:
ok single line: '000111000001000000100000001011...0000000000001001111000011001101'
Test #7:
score: 10
Accepted
time: 39ms
memory: 114164kb
input:
0101001011011101100111110110000010010010000001110111000000101010111110100000011101111011100010010000...
output:
0001110000011111100111101101001011110101000001111011111110011110111100111000000011001000000010011001...
result:
ok single line: '000111000001111110011110110100...0000100000001111110010000000000'
Test #8:
score: 10
Accepted
time: 35ms
memory: 114480kb
input:
1000111000101000001000110101101010101011111101000110000101101110110001101111100010100011001100010001...
output:
0010111100110011000111010000000000000000011001111110010001110001000111111010011110000000100000001100...
result:
ok single line: '001011110011001100011101000000...1111111000000011101001111111000'
Test #9:
score: 10
Accepted
time: 53ms
memory: 126496kb
input:
0000110111100010110111110010111001001110000100001111000111001001100000000010110111001110000001100000...
output:
1001000100011010101011010000010101110011111111110110011111000011000010000000000000000000000000011010...
result:
ok single line: '100100010001101010101101000001...0000000001000001011011001001001'
Test #10:
score: 10
Accepted
time: 55ms
memory: 122648kb
input:
0010010010000000101101000100111010010010010001101000110000110101110111010001010100011000110000001001...
output:
0111100011001111001010000011111101101000110110000010100000011000111110111001100000011110000011000000...
result:
ok single line: '011110001100111100101000001111...1001110001000011001000000000000'