CSP-S游记
省流:寄了
开题:T1这么简单,不会是我想假了吧,写了40min,打开样例,怎么这么水,和没有有什么区别于是自己出了几个都过了,此时大概1h。然后看 开赛前40min我还说今年不会考大模拟吧(开了光的嘴),然后直接开摆,看 血亏
考场代码:
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
char c[2000005];
int stk[2000005],top;
inline int read(){
int f=1,res=0;
char c=getchar();
while(c<'0' || c>'9'){
if(c=='-'){
f=-1;
}
c=getchar();
}
while(c>='0' && c<='9'){
res=(res<<3)+(res<<1)+c-'0';
c=getchar();
}
return f*res;
}
int main(){
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
n=read();
scanf("%s",c+1);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j+=2){
top=0;
for(int k=i;k<=j;k++){
if(c[k]-'a'+1==stk[top] && top){
top--;
}else{
stk[++top]=c[k]-'a'+1;
}
}
if(!top){
ans++;
}
}
}
printf("%lld",ans);
return 0;
}
O(n^2) 代码:
#include<bits/stdc++.h>
using namespace std;
int n,stk[2000005],top;
long long ans=0;
char c[2000005];
int main(){
scanf("%d",&n);
scanf("%s",c+1);
for(int i=1;i<=n;i++){
top=0;
for(int j=i;j<=n;j++){
if(top && stk[top]==c[j]-'a'+1){
top--;
}else{
stk[++top]=c[j]-'a'+1;
}
if(!top){
ans++;
}
}
}
printf("%lld",ans);
return 0;
}
就只差了一点啊(悲
然后看
总分(民间数据)
寄喽