Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// solutia mea
- #include <bits/stdc++.h>
- #define DAU std::ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
- #define PLEC fin.close(); fout.close(); return 0;
- using namespace std;
- ifstream fin("p.in");
- ofstream fout("p.out");
- int n, m, x, nr, sum;
- string cif, str;
- unordered_map<string, bool> M;
- int main()
- {
- DAU
- fin >> n;
- cif += '0';
- for (int i = 1; i <= n; ++i)
- fin >> x, cif += char(x + '0');
- for (int i = 1; i <= n; ++i)
- {
- str.clear();
- for (int j = 0; i + j <= n && j < 5; ++j)
- {
- str += cif[i + j];
- M[str] = true;
- }
- }
- fin >> m;
- for (int i = 1; i <= m; ++i)
- {
- fin >> str;
- if (M[str])
- {
- nr = 0;
- for (size_t j = 0; j < str.size(); ++j)
- nr = nr * 10 + str[j] - '0';
- sum += nr;
- M[str] = false;
- }
- }
- fout << sum;
- PLEC
- }
- /// oficiala
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <cassert>
- using namespace std;
- ifstream fin("p.in");
- ofstream fout("p.out");
- int n, A[100001], m, x;
- int S = 0;
- int v[100000];
- int main()
- {
- fin >> n;
- for(int i = 1; i <= n ; i ++)
- {
- fin >> A[i];
- assert(A[i] >= 0 && A[i] <= 9);
- }
- for(int i = 1 ; i <= n ; i ++)
- v[A[i]] = 1;
- for(int i = 1 ; i <= n - 1; i ++)
- v[A[i]*10 + A[i+1]] = 1;
- for(int i = 1 ; i <= n - 2; i ++)
- v[A[i]*100 + A[i+1]*10+A[i+2]] = 1;
- for(int i = 1 ; i <= n - 3; i ++)
- v[A[i]*1000 + A[i+1]*100+A[i+2]*10+A[i+3]] = 1;
- for(int i = 1 ; i <= n - 4; i ++)
- v[A[i]*10000 + A[i+1]*1000 + A[i+2]*100 + A[i+3]*10 +A[i+4]] = 1;
- for(fin >> m; m ; m --)
- {
- fin >> x;
- assert(x >= 0 && x <= 99999);
- if(v[x])
- S += x, v[x] = 0;
- }
- fout << S << "\n";
- fin.close();
- fout.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment