QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747636 | #9568. Left Shifting 3 | PlentyOfPenalty# | AC ✓ | 3ms | 6184kb | C++20 | 1.1kb | 2024-11-14 17:44:08 | 2024-11-14 17:44:08 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) (void(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
const int N = 500011;
string s, t = "nanjing";
int f[N];
int main() {
#ifdef memset0
freopen("E.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
int task;
cin >> task;
while (task--) {
int n, k;
cin >> n >> k >> s;
s = s + s;
s.insert(s.begin(), '#');
for (int i = 0; i < s.size(); ++i) f[i] = 0;
for (int i = 1; i + t.size() - 1 < s.size(); ++i) {
bool eq = 1;
for (int k = 0; k < t.size(); ++k)
if (s[i + k] != t[k]) {
eq = 0;
break;
}
if (eq) f[i] = f[i - 1] + 1;
else
f[i] = f[i - 1];
}
int ans = 0;
for (int i = max(sz(t), n); i <= n + k && i < sz(s); ++i) ans = max(ans, f[i - t.size() + 1] - f[i - n]);
cout << ans << '\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 0
Accepted
time: 3ms
memory: 3704kb
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:
3 0 3 2 2 3 3 4 3 4 0 2 4 3 2 1 1 1 4 2 0 3 3 0 0 1 0 0 0 5 4 0 1 2 1 2 2 1 1 1 3 3 1 3 2 0 1 2 4 1 2 1 2 1 2 3 0 1 0 0 1 1 3 2 2 1 0 3 1 2 1 1 4 4 1 1 1 1 0 1 1 1 1 2 0 4 4 3 1 1 2 1 1 1 1 5 1 4 0 1 2 1 3 4 3 3 3 3 1 3 2 1 3 1 2 0 0 1 0 5 0 2 0 3 1 0 2 2 3 2 1 2 0 1 1 1 2 4 1 3 2 0 1 1 2 2 2 1 0 3 ...
result:
ok 2130 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 6184kb
input:
3 100000 998244353 gbppzfsncqyzmuwrcvtxsciucxusskcjhaanwhqmyncytwhkubrvcqxgcehdxyewdyvpqjcmrnmlgrytrucexmmfulqbtfctehphmrzkosyvhtvjrromqncbgsjcwhmlqidkycaxyhsrduoxayntuhqubvboseeziwjvrfagsbvtxjjbexnajqapgxydwtztzbbdpoydnjipfizdfpmczgqvdmpvxbqubtygkfpdeonegfzsttirbhzkobbigwneyvtcxndfkljdvbbcfnadtfhgo...
output:
4 1649 3651
result:
ok 3 number(s): "4 1649 3651"
Extra Test:
score: 0
Extra Test Passed