QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751050 | #9568. Left Shifting 3 | Crying# | AC ✓ | 11ms | 6072kb | C++14 | 1.1kb | 2024-11-15 16:52:01 | 2024-11-15 16:52:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
//
int T,n,k,m = 7,f[N],pre[N],suf[N],ans;
string s,t=" nanjing";
void solve(){
cin>>n>>k; tomin(k,n-1);
cin>>s; s = " "+s;
ans = 0; for(int i=0;i<=n+1;i++)f[i] = pre[i] = suf[i] = 0;
for(int i=1;i<=n-m+1;i++){
f[i] = 1;
for(int j=1;j<=m;j++)f[i] &= s[i+j-1] == t[j];
}
for(int i=1;i<=n;i++)pre[i] = pre[i-1] + f[i]; for(int i=n;i>=1;i--)suf[i] = suf[i+1] + f[i];
for(int i=0;i<=k;i++){
int cnt = pre[i] + suf[i+1];
for(int j=1;j<m;j++){
if(m-j > i || j > n-i)continue;
int w = 1;
for(int k=1;k<=j;k++)w &= t[j-k+1] == s[n-k+1];
for(int k=1;k<=m-j;k++)w &= t[j+k] == s[k];
cnt += w;
}
tomax(ans,cnt);
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>T; while(T--)solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: 5ms
memory: 3812kb
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: 11ms
memory: 6072kb
input:
3 100000 998244353 gbppzfsncqyzmuwrcvtxsciucxusskcjhaanwhqmyncytwhkubrvcqxgcehdxyewdyvpqjcmrnmlgrytrucexmmfulqbtfctehphmrzkosyvhtvjrromqncbgsjcwhmlqidkycaxyhsrduoxayntuhqubvboseeziwjvrfagsbvtxjjbexnajqapgxydwtztzbbdpoydnjipfizdfpmczgqvdmpvxbqubtygkfpdeonegfzsttirbhzkobbigwneyvtcxndfkljdvbbcfnadtfhgo...
output:
4 1649 3651
result:
ok 3 number(s): "4 1649 3651"
Extra Test:
score: 0
Extra Test Passed