跳到正文

题解

题解:P17173 「MSOI R1」回响

elainya_love约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年8月8日
更新
2026年8月8日
篇幅
约 2 分钟
获赞
1
题目
P17173

版本

  1. v1当前

P17173 「MSOI R1」回响 题解

你猜为啥我拿小号来写题解了。

思路

题意就是正着前 nn 个,反着前 n−1n-1 个,正着前 n−2n-2 个,反着前 n−3n-3 个……这样的。所以预处理一个 ss 是正着,tt 是反着,正反就用 i mod 2i\bmod 2 的值判断就行了。也可以像我一样搞个变量 jj 然后让它一直异或 11。然后前缀的话用 s.substr(0,长度) 就可以了。

C++
#include<bits/stdc++.h>
using namespace std;
string ccccc0;
#define int long long
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fls cerr<<"";
#define nbsp(x) ccccc0=#x;(ccccc0=="fls" ? (cerr<<'\n') : (cout<<'\n'));
#define debugx(x) cerr<<#x<<" : "<<x<<'\n';
#define debuga(x,l,r) cerr<<#x<<" : ";for(int o_o=l;o_o<=r;o_o++)cerr<<x[o_o]<<' ';cerr<<'\n';
#define debugp(x,i) cerr<<#x<<'['<<i<<']'<<" : "<<x[i]<<'\n';
#define flin(s) char ccccc1[100]=#s;freopen(strcat(ccccc1,".in"),"r",stdin);
#define flout(s) char ccccc2[100]=#s;freopen(strcat(ccccc2,".out"),"w",stdout);
#define clr(x,y) memset(x,y,sizeof x);
#define clrp(x,l,r,y) for(int o_o=l;o_o<=r;o_o++)x[o_o]=y;

const int inf=0x3f3f3f3f3f3f3f3f;
const int N=505;
int n;string s,t,ans;

signed main()
{
	fastio;
	cin>>s;
	n=s.size();
	for(int i=n-1;i>=0;i--) t+=s[i];
	ans+=s;
	for(int i=n-1,j=1;i>0;i--,j^=1)
	{
		if(j==1) ans+=t.substr(0,i);
		else ans+=s.substr(0,i);
	}
	return cout<<ans<<'\n',0;
}
原文