Submission #1045554

#TimeUsernameProblemLanguageResultExecution timeMemory
1045554javotazDabbeh (INOI20_dabbeh)C++17
0 / 100
369 ms53072 KiB
// In the Name of Allah #include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,avx,avx2,sse4.2,popcnt,tune=native") typedef long long ll; #define F first #define S second #define pii pair<int, int> #define pb push_back #define pp pop_back #define all(x) x.begin(), x.end() const int N = 3e5 + 7, M = 1e4 + 7, K = 5e5 + 7; string s, a[M]; int n, q, dp[N], c, t[K][26]; void add(int id) { int p = 0; for (int i = 0; i < a[id].size(); i++) { if (!t[p][a[id][i] - 'a']) t[p][a[id][i] - 'a'] = ++c; p = t[p][a[id][i] - 'a']; } } void ip() { cin >> n >> q; for (int i = 0; i < n; i++) { cin >> a[i]; add(i); } cin >> s; } void solve() { while (q--) { int l, r; cin >> l >> r; fill(dp + l, dp + r + 1, 0); for (int i = r - 1; i >= l; --i) { dp[i] = n + 1; for (int j = i, p = 0; j < r && (p = t[p][s[j] - 'a']); j++) dp[i] = min(dp[i], 1 + dp[j + 1]); } cout << ((dp[l] > n)? -1 : dp[l]) << '\n'; } } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ip(), solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void add(int)':
Main.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < a[id].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...