QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744669 | #9568. Left Shifting 3 | Harryxxy | TL | 0ms | 3768kb | C++20 | 782b | 2024-11-13 22:46:01 | 2024-11-13 22:46:02 |
Judging History
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...