【Gym 100971K】Palindromization

Mihahim has a string s. He wants to delete exactly one character from it so that the resulting string would be a palindrome. Determine if he can do it, and if he can, what character should be deleted.

Input

The input contains a string s of length (2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.

Output

If the solution exists, output «YES» (without quotes) in the first line. Then in the second line output a single integer x — the number of the character that should be removed from s so that the resulting string would be a palindrome. The characters in the string are numbered from 1. If there are several possible solutions, output any of them.

If the solution doesn‘t exist, output «NO» (without quotes).

Examples

input

evertree

output

YES2

input

emerald

output

NO

input

aa

output

YES2

从左右两边往中间移动,如果相同,l++,r--,如果不同,第一次循环i==0时,则让l++,第二次循环则让r--,最后判断不同的出现了几次。如果dif是0,l>=r代表本身就是回文,则去掉l位置的字符。

#include <cstring>
#include <cstdio>
#define N 100005
char s[N<<1];
int len,l,r,dif,at;
int main() {
	scanf("%s",s);
	len=strlen(s);
	for(int i=0;i<2;i++){
		dif=0;
		l=0,r=len-1;
		while(l<r){
			if(s[l]!=s[r]){
				dif++;
				if(i){
					at=r;
					r--;
				}else {
					at=l;
					l++;
				}
			}
			if(s[l]==s[r]){
				l++;
				r--;
			}
		}
		if(l>=r&&dif==0)at=l;
		if(dif<2){
			printf("YES\n%d\n",at+1);
			break;
		}
	}
	if(dif>1)puts("NO");
}

  

时间: 2024-10-06 00:22:32

【Gym 100971K】Palindromization的相关文章

【Gym 100015B】Ball Painting

题 There are 2N white balls on a table in two rows, making a nice 2-by-N rectangle. Jon has a big paint bucketfull of black paint. (Don’t ask why.) He wants to paint all the balls black, but he would like to have somemath fun while doing it. (Again, d

【Gym 100947C】Rotate It !!

分两类,奇数和偶数的,用隔项前缀和算一下. #include <algorithm> #include <iostream> #define N 10005 using namespace std; long long a,t,n,s[N],ans; int main(){ cin>>t; while(t--){ cin>>n>>s[1]; for(int i=2;i<=n;i++){ cin>>a; s[i]=a+s[i-2]

【Gym 100712B】Rock-Paper-Scissors

题 题意 对给定的对手的出拳顺序,如果只能按几个R,然后几个P,再几个S的顺序出拳(几个也可以是0个),那么求赢的方法有多少种. 分析 我原来想枚举P开始的位置和S开始的位置然后算得分,但是超时了o(╯□╰)o..因为时间复杂度T(n^3)最大规模是500,而这里n≤1000. 用前缀和思想,s[i][0到2]储存前i个里有几个R.S.P,然后再枚举P.S开始位置为i.j: 0到i-1是R的时候,对方是S,我得分,可以得到s[i-1][1]分,对方是P,我失分,失去s[i-1][2]分,同理最后

【Gym 100015A】Another Rock-Paper-Scissors Problem

题 题意 Sonny出石头剪刀布的猜拳策略是 先出R,然后每连续两段都是打败前一段的出拳, 现在问你第n回合打败他要出什么. 分析 他的策略 R P S PSR  SRP PSRSRPRPS SRPRPSPSR … … 打败他的策略是 P S R SRP  RPS SRPRPSPSR RPRPSRSRP … … 一套策略 1 1 1 3 3 9 9  … … 第几轮 1 2 3 4-6  7-9  10-18 19-27 … … 如果n是介于3的某个次方的(1,2]倍,那就是n要打败 n减去这个

【Gym 100610A】Alien Communication Masterclass

题 Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the Alien Communication Masterclass (ACM), where she teaches how to behave if you encounter alien life forms or at least alien artifa

【Gym 100733D】Little thief Shi

题 Shi realized that he was almost out of money, even renting Shitalian lands. Shi was walking on a street, while thinking of a way to recover his fortune. In his way, he passed by a jewelry store. The owner of the store was a Shitalian man suspected

【Gym - 100923A】Por Costel and Azerah(思维水题)

Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 https://vjudge.net/problem/Gym-100923A 恶心死了   freopen("azerah.in","r",stdin); freopen("azerah.out","w",stdout); 必须加

【DFS】【拓扑排序】【动态规划】Gym - 100642A - Babs&#39; Box Boutique

给你10个箱子,有长宽高,每个箱子你可以决定哪个面朝上摆.把它们摞在一起,边必须平行,上面的不能突出来,问你最多摆几个箱子. 3^10枚举箱子用哪个面.然后按长为第一关键字,宽为第二关键字,从大到小排序. 如果前面的宽大于等于后面的宽,就连接一条边. 形成一张DAG,拓扑排序后跑最长路即可. #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespa

【LIS】【递推】Gym - 101246H - ``North-East&#39;&#39;

x坐标排序,y坐标当权值,同一个x坐标的,y从大到小排. 求f(i)表示以i结尾的LIS以后,从后向前枚举,不断更新一个max数组,max(i)代表最长上升子序列为i时,当前的 结尾的最大值是多少. 一个元素可能在LIS里面,则说明存在一个j>i,f(j)=f(i)+1,且a(j)>a(i),就查询一下max(f(i)+1)是否大于a(i)即可.如果可行的话,再用该值更新max数组. 一定在LIS里面的就是i可能在LIS里面,并且f(i)只出现了一次的. 队友的代码(↓) #include &