一个点MLE了……

P1246 编码

暴力稳稳过了(最慢跑了21ms) ```cpp #include<bits/stdc++.h> using namespace std; string str; int k; queue<string> qt; int main(){ cin>>str; for(int i=1;i<str.length();i++){ if(str[i]<=str[i-1]){ printf("0"); return 0; } } qt.push(""); while(!qt.empty()){ string now=qt.front(); int c; if(now.length()) c=now[now.length()-1]+1-'a'; else c=0; for(int i=c;i<26;i++){ string p=now; p+=char(i+'a'); k++; if(p==str){ printf("%d",k); return 0; } qt.push(p); } qt.pop(); } return 0; } ```
by YuRuochen @ 2022-09-10 23:13:42


|