UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201025#458. sequenceAnonyme100264ms79636kbC++111.1kb2024-01-18 09:41:252024-01-18 12:04:57

answer

#include <bits/stdc++.h>
using namespace std;

#define QwQ330AwA return 0
#define ll long long

const int N = 4005;

struct SSAM {
	int nxt[N][2];
	void build(string s) {
		s = " " + s;
		int n = s.length() - 1;
		nxt[n + 1][0] = nxt[n + 1][1] = n + 1;
		for (int i = n; i >= 0; i--) {
			memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i + 1]));
			if (i + 1 <= n) nxt[i][s[i + 1] - '0'] = i + 1;
		}
	}
} S, T;

string s, t;
int f[N][N];
bool pre[N][N];
int n, m;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s >> t;
	S.build(s);
	T.build(t);
	int n = s.length();
	int m = t.length();
	memset(f, 0x3f, sizeof(f));
	f[n + 1][m + 1] = 0;
	for (int i = n + 1; i >= 0; i--) {
		for (int j = m + 1; j >= 0; j--) {
			for (int o = 0; o < 2; o++) {
				if (f[i][j] > f[S.nxt[i][o]][T.nxt[j][o]] + 1) {
					f[i][j] = f[S.nxt[i][o]][T.nxt[j][o]] + 1;
					pre[i][j] = o; 
				}
			}
		}
	}
	int x = 0, y = 0;
	while (x != n + 1 || y != m + 1) {
		cout << pre[x][y];
		int op = pre[x][y];
		x = S.nxt[x][op], y = T.nxt[y][op];
	}
	QwQ330AwA;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 3ms
memory: 63952kb

input:

011000100
0110110011

output:

000001

result:

ok single line: '000001'

Test #2:

score: 10
Accepted
time: 4ms
memory: 63948kb

input:

10111011
111000110

output:

0100

result:

ok single line: '0100'

Test #3:

score: 10
Accepted
time: 7ms
memory: 64260kb

input:

0110000001000011100110010010010110011100010111101000000110010011000101001101011011010100
11011000100...

output:

00110001110000110110111110000000010

result:

ok single line: '00110001110000110110111110000000010'

Test #4:

score: 10
Accepted
time: 8ms
memory: 64256kb

input:

011001000111110000100000011101000001011011100000000000001101000011110101001000111011001
000011100000...

output:

101001001100100011011100010000000

result:

ok single line: '101001001100100011011100010000000'

Test #5:

score: 10
Accepted
time: 7ms
memory: 64232kb

input:

011110011001111010001010110100110101001110001011100101101110011001001101101010010
101011111110101110...

output:

0000001100101100000110000010000000011

result:

ok single line: '0000001100101100000110000010000000011'

Test #6:

score: 10
Accepted
time: 49ms
memory: 79520kb

input:

0101100010010000110011110110100011111110010101101000101111101110010111101111000011100000101000101000...

output:

0001110000010000001000000010111011111100000101011111101011000000011100000001111110001111100010001111...

result:

ok single line: '000111000001000000100000001011...0000000000001001111000011001101'

Test #7:

score: 10
Accepted
time: 39ms
memory: 78088kb

input:

0101001011011101100111110110000010010010000001110111000000101010111110100000011101111011100010010000...

output:

0001110000011111100111101101001011110101000001111011111110011110111100111000000011001000000010011001...

result:

ok single line: '000111000001111110011110110100...0000100000001111110010000000000'

Test #8:

score: 10
Accepted
time: 56ms
memory: 78132kb

input:

1000111000101000001000110101101010101011111101000110000101101110110001101111100010100011001100010001...

output:

0010111100110011000111010000000000000000011001111110010001110001000111111010011110000000100000001100...

result:

ok single line: '001011110011001100011101000000...1111111000000011101001111111000'

Test #9:

score: 10
Accepted
time: 48ms
memory: 79636kb

input:

0000110111100010110111110010111001001110000100001111000111001001100000000010110111001110000001100000...

output:

1001000100011010101011010000010101110011111111110110011111000011000010000000000000000000000000011010...

result:

ok single line: '100100010001101010101101000001...0000000001000001011011001001001'

Test #10:

score: 10
Accepted
time: 43ms
memory: 79148kb

input:

0010010010000000101101000100111010010010010001101000110000110101110111010001010100011000110000001001...

output:

0111100011001111001010000011111101101000110110000010100000011000111110111001100000011110000011000000...

result:

ok single line: '011110001100111100101000001111...1001110001000011001000000000000'