QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734680#9568. Left Shifting 3wifi32767AC ✓17ms4040kbC++201.1kb2024-11-11 14:07:432024-11-11 14:07:44

Judging History

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

  • [2024-11-11 14:07:44]
  • 评测
  • 测评结果:AC
  • 用时:17ms
  • 内存:4040kb
  • [2024-11-11 14:07:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
const int MAX = 3e5 + 5;

int kmp(string s1, string s2){
    int l1 = s1.size(), l2 = s2.size();
    s1 = ' ' + s1;
    s2 = ' ' + s2;
    vector<int> nex(l2 + 1);
    int ans = 0;
    int j = 0;
    for (int i = 2; i <= l2; ++ i){
		while (j and s2[i] != s2[j + 1]) j = nex[j];
		if (s2[i] == s2[j + 1]) j ++;
		nex[i] = j;
    }
    j = 0;
    for (int i = 1; i <= l1; ++ i){
        while (j and s1[i] != s2[j + 1]) j = nex[j];
        if (s1[i] == s2[j + 1]) j ++;
        if (j == l2) ans ++, j = nex[j];
    }
    return ans;
}

void solve(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int ans = 0;
    string t = "nanjing";
    for (int i = 0; i < min(7, k + 1); i ++){
        string s2;
        for (int j = 0; j < n; j ++){
            s2 += s[(i + j) % n];
        }
        ans = max(ans, kmp(s2, t));
    }
    cout << ans << endl;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // cout << fixed << setprecision(10);
    int T;cin>>T;while (T--)
        solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 9ms
memory: 3732kb

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: 17ms
memory: 4040kb

input:

3
100000 998244353
gbppzfsncqyzmuwrcvtxsciucxusskcjhaanwhqmyncytwhkubrvcqxgcehdxyewdyvpqjcmrnmlgrytrucexmmfulqbtfctehphmrzkosyvhtvjrromqncbgsjcwhmlqidkycaxyhsrduoxayntuhqubvboseeziwjvrfagsbvtxjjbexnajqapgxydwtztzbbdpoydnjipfizdfpmczgqvdmpvxbqubtygkfpdeonegfzsttirbhzkobbigwneyvtcxndfkljdvbbcfnadtfhgo...

output:

4
1649
3651

result:

ok 3 number(s): "4 1649 3651"

Extra Test:

score: 0
Extra Test Passed