Submission #338721

# Submission time Handle Problem Language Result Execution time Memory
338721 2020-12-23T18:50:26 Z FlashGamezzz Savez (COCI15_savez) C++11
108 / 120
148 ms 65540 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

int n, p = 31, m = 1000000009;
vector< vector<long long> > ph, sh;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n;
	long long pow = 1, h = 0;
	vector<long long> temp;
	for (int i = 0; i < n; i++){
		string a; cin >> a;
		pow = 1, h = 0; temp.clear();
		for (int j = 0; j < a.length(); j++) {
			h += (a[j]-'A'+1)*pow; h %= m;
			temp.push_back(h); pow *= p; pow %= m;
		}
		ph.push_back(temp); h = 0; temp.clear();
		for (int j = a.length()-1; j >= 0; j--) {
			h *= p; h %= m; h += (a[j]-'A'+1); h %= m;
			temp.push_back(h);
		}
		sh.push_back(temp);
	}
	unordered_map<int, int> subsq;
	int ans = 0;
	for (int i = 0; i < n; i++){
		int mv = 0;
		for (int j = 0; j < ph[i].size(); j++){
			if (ph[i][j] == sh[i][j]){
				unordered_map<int, int>::iterator it = subsq.find(ph[i][j]);
				if (it != subsq.end()){
					mv = max(mv, it->second);
				}
			}
		}
		subsq[ph[i][ph[i].size()-1]] = mv+1; ans = max(ans, mv+1);
	}
	cout << ans << endl;
}

Compilation message

savez.cpp: In function 'int main()':
savez.cpp:24:21: 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 j = 0; j < a.length(); j++) {
      |                   ~~^~~~~~~~~~~~
savez.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int j = 0; j < ph[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 4 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 16064 KB Output is correct
2 Correct 53 ms 16108 KB Output is correct
3 Correct 55 ms 16236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 41 ms 15468 KB Output is correct
3 Correct 45 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 16364 KB Output is correct
2 Correct 51 ms 16492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16860 KB Output is correct
2 Correct 50 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 18004 KB Output is correct
2 Correct 53 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 20564 KB Output is correct
2 Correct 74 ms 20344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 30404 KB Output is correct
2 Correct 98 ms 30388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 44396 KB Output is correct
2 Correct 148 ms 44204 KB Output is correct
3 Runtime error 142 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)