1 Star 1 Fork 0

yinjinrun/code-public-2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AGC037E.cpp 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
yinjinrun 提交于 3年前 . AGC037E
#include <bits/stdc++.h>
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)
using namespace std;
using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;
template < typename T > T read() {
T x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)) f |= ch == '-', ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }
const int N = 1e6 + 10;
string s;
int n, K;
string rev(string s) { reverse(s.begin(), s.end()); return s; }
string get(string s) {
string lst, ret;
rep(i, 0, n + n - 1) {
lst = s[i] + lst;
if(lst.size() > n) lst.resize(n);
if(lst.size() == n) {
if(!ret.size()) ret = lst;
else chkmin(ret, lst);
}
} return rev(ret);
}
string mxget(string s) {
string lst, ret;
rep(i, n - 1, n + n - 1) {
lst = ""; rep(j, i - n + 1, i) lst += s[j];
if(i == n - 1) ret = lst;
else chkmin(ret, lst);
} return ret;
}
int main() {
#ifdef YJR_2333_TEST
freopen("1.in", "r", stdin);
#endif
n = in, K = in; cin >> s;
rep(i, 1, K - 1) {
s = get(s + rev(s));
bool fl = 1;
for(auto v : s) fl &= v == s[0];
if(fl) break;
} s = mxget(s + rev(s)); cout << s << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yinjinrun/code-public-2.git
git@gitee.com:yinjinrun/code-public-2.git
yinjinrun
code-public-2
code-public-2
master

搜索帮助