Submission #246284

# Submission time Handle Problem Language Result Execution time Memory
246284 2020-07-08T14:41:19 Z vanic Palinilap (COI16_palinilap) C++14
54 / 100
299 ms 2048 KB
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>


using namespace std;

const int maxn=5005;

string s;
int jos[maxn][30];

int rijesi(int x, bool p1){
	int l, d;
	int br=0;
	if(p1){
		br++;
		l=x-1;
		d=x+1;
	}
	else{
		l=x;
		d=x+1;
	}
	bool p=1;
	int l1=0, d1=s.size()-1;
	while(l>-1 && d<s.size()){
		if(s[l]==s[d]){
			if(p){
				if(l!=d){
				}
				br++;
			}
			else{
				jos[l1][s[d1]-'a']++;
				jos[d1][s[l1]-'a']++;
			}
		}
		else{
			if(p){
				l1=l;
				d1=d;
				jos[l1][s[d1]-'a']++;
				jos[d1][s[l1]-'a']++;
				p=0;
			}
			else{
				break;
			}
		}
		l--;
		d++;
	}
	int xx=0;
	if(p1){
		xx++;
		l=x-1;
		d=x+1;
	}
	else{
		l=x;
		d=x+1;
	}
	while(l>=l1 && d<=d1){
		for(int i=0; i<26; i++){
			jos[l][i]-=br-xx;
			jos[d][i]-=br-xx;
		}
		xx++;
		l--;
		d++;
	}
	return br;
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> s;
	int br=0;
	for(int i=0; i<s.size(); i++){
		br+=rijesi(i, 1);
		br+=rijesi(i, 0);
	}
	int maksi=0;
	for(int i=0; i<s.size(); i++){
		for(int j=0; j<26; j++){
			maksi=max(maksi, jos[i][j]);
		}
	}
	cout << br+maksi << '\n';
	return 0;
}

Compilation message

palinilap.cpp: In function 'int rijesi(int, bool)':
palinilap.cpp:28:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(l>-1 && d<s.size()){
                ~^~~~~~~~~
palinilap.cpp: In function 'int main()':
palinilap.cpp:84:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
palinilap.cpp:89:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 892 KB Output is correct
2 Correct 299 ms 1080 KB Output is correct
3 Correct 16 ms 944 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -