Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <cmath>
- #include <iostream>
- using namespace std;
- using ll = long long;
- /*bool cmp(pair<string, int> a, pair <string, int> b) {
- return a.first
- }*/
- int main()
- {
- string N;
- cin >> N;
- int M;
- cin >> M;
- ll ans = 0;
- //vector <string> sections;
- map <string, int> met;
- map <string, int> last_idx;
- map <string, int> val;
- unsigned int max_size = 0;
- for (int i = 0; i < M; ++i) {
- string sect;
- int ch;
- cin >> sect>>ch;
- val[sect] = ch;
- last_idx[sect] = -999;
- met[sect] = 0;
- if (sect.size() > max_size) {
- max_size = sect.size();
- }
- }
- //cout << N.size() - max_size;
- int till = N.size() - max_size;
- for (int i = 0; i < till; ++i) {
- //cout << N << '\n';
- for (auto el: val) {
- string sub = el.first;
- int ch = el.second;
- int idx = N.find(sub);
- //cout << "sub = " << sub << " idx = " << idx << '\n';
- //cout << "idx = " << idx << " last_idx[sub] = " << last_idx[sub] << '\n';
- if (idx == -1 || idx > N.size()) {
- //cout << "ONE\n";
- continue;
- }
- else if (idx == last_idx[sub] - 1) {
- //cout << "TWO\n";
- last_idx[sub] = idx;
- }
- else {
- //cout << "MET INCREASE\n";
- met[sub]++;
- last_idx[sub] = idx;
- }
- }
- N = N.substr(1);
- //cout << '\n';
- }
- //cout << "MET\n";
- for (auto x : met) {
- string sub = x.first;
- int many = x.second;
- //cout << "sub = " << sub << " met = " << many << '\n';
- ans += val[sub] * met[sub];
- }
- //cout << "ans = " << ans << '\n';
- cout << ans << '\n';
- //string a = "Hello World";
- //auto ans = a.find("Helo");
- //cout << typeid(ans).name() << '\n';
- //if (ans > a.size()) cout << "NFOUND\n";
- //cout << ans;
- }
- //MET
- //sub = 123456789 met = 3
- //sub = 1234567891 met = 2
- //sub = 91 met = 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement