题目
题目链接:http://codeforces.com/contest/666/problem/A
题目来源:Codeforces #349 div1
题解
英文是硬伤,twice in a row竟然是连续两次,赛后两眼泪汪汪。
首先肯定是用个set去存,比较方便。
反向扫,根据可行性进行递推,就去看+2,+3的位置是否可以进行递推。
连续两次的条件就去判断能否在之后用不同长度构造,或者相同长度字符不同。
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
// head
const int N = 1e4+5;
char s[N];
char temp[15];
bool a[N];
set<string> ma;
int main() {
scanf("%s", s);
int n = strlen(s);
a[n] = true;
for (int i = n-2; i > 4; i--) {
if (a[i+2]) {
for (int j = 0; j < 2; j++) {
temp[j] = s[i+j];
}
temp[2] = '\0';
string ss = temp;
ma.insert(ss);
if (strstr(s+i+2, temp) != s+i+2 || a[i+5]) a[i] = true;
}
if (a[i+3]) {
for (int j = 0; j < 3; j++) {
temp[j] = s[i+j];
}
temp[3] = '\0';
string ss = temp;
ma.insert(ss);
if (strstr(s+i+3, temp) != s+i+3 || a[i+5]) a[i] = true;
}
}
printf("%d\n", ma.size());
for (auto it : ma) {
printf("%s\n", it.c_str());
}
return 0;
}