题目本质:忽略串的变化,只记载26个字母的相关变化。

解决方法:

在上一次与本次的转移过程中,情况并不多,主要取决于本次串的首尾字母,若不是本次的首尾字母,会被置1;如果是的话,分情况接一下并更新。另外应该不会忘记的就是要拿本次串的最长串再更新一下。

复杂度最差时不是O(n2)吗?数据骗了。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#define ri readint()
#define gc getchar()
#define R(x) scanf("%d", &x)
#define W(x) printf("%d\n", x)
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
#define ls p << 1
#define rs p << 1 | 1
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; inline int readint() {
int x = , s = , c = gc;
while (c <= ) c = gc;
if (c == '-') s = -, c = gc;
for (; isdigit(c); c = gc)
x = x * + c - ;
return x * s;
} const int maxn = 1e5 + ; vector<ll> getLength(string s) {
vector<ll> v(, );
int len = , last = -; rep(i, , s.length() - ) {
int now = s[i] - 'a';
if (now == last) {
len++;
} else {
last = now;
len = ;
}
v[now] = max(v[now], (ll)len);
} return v;
} int main() {
ios_base::sync_with_stdio(false);
cin.tie(); int n;
cin >> n;
string s;
cin >> s;
vector<ll> Len = getLength(s); rep(i, , n - ) {
cin >> s;
int prec = s[] - 'a', sufc = s.back() - 'a';
int prel = , sufl = ;
rep(j, , s.length() - ) {
if (s[j] - 'a' == prec) prel++;
else break;
}
irep(j, s.length() - , ) {
if (s[j] - 'a' == sufc) sufl++;
else break;
} vector<ll> cur = getLength(s);
if (prel == s.length()) {
rep(j, , ) {
if (j == prec) {
Len[j] += (Len[j] + ) * prel;
} else {
Len[j] = min(Len[j], 1ll);
}
}
} else {
rep(j, , ) {
if (Len[j])
Len[j] = (prec == j) * prel + (sufc == j) * sufl + ;
Len[j] = max(Len[j], cur[j]);
}
} rep(j, , ) Len[j] = min(Len[j], (ll)1e9);
} ll ans = -;
rep(i, , ) ans = max(ans, Len[i]);
cout << ans << endl;
return ;
}

CF #541div2 E的更多相关文章

  1. CF #541div2 D

    题目本质:形成一个拓扑图,不应带自环. 解决方法: 1.先把等于号的部分用dsu缩点: 2.大于和小于号建立拓扑关系: 3.n*m的矩阵,只要用标号n+j代表m集合的第j个就从二维降到一维了: 4.d ...

  2. CF #541div2 F

    题目本质:并查集的链式合并 解决方法1: 类似哈夫曼树,叶节点们为真点,其余造一些虚的父节点,使得dfs这棵树的时候,先进行并查合并的点一定是兄弟节点因而紧挨着被输出,巧妙达到了效果. #pragma ...

  3. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  6. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  7. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  8. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  9. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

随机推荐

  1. MySQL学习笔记(四)——分组数据group by子句和having子句

    分组允许把数据分为多个逻辑组,以便对每个组进行聚集计算. 例如我们查下每个系里有多少名学生: 在使用group by 子句之前,还需要知道一些规定: 1. group by 子句可以包含任意数目的列, ...

  2. 极光API推送 (v3 版本)

    Push API v3 这是 Push API 最近的版本. 相比于 API v2 版本,v3 版本的改进为: 完全基于 https,不再提供 http 访问: 使用 HTTP Basic Authe ...

  3. HihoCoder 1638 : 小Hi的天平 (2-sat+并查集)

    描述 小Hi给小Ho邮寄了一个天平.收到天平后,小Ho想知道天平在运输过程中是否损坏,为此它准备了A类物品和B类物品共n个(可能只有A类物品,也可能只有B类物品),但无法确定一个物品是哪一类.A类物品 ...

  4. 开发板启动时,内核打印出"can't access tty,job control turned off"

    启动后的最后一行提示can't access tty,job control turned off, 这说明没有进入到控制台,原因就在于文件系统的/etc/inittab 这个文件里有问题 vi /e ...

  5. $bzoj4569$

    $st表+并查集$ $考虑暴力方法:我们每次将对应相等的位置用并查集连起来,那么最终答案就是9*10^{连通块个数-1}$ $很明显上面这个办法过不去,问题在于重复次数太多了,如果一个区间已经对应相等 ...

  6. ARM之工作模式

    前言            以下内容是个人学习之后的感悟,转载请注明出处~ ARM工作模式 ARM工作模式根据功能不同,可分为7类: User Mode:用户模式.操作系统的Task一般以这种模式执行 ...

  7. 【转】Cache Buffer Chain 第二篇

    文章转自:http://m.bianceng.cn/database/Oracle/201407/42884.htm 测试环境:版本11gR2 SQL> select * from v$vers ...

  8. stdout引发的curl 302跳转 crash

    重现步骤: 0.开发环境:Windows 7 SP1 64bit, VS2008 SP1 1.进程中修改了stdout这个句柄的值:调用了prinft和cout都会修改stdout,TRACE不会修改 ...

  9. SQLite win7

    https://blog.csdn.net/louislee92/article/details/50390000 vs2008利用sqlite A 添加sqlite3.h sqlite3.lib到工 ...

  10. 关于在项目中遇到MySQL数据库死锁的问题

    在MySQL中, 当一个事务去更新某条数据, 还没有提交的时候, 第二个事务去更新该数据, 则会出现等待获取锁超时异常: >> Lock wait timeout exceeded; tr ...