-2
我在Codeforces问题(测试用例#28)上得到了超出时间限制的错误。我该如何改进我的Codeforces解决方案?它显示超出时间限制
链接是http://codeforces.com/problemset/problem/525/B 该解决方案无处可寻谷歌。 有没有人有任何想法让这个解决方案更快一点。
我的代码是:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
char str[2000005];
scanf("%s", &str);
long long l = strlen(str);
long long k, i, j, days, pos, counter = 0;
scanf("%I64d", &days);
for (k = 1; k <= days; k++) {
f:
cin >> pos;
counter++;
i = pos - 1;
j = l - pos;
// swap(str[pos - 1], str[l - pos])
start:
swap(str[i], str[j]);
i++;
j--;
if (i <= j)
goto start;
else if (i > j && counter < days)
goto f;
else if(counter==days)
break;
}
printf("%s", str);
return 0;
}
谢谢Shreevardhan。但它仍然显示你的代码上的TLE :( – Subhankar
非常感谢:)它被接受:);) – Subhankar