T1
AC代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("restore.in","r",stdin);
freopen("restore.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int k=n;
for(int i=0,j=n-1;i<k/2;i++,j--){
if(s[i]!=s[j]) n-=2;
else break;
}
cout<<n<<'\n';
}
return 0;
}T2
WA代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[4][N];
int dp[4][N];
int n;
int main()
{
freopen("study.in","r",stdin);
freopen("study.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[0][i];
for(int i=1;i<=n;i++) cin>>a[1][i];
for(int i=1;i<=n;i++) cin>>a[2][i];
for(int i=n;i>=1;i--){
for(int j=0;j<3;j++){
dp[j][i]=a[j][i]+min(dp[(j+2)%3][i+1],dp[(j+4)%3][i+1]);
}
}
for(int i=0;i<3;i++){
for(int j=1;j<=n;j++){
cout<<dp[i][j]<<' ';
}
cout<'\n';
}
cout<<min(dp[0][1],min(dp[1][1],dp[2][1]));
return 0;
}错因
第~行是比赛时的调试!忘删了!!!
T^T