Submission #471965

# Submission time Handle Problem Language Result Execution time Memory
471965 2021-09-12T01:35:06 Z malar Palindromes (APIO14_palindrome) C++14
23 / 100
1000 ms 131076 KB
#include <iostream>
using namespace std;

bool isPalindrome(string str) {
	for(int i = 0; i <str.length()/2; i++) {
		if(str[i] != str[str.length()-1-i]) {
			return false;
		}
	}
	return true;
}

int findPosition(string array[], string sub, int size) {
	for(int i = 0; i < size; i++) {
		if(array[i] == sub) {
			return i;
		}
	}
	return -1;
}


int findMax(int array[], int maxPos) {
	int max = array[0];
	for(int i = 1; i <= maxPos; i++) {
		if(array[i] > max) {
			max = array[i];
		}
	} 
	return max;	
}


int main() {
	
	string str;
	cin >> str;
	
	string substr[str.length()];
	int times[str.length()]; 
	int points[str.length()];
	
	string temp;
	
	int maxIndex = -1;

	
	for(int i = 0; i < str.length(); i++) {
		temp = "";
		for(int k=i; k < str.length(); k++) {
			temp = temp + str[k]; 
			if(isPalindrome(temp)) {
			int pos = findPosition(substr, temp, maxIndex);
				if(pos >= 0) {
					times[pos] = times[pos] + 1;
				} else{
					maxIndex++;
					substr[maxIndex] = temp;
					times[maxIndex] = 1;
					
				}
			}
		}
		
	}
	
	for(int i = 0; i <= maxIndex; i++) {
		points[i] = substr[i].length() * times[i];
	}
	
		
	cout << findMax(points, maxIndex);
}

Compilation message

palindrome.cpp: In function 'bool isPalindrome(std::string)':
palindrome.cpp:5:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |  for(int i = 0; i <str.length()/2; i++) {
      |                 ~~^~~~~~~~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0; i < str.length(); i++) {
      |                 ~~^~~~~~~~~~~~~~
palindrome.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int k=i; k < str.length(); k++) {
      |                ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 288 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 900 KB Output is correct
2 Correct 171 ms 624 KB Output is correct
3 Correct 382 ms 924 KB Output is correct
4 Correct 108 ms 548 KB Output is correct
5 Correct 394 ms 844 KB Output is correct
6 Correct 380 ms 916 KB Output is correct
7 Correct 93 ms 664 KB Output is correct
8 Correct 278 ms 844 KB Output is correct
9 Correct 99 ms 412 KB Output is correct
10 Correct 90 ms 396 KB Output is correct
11 Correct 85 ms 292 KB Output is correct
12 Correct 96 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 49860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 264 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 227 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -