Cod sursa(job #2649201)

Utilizator Katherine456719Swan Katherine Katherine456719 Data 13 septembrie 2020 14:36:26
Problema Cel mai lung subsir comun Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("cmlsc.in");
ofstream fout("cmlsc.out");

//int dp[1025][1025];
int a[1025] ,b[1025];
vector <int> ans;

int main() {
    int m, n;
    fin >> m >> n;
    for(int i = 1;i <= m; ++i)
        fin >> a[i];
    for(int i = 1;i <= n; ++i)
        fin >> b[i];
    for(int i = 1;i <= m; ++i)
        for(int j = 1;j <= n; ++j)
            if(a[i] == b[j]) {
               // dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]) + 1;
             ans.push_back(a[i]);
            }
    fout << ans.size() <<"\n";
    for(auto x : ans){
        fout << x << " ";
    }
    return 0;
}