aboutsummaryrefslogtreecommitdiff
path: root/PolyCarpAndDividend/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'PolyCarpAndDividend/main.cpp')
-rw-r--r--PolyCarpAndDividend/main.cpp49
1 files changed, 0 insertions, 49 deletions
diff --git a/PolyCarpAndDividend/main.cpp b/PolyCarpAndDividend/main.cpp
deleted file mode 100644
index 81e6a92..0000000
--- a/PolyCarpAndDividend/main.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <bits/stdc++.h>
-
-using namespace std;
-
-const int N = 1234567;
-
-int a[12], p[N], e[N];
-bool vis[N];
-
-void print(int x) {
- if (x == -1) return;
- print(p[x]);
- printf("%d", e[x]);
-}
-
-int main() {
- int n, m;
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%d", a + i);
- }
- sort(a, a + n);
- scanf("%d", &m);
- int cnt = 0;
- queue < pair <int, int> > q;
- q.push(make_pair(-1, 0));
- while (!q.empty()) {
- int u = q.front().first;
- int x = q.front().second;
- q.pop();
- for (int i = 0; i < n; i++) {
- int v = (x * 10 + a[i]) % m;
- if (u == -1 && a[i] == 0) continue;
- if (!vis[v]) {
- vis[v] = true;
- q.push(make_pair(cnt, v));
- e[cnt] = a[i];
- p[cnt++] = u;
- }
- if (v == 0) {
- print(cnt - 1);
- return 0;
- }
- }
- }
- puts("-1");
- return 0;
-}
-