我写了以下代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
map < char , long long > m ;
long long counti = 1 , n , k , temp , pos , t , maxi ;
for ( char c = 'a' ; c <= 'z' ; c++ ) { m[c] = counti ; counti++ ; }
for ( char c = 'A' ; c <= 'Z' ; c++ ) { m[c] = counti ; counti++ ; }
scanf ( "%lld" , &t ) ;
while ( t-- ){
temp = 0 ;
maxi = 0 ;
pos = 0 ;
scanf ( "%lld%lld" , &n , &k ) ;
string alpha ;
cin >> alpha ;
for ( long long i = 0 ; i < min ( n , ( 2 * k ) + 1 ) ; i++ ){
temp += m [ alpha [ i ] ] ;
if ( i == 2 * k ) { maxi = temp ; pos = k ; }
}
if ( maxi == 0 && pos == 0 ) { pos = n - 1 ; maxi = temp ; }
else for ( long long i = k + 1 ; i <= n - k - 1 ; i++ ){
temp -= m [ alpha [ i - k - 1 ] ] ;
temp += m [ alpha [ i + k ] ] ;
if ( temp > maxi ) { maxi = temp ; pos = i ; }
}
printf ("%lld %lld\n" , pos + 1 , maxi ) ;
}
return 0;
}
在codeforces.com提交后我收到以下错误:
Diagnostics detected issues [cpp.g++17-drmemory]: ~~Dr.M~~ Dr. Memory version 1.11.0
~~Dr.M~~ Running "program.exe"
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
~~Dr.M~~
~~Dr.M~~ Error #1: POSSIBLE LEAK 60 direct bytes 0x114200f8-0x11420134 + 0 indirect bytes
~~Dr.M~~ # 0 replace_malloc [d:\drmemory_package\common\alloc_replace.c:2576]
~~Dr.M~~ # 1 msvcrt.dll!strcpy_s +0x5e (0x75aef5d3 <msvcrt.dll+0xf5d3>)
~~Dr.M~~ # 2 msvcrt.dll!clearerr_s +0x337 (0x75af9eed <msvcrt.dll+0x19eed>)
~~Dr.M~~ # 3 msvcrt.dll!clearerr_s +0x27e (0x75af9e34 <msvcrt.dll+0x19e34>)
~~Dr.M~~ # 4 pre_cpp_init
~~Dr.M~~ # 5 __tmainCRTStartup
~~Dr.M~~ # 6 KERNEL32.dll!BaseThreadInitThunk +0x11 (0x7582343d <KERNEL32.dll+0x1343d>)
任何想法将不胜感激。请注意,代码在我的计算机上运行良好。