답안 #920135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920135 2024-02-02T05:47:56 Z TIN Savez (COCI15_savez) C++17
120 / 120
90 ms 19000 KB
#include <bits/stdc++.h>

using namespace std;

#define FNAME "test"

#define sz(s) (int) (s).size()

typedef long long ll;

const int base = 311;
const ll M = 1e9 + 3;
const int N = 505;
const int len = 2e6 + 5;

int n;
string s;
ll p[len];
ll hashS[len];
map<ll,ll> dp;
ll ans = 0;

void Task() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(9);
	if (fopen(FNAME".inp","r")) {
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

void prepare() {
	p[0] = 1;
	for (int i = 1; i <= 2000000; i++) p[i] = (p[i - 1] * base) % M;
}

ll getHash(int l, int r) {
	return (hashS[r] - hashS[l - 1] * p[r - l + 1] + M * M) % M;
}

void Solve() {
	//Your Code
	prepare();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		int lenS = sz(s);
		s = " " + s;
		hashS[0] = 1;
		for (int j = 1; j <= lenS; j++) {
			hashS[j] = (hashS[j - 1] * base + s[j] + 1) % M;
		}
		ll val = 0;
		for (int j = 1; j <= lenS; j++) {
			if (getHash(1, j) == getHash(lenS - j + 1, lenS)) {
				val = max(val, dp[getHash(1, j)]);
			}
		}
		dp[getHash(1, lenS)] = val + 1;
		ans = max(ans, dp[getHash(1, lenS)]);
	}
	cout << ans << '\n';
}

int main() {
	Task();
	Solve();
	cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
	return 37^37;
}

Compilation message

savez.cpp: In function 'void Task()':
savez.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   freopen(FNAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
savez.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   freopen(FNAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17240 KB Output is correct
2 Correct 11 ms 17244 KB Output is correct
3 Correct 11 ms 17244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 17240 KB Output is correct
2 Correct 11 ms 17240 KB Output is correct
3 Correct 11 ms 17240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 18516 KB Output is correct
2 Correct 80 ms 18252 KB Output is correct
3 Correct 81 ms 18272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17240 KB Output is correct
2 Correct 29 ms 18264 KB Output is correct
3 Correct 45 ms 18512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 18000 KB Output is correct
2 Correct 23 ms 18264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 18124 KB Output is correct
2 Correct 23 ms 18000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 18000 KB Output is correct
2 Correct 24 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18252 KB Output is correct
2 Correct 26 ms 18260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 18256 KB Output is correct
2 Correct 37 ms 18264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 18484 KB Output is correct
2 Correct 51 ms 18516 KB Output is correct
3 Correct 90 ms 19000 KB Output is correct