Submission #209876

# Submission time Handle Problem Language Result Execution time Memory
209876 2020-03-15T20:07:39 Z ZwariowanyMarcin Savez (COCI15_savez) C++14
0 / 120
560 ms 33748 KB
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(), x.end()

using namespace std;

const int N = 2e6 + 12;
const int MOD1 = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int P = 31;

int n;
vector <string> v;
char s[N];
string t;

map <string, int> ile;
map <pair<int, int>, int> dp;

int h1[N];
int h2[N];
int p1[N];
int p2[N];

void prep(string x) {
	x = '#' + x;
	int n = ss(x) - 1;
	rep(i, 1, n) {
		h1[i] = ((LL) h1[i - 1] * P + (x[i] - 'A' + 1)) % MOD1;
		h2[i] = ((LL) h2[i - 1] * P + (x[i] - 'A' + 1)) % MOD2;
	}
}

pair <int, int> hh(int l, int r) {
	pair <int, int> x;
	x.fi = (h1[r] - (LL) h1[l - 1] * p1[r - l + 1] % MOD1 + MOD1) % MOD1;
	x.se = (h2[r] - (LL) h2[l - 1] * p2[r - l + 1] % MOD2 + MOD2) % MOD2;
	return x;
}

int main() {
	p1[0] = p2[0] = 1;
	rep(i, 1, N - 1) {
		p1[i] = (LL) p1[i - 1] * P % MOD1;
		p2[i] = (LL) p2[i - 1] * P % MOD2;
	}
		
	
	scanf ("%d", &n);
	rep(i, 1, n) {
		scanf ("%s", s + 1);
		int n = strlen(s + 1);
		t = "";
		rep(j, 1, n) t.pb(s[j]);
		v.pb(t);
		ile[t]++;
	}
	sort(all(v), [](string a, string b) {
		return ss(a) < ss(b);
	});
	int best = 0;
	for (auto it : v) {
		prep(it);
		int n = ss(it);
		pair<int, int> ja = hh(1, n);
		dp[ja] = ile[it];
		rep(i, 1, n - 1) {
			if (hh(1, i) == hh(n - i + 1, n)) {
				dp[ja] = max(dp[ja], ile[it] + dp[hh(1, i)]);
			}
		}
		best = max(best, dp[ja]);
	}
	printf ("%d\n", best);
		
		
	
		
	return 0;
}

Compilation message

savez.cpp: In function 'int main()':
savez.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &n);
  ~~~~~~^~~~~~~~~~
savez.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s", s + 1);
   ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 15864 KB Output is correct
2 Incorrect 24 ms 15996 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 16120 KB Output is correct
2 Correct 23 ms 15992 KB Output is correct
3 Incorrect 28 ms 16248 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 18168 KB Output is correct
2 Incorrect 391 ms 18172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 16248 KB Output is correct
2 Correct 367 ms 18552 KB Output is correct
3 Incorrect 560 ms 19064 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 18420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 19056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 20072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 21988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 222 ms 25308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 33748 KB Output isn't correct
2 Halted 0 ms 0 KB -