2023 江苏CCPC A. Today‘s Word

A. Today's Word

time limit per test: 1 second

memory limit per test: 256 megabytes

You have accepted an offer at VortaroEnMano Inc., a company committed to creating the most comprehensive Esperanto dictionary. Esperanto estas tre mojosa lingvo, so you work really hard to do your best -- mostly to keep your job in the depression of employment.

Today, you're assigned to refactor the function called "Hodiaŭa Vorto", i.e. "Today's Word" in English. This word is generated from a string, denoted as .

Here's how is generated:

1.The process begins with an initial string, , which is given. This string contains only lowercase English letters and has an even length.

2.For n≥1, is generated in the following way:

, where is the length of and +

is used to concatenate the strings. Note that the index of the string starts from 0.

The function next(S) increments each character in the string S to the next letter in the alphabet, i.e., a changes to b , b to c, and so on, with z changing to a. For instance, next(abz)=bca.

Your task is to determine the suffix of with a length of m.

Input

The first line contains two integers n

and m (1≤n,m≤), representing the length of and the length of the desired suffix, respectively. It is guaranteed that n is an even number.

The second line contains a string, , composed of n lowercase English letters.

Output

Output a string of length m, which represents the suffix you are tasked to determine.

Example

input

6 10

bocchi

output

wrwxrwxsxy

Note

In the provided example, S1=bocbocchidij.

【思路分析】

递推+构造+模拟。直接模拟,从的后缀暴力构造,由于每次长度倍增,时间复杂度为.

cpp 复制代码
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <cstring>

#define i64 long long

using namespace std;

void getString(string &s) {
    for (auto &item: s) {
        if (item + 16 <= 'z') item = item + 16;
        else item = 16 - ('z' - item) + 'a' - 1;
    }
}

void moveForwardString(string &s) {
    for (auto &item: s) {
        if (item - 1 < 'a') item = 'z';
        else item -= 1;
    }
}

void moveBackString(string &s) {
    for (auto &item: s) {
        if (item + 1 > 'z') item = 'a';
        else item += 1;
    }
}

void solve() {
    i64 n, m;
    cin >> n >> m;
    string s, tmp;
    cin >> s;
    string sub = s.substr(n / 2, n / 2);
    getString(sub);
    int cnt = 4;
    for (int i = 4 * n; i >= n / 2; i -= n / 2) {
        tmp.insert(0, sub);
        if (cnt == 4 || cnt == 2) moveForwardString(sub);
        cnt--;
        if (cnt == 0) {
            cnt = 4;
            moveBackString(sub);
        }
    }
    for (int i = 0;i < 25;i++) {
        cnt = 4;
        sub = tmp;
        if (tmp.length() >= m) break;
        tmp.clear();
        for (int i = 4 * n; i >= n / 2; i -= n / 2) {
            tmp.insert(0, sub);
            if (cnt == 4 || cnt == 2) moveForwardString(sub);
            cnt--;
            if (cnt == 0) {
                cnt = 4;
                moveBackString(sub);
            }
        }
    }
    cout<<tmp.substr(tmp.length()-m,m);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
相关推荐
我只会发热2 分钟前
Java SE 与 Java EE:基础与进阶的探索之旅
java·开发语言·java-ee
懷淰メ11 分钟前
PyQt飞机大战游戏(附下载地址)
开发语言·python·qt·游戏·pyqt·游戏开发·pyqt5
hummhumm25 分钟前
第 22 章 - Go语言 测试与基准测试
java·大数据·开发语言·前端·python·golang·log4j
宁静@星空31 分钟前
006-自定义枚举注解
java·开发语言
hummhumm42 分钟前
第 28 章 - Go语言 Web 开发入门
java·开发语言·前端·python·sql·golang·前端框架
武子康1 小时前
Java-07 深入浅出 MyBatis - 一对多模型 SqlMapConfig 与 Mapper 详细讲解测试
java·开发语言·数据库·sql·mybatis·springboot
珹洺1 小时前
C语言数据结构——详细讲解 双链表
c语言·开发语言·网络·数据结构·c++·算法·leetcode
每天吃饭的羊1 小时前
python里的数据结构
开发语言·python
码农飞飞1 小时前
详解Rust枚举类型(enum)的用法
开发语言·rust·match·枚举·匹配·内存安全
孙同学要努力1 小时前
C++知识整理day1——前置基础知识整理(命名空间、输入输出、函数重载、引用)
开发语言·c++