Skip to content

Commit 8f80c37

Browse files
authored
Merge pull request #173 from AlgorithmWithGod/khj20006
[20250225] BOJ / G4 / 사전 순 최대 공통 부분 수열 / 권혁준
2 parents 191ed2f + e58e668 commit 8f80c37

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <vector>
5+
using namespace std;
6+
7+
int main()
8+
{
9+
cin.tie(0)->sync_with_stdio(0);
10+
11+
int N, M;
12+
cin >> N;
13+
vector<int> A(N);
14+
for (int &i : A) cin >> i;
15+
cin >> M;
16+
vector<int> B(M);
17+
for (int &i : B) cin >> i;
18+
19+
vector<int> R;
20+
int idxA = 0, idxB = 0;
21+
while (idxA < N && idxB < M) {
22+
bool suc = 0;
23+
for (int x = 100; x >= 1; x--) {
24+
int res = 0;
25+
int new_idxA = idxA, new_idxB = idxB;
26+
for (int i = idxA; i < N; i++) if (A[i] == x) { res++; new_idxA = i + 1; break; }
27+
for (int i = idxB; i < M; i++) if (B[i] == x) { res++; new_idxB = i + 1; break; }
28+
if (res == 2) {
29+
idxA = new_idxA, idxB = new_idxB;
30+
R.push_back(x);
31+
suc = 1;
32+
break;
33+
}
34+
}
35+
if (!suc) break;
36+
}
37+
cout << R.size() << '\n';
38+
for (int i : R) cout << i << ' ';
39+
40+
}
41+
42+
```

0 commit comments

Comments
 (0)