From a4c825835cfddc8a2f924552c53efb77ad6a96a2 Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Wed, 23 Sep 2026 20:45:53 +0800 Subject: [PATCH] new file: P12903.cpp --- P12903.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 P12903.cpp diff --git a/P12903.cpp b/P12903.cpp new file mode 100644 index 0000000..57cc097 --- /dev/null +++ b/P12903.cpp @@ -0,0 +1,75 @@ +#include +using namespace std; +#define int long long +int n, m; +int a[100005]; +long double f[2][10]; +int op; +bitset<100005> b[2][10]; +signed main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + cin >> n >> m; + for (int i = 1; i <= n; i++) + { + cin >> a[i]; + } + for (int i = 1; i <= n; i++) + { + for (int j = 0; j < 10; j++) + { + f[op][j] = f[op ^ 1][j]; + b[op][j] = b[op ^ 1][j]; + } + if (f[op][a[i] % 10] < a[i]) + { + f[op][a[i] % 10] = log(a[i]); + b[op][a[i] % 10].reset(); + b[op][a[i] % 10].set(i); + } + for (int j = 0; j < 10; j++) + { + if (!f[op ^ 1][j]) + { + continue; + } + int v = j * a[i] % 10; + if (f[op][v] < f[op ^ 1][j] + log(a[i])) + { + f[op][v] = f[op ^ 1][j] + log(a[i]); + b[op][v] = b[op ^ 1][j]; + b[op][v].set(i); + } + else if (f[op][v] == f[op ^ 1][j] + log(a[i]) && b[op ^ 1][j].count() + 1 >= b[op][v].count()) + { + f[op][v] = f[op ^ 1][j] + log(a[i]); + b[op][v] = b[op ^ 1][j]; + b[op][v].set(i); + } + } + op ^= 1; + } + if (b[op ^ 1][m].none()) + { + cout << "-1"; + } + else + { + multiset res; + cout << b[op ^ 1][m].count() << "\n"; + for (int i = 1; i <= n; i++) + { + if (b[op ^ 1][m][i]) + { + res.insert(a[i]); + // cout << a[i] << ' '; + } + } + for (int i : res) + cout << i << ' '; + cout << endl; + } + return 0; +}