답안 #89459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89459 2018-12-14T22:47:06 Z jasony123123 Savez (COCI15_savez) C++11
0 / 120
1000 ms 66560 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
inline void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */
#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/**********************COCI 16-17 R2 P4 :(*****************************/

int N;
v<string> S;
v<v<pll>> normhsh, revhsh;
v<int> dp;


#define MOD1 1000000009LL
#define MOD2 2038072819LL
#define PRIME1 610639LL
#define PRIME2 949957LL
pll p[2000010];
void computeHsh(int sidx) {
	if (p[0] == make_pair(0LL,0LL)) {
		p[0] = { 1, 1 };
		FOR(i, 1, 2000010)
			p[i] = { (p[i - 1].first * PRIME1) % MOD1, (p[i - 1].second* PRIME2) % MOD2 };
	}
	FOR(i, 0, S[sidx].size()) {
		normhsh[sidx][i] = { (S[sidx][i] * PRIME1) % MOD1, (S[sidx][i] * PRIME2) % MOD2 };
		if (i) normhsh[sidx][i] = { (normhsh[sidx][i].first + normhsh[sidx][i - 1].first) % MOD1, (normhsh[sidx][i].second + normhsh[sidx][i - 1].second) % MOD2 };
	}
	FOR(i, 0, S[sidx].size()) {
		revhsh[sidx][i] = { (S[sidx][S[sidx].size() - i - 1] * PRIME1) % MOD1, (S[sidx][S[sidx].size() - i - 1] * PRIME2) % MOD2 };
		if (i) revhsh[sidx][i] = { (revhsh[sidx][i].first + revhsh[sidx][i - 1].first) % MOD1, (revhsh[sidx][i].second + revhsh[sidx][i - 1].second) % MOD2 };
	}
}

int main() {
	io();
	cin >> N;
	S.resize(N);
	normhsh.resize(N);
	revhsh.resize(N);
	FOR(i, 0, N) {
		cin >> S[i];
		normhsh[i].resize(S[i].size());
		revhsh[i].resize(S[i].size());
		computeHsh(i);
	}

	int ans = 1;
	dp.resize(N, 1);
	RFORE(i, N - 1, 0) {
		FOR(j, i + 1, N)
			if(S[i].size() <= S[j].size() && normhsh[i].back()==normhsh[j][normhsh[i].size()-1] && revhsh[i].back() == revhsh[j][revhsh[i].size()-1])
				maxx(dp[i], 1 + dp[j]);
		maxx(ans, dp[i]);
	}
	cout << ans << "\n";
	return 0;
}












# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 31608 KB Output is correct
2 Incorrect 36 ms 31872 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 31872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 65140 KB Output is correct
2 Runtime error 77 ms 66192 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 66192 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 808 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 66560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 106 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 103 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -