CF #541div2 E
题目本质:忽略串的变化,只记载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的更多相关文章
- CF #541div2 D
题目本质:形成一个拓扑图,不应带自环. 解决方法: 1.先把等于号的部分用dsu缩点: 2.大于和小于号建立拓扑关系: 3.n*m的矩阵,只要用标号n+j代表m集合的第j个就从二维降到一维了: 4.d ...
- CF #541div2 F
题目本质:并查集的链式合并 解决方法1: 类似哈夫曼树,叶节点们为真点,其余造一些虚的父节点,使得dfs这棵树的时候,先进行并查合并的点一定是兄弟节点因而紧挨着被输出,巧妙达到了效果. #pragma ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- 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 ...
- 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 ...
随机推荐
- jquery特效(5)—轮播图③(鼠标悬浮停止轮播)
今天很无聊,就接着写轮播图了,需要说明一下,这次的轮播图是在上次随笔中jquery特效(3)—轮播图①(手动点击轮播)和jquery特效(4)—轮播图②(定时自动轮播)的基础上写出来的,也就是本次随笔 ...
- ansible管理windows实践
一.前言 近期打算搞搞自动部署,因为是windows服务器,一些工具和系统支持都不是太好.最后发现ansible比较火,最重要的是他支持windows.本文主要就ansible 在windows使用环 ...
- nyoj 1279 (河南省第九届ACM比赛 D 题)
思路:变换一下坐标系新的坐标系就是给定的两条直线,变换之后求 x,y 都严格递增的点的个数的max: 求 x,y 都严格递增的点的个数的max,按照x的从小到大排序,x相同的按照y的从大到小排序然后对 ...
- 配置react+webpack+es6中的一些教训
1.要用es6,因为目前浏览器的支持情况,那么肯定需要插件将e6的代码转换成es5,我用的是babel-loader,事实证明使用6.x版本似乎是不行的,我换成5.3.2之后就成功了. 2.webpa ...
- C++中对类的提前引用声明注意事项
//或许,友元是VC++6.0心里永远的痛,对于这个BUG我一直很介意.//注:这个程序在VC++6.0里是行不通的,在VS2008里是可以的.#include <iostream> #i ...
- POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)
由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...
- js 异步问题
如果发现前端的异步请求,network有发送成功而且有返回值,但是没有进前端的callback成功回掉函数内,这时候就需要检查是不是配置文件做了语法限制,只能返回某些数据格式,不能返回某些数据格式. ...
- Java原子属性更新器AtomicReferenceFieldUpdater的使用
AtomicReferenceFieldUpdater是基于反射的工具类,用来将指定类型的指定的volatile引用字段进行原子更新,对应的原子引用字段不能是private的.通常一个类volatil ...
- bzoj1012最大数maxnumber——单调栈
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1012 单调栈水题:用了一下lower_bound二分. 代码如下: #include< ...
- Azure REST API (5) 中国Azure EA Portal Billing API
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. EA Portal的管理url是:https://ea.azure ...