QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744669#9568. Left Shifting 3HarryxxyTL 0ms3768kbC++20782b2024-11-13 22:46:012024-11-13 22:46:02

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 22:46:02]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3768kb
  • [2024-11-13 22:46:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int solve(const string &s) {
    const string s1 = "nanjing";
    int cnt = 0;
    size_t pos = s.find(s1);
    while (pos != string::npos) {
        cnt++;
        pos = s.find(s1, pos + 1);
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while (T--) {
        long long n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int maxn = solve(s);
        string s2 = s + s;
        int minn = min(n, k);
        for (int i = 1; i <= minn; ++i) {
            string current = s2.substr(i, n);
            maxn = max(maxn, solve(current));
        }

        cout << maxn << '\n';
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3768kb

input:

4
21 10
jingicpcnanjingsuanan
21 0
jingicpcnanjingsuanan
21 3
nanjingnanjingnanjing
4 100
icpc

output:

2
1
3
0

result:

ok 4 number(s): "2 1 3 0"

Test #2:

score: -100
Time Limit Exceeded

input:

2130
39 7
nnananjingannanjingngnanjinganjinggjina
1 479084228
g
33 2
gqnanjinggrjdtktnanjingcvsenanjin
24 196055605
ginganjingnanjingnanjing
23 3
ngnanjinganjingjinnanji
40 3
njingaaznannanjingnananjingyonwpnanjinga
40 207842908
nanjinggphconanjingkonanjinannanjinglxna
46 3
ingjingnnanjingnanjinging...

output:


result: