# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542534 |
2022-03-26T21:13:47 Z |
Olympia |
Savez (COCI15_savez) |
C++17 |
|
326 ms |
59036 KB |
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#include <limits.h>
using namespace std;
int64_t binPow (int64_t x, int64_t y, int64_t MOD) {
int64_t res = x;
int64_t ans = 1;
while (y > 0) {
if (y & 1) {
ans *= res, ans %= MOD;
}
res *= res, res %= MOD;
y /= 2;
}
return ans;
}
int64_t inv (int64_t x, int64_t MOD) {
return binPow(x, MOD - 2, MOD);
}
struct Hasher {
void resz (int mod, int base, string str) {
int n = str.size();
this->sz = n;
this->MOD = mod, this->BASE = base;
this->pref.assign(n + 1, 0);
for (int i = 1; i <= n; i++) {
pref[i] = (BASE * pref[i - 1] + (str[i - 1] - 'A' + 1)) % MOD;
}
}
int sz;
int MOD;
int BASE;
vector<int64_t> pref;
int64_t query (int l, int r) {
return (pref[r + 1] - (binPow(BASE, r - l + 1, MOD) * pref[l]) % MOD + MOD) % MOD;
}
};
vector<int> dp;
vector<vector<int>> adj;
int myMax = 0;
void rec (int curNode) {
if (dp[curNode] != 0) {
return;
}
dp[curNode] = 0;
for (int i: adj[curNode]) {
rec(i);
dp[curNode] = max(dp[curNode], dp[i]);
}
dp[curNode] ++;
myMax = max(myMax, dp[curNode]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
unordered_map<int64_t,int> myMap;
adj.resize(N);
dp.assign(N, 0);
for (int i = 0; i < N; i++) {
string str;
cin >> str;
Hasher h1; h1.resz(1e9 + 9, 31, str);
for (int l = 1; l <= str.size(); l++) {
if (h1.query(0, l - 1) == h1.query(str.size() - l, str.size() - 1)) {
if (myMap.count(h1.query(0, l - 1))) {
adj[i].push_back(myMap[h1.query(0, l - 1)]);
}
}
}
myMap[h1.query(0, str.size() - 1)] = i;
}
for (int i = 0; i < N; i++) {
rec(i);
}
cout << myMax;
}
Compilation message
savez.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
14 | #pragma GCC optimization ("O2")
|
savez.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
15 | #pragma GCC optimization ("unroll-loops")
|
savez.cpp: In function 'int main()':
savez.cpp:80:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int l = 1; l <= str.size(); l++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
19 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
304 ms |
380 KB |
Output is correct |
2 |
Correct |
301 ms |
356 KB |
Output is correct |
3 |
Correct |
326 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
340 KB |
Output is correct |
2 |
Correct |
302 ms |
784 KB |
Output is correct |
3 |
Correct |
320 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
1996 KB |
Output is correct |
2 |
Correct |
225 ms |
1948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
3760 KB |
Output is correct |
2 |
Correct |
199 ms |
3852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
4556 KB |
Output is correct |
2 |
Correct |
177 ms |
4488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
5828 KB |
Output is correct |
2 |
Correct |
176 ms |
5772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
14292 KB |
Output is correct |
2 |
Correct |
129 ms |
14364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
23716 KB |
Output is correct |
2 |
Correct |
172 ms |
23716 KB |
Output is correct |
3 |
Correct |
250 ms |
59036 KB |
Output is correct |