Submission #115036

#TimeUsernameProblemLanguageResultExecution timeMemory
115036FrankenweenParametriziran (COCI19_parametriziran)C++17
66 / 110
3050 ms33536 KiB
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define ull unsigned long long #define pll pair<ll, ll> #define mp make_pair #define ll long long #define pb push_back #define deb(x) cout << #x << " = " << x << endl #define all(x) x.begin(), x.end() #define ld long double const ll mod1 = (ll)1e9 + 7; const ll mod2 = (ll)1e9 + 9; const ll BASE = 539; const ll inf = (ll)1e18; const long double e = 2.718281828459; const long double pi = 3.141592653; const ld EPS = 1e-9; using namespace std; template <class T> istream& operator>>(istream &in, vector<T> &arr) { for (T &cnt : arr) { in >> cnt; } return in; }; struct Node { bool terminal; ll have; vector<Node*> nxt; Node(bool t) { nxt.resize(27, nullptr); terminal = t; have = terminal; } }; ll get(Node *t) { if (!t) { return 0; } return t->have; } void recalc(Node *t) { if (!t) { return; } t->have = t->terminal; for (int i = 0; i < 27; i++) { t->have += get(t->nxt[i]); } } void add(Node *t, string &s, int i) { if (i == s.size()) { t->terminal = true; t->have++; return; } if (t->nxt[s[i] - 'a'] == nullptr) { t->nxt[s[i] - 'a'] = new Node(false); } add(t->nxt[s[i] - 'a'], s, i + 1); recalc(t); } ll get_bad(Node *t, string &s, int i) { if (!t or i == s.size()) { return 0; } if (s[i] == '{') { ll ans = 0; for (int j = 0; j < 27; j++) { ans += get_bad(t->nxt[j], s, i + 1); } return ans; } else { ll ans = 0; for (int j = 0; j < 26; j++) { if (s[i] - 'a' == j) { continue; } ans += get(t->nxt[j]); } ans += get_bad(t->nxt[s[i] - 'a'], s, i + 1); ans += get_bad(t->nxt[26], s, i + 1); return ans; } } void solve() { Node *cnt = new Node(false); ll n, m; cin >> n >> m; ll answer = 0; for (int i = 0; i < n; i++) { string s; cin >> s; for (auto &c : s) { if (c == '?') { c = '{'; } } answer += i - get_bad(cnt, s, 0); add(cnt, s, 0); } cout << answer; } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #else freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cout.precision(30); ll seed = time(0); //cerr << "Seed: " << seed << "\n"; srand(seed); solve(); return 0; }

Compilation message (stderr)

parametriziran.cpp: In function 'void add(Node*, std::__cxx11::string&, int)':
parametriziran.cpp:68:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i == s.size()) {
         ~~^~~~~~~~~~~
parametriziran.cpp: In function 'long long int get_bad(Node*, std::__cxx11::string&, int)':
parametriziran.cpp:82:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (!t or i == s.size()) {
               ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...