https://codeforces.com/contest/1080/problem/E

比赛时候一个多小时码不出来。。。

来看遇到的困难:

1.没有能用的随机unsignedlonglong函数

来一个可以A题的:

ull splitmix64(ull x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> )) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> )) * 0x94d049bb133111eb;
return x ^ (x >> );
}
ull rd()
{
static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count());
return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull);
}

2.不会马拉车

以后学。。以下代码的马拉车(calc函数)是网上找的

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<chrono>
#include<cstdlib>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; ull cpy[];
int rad[]; ull splitmix64(ull x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> )) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> )) * 0x94d049bb133111eb;
return x ^ (x >> );
}
ull rd()
{
static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count());
return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull);
} void manacher(ull str[], int rad[], int len) {
for (int i=,j=,k; i < len; i+=k,j-=k) {
while (str[i-j-] == str[i+j+]) ++j;
rad[i] = j;
for (k=; k<=j && rad[i-k]!=rad[i]-k; ++k) {
rad[i+k] = min(rad[i-k], rad[i]-k);
}
}
} ll calc(const ull *seq,int len)
{
//for(int i=0;i<len;++i)
// printf("1t%llu\n",seq[i]);
ull t1,t2,t3;
while()
{
t1=rd();t2=rd();t3=rd();
if(t1==t2||t1==t3||t2==t3) continue;
for(int i=;i<len;++i)
if(t1==seq[i]||t2==seq[i]||t3==seq[i])
continue;
break;
}
cpy[] = t1, cpy[] = t2;
for (int i=,j=; j < len; i+=,++j) {
cpy[i] = seq[j];
cpy[i+] = t2;
}
len = len*+;
cpy[len-] = t3;
manacher(cpy, rad, len);
ll ret = ;
for (int i = ; i < len-; ++i) {
ret += (rad[i]+) / ;
}
//printf("2t%lld\n",ret);
return ret;
} ull bs,bss[]={,,,,,};
ull pwx[];
ull st[];int tp;
struct CharSet
{
int num[],odd;
ull hs;
void add(int c)
{
++num[c];
odd^=(<<c);
hs+=pwx[c];
}
void del(int c)
{
--num[c];
odd^=(<<c);
hs-=pwx[c];
}
void clear()
{
memset(num,,sizeof(num));
odd=;
hs=;
}
}cs[];
ll ans;
bool ok[];
int n,m;
int to[];
char s[][];
int main()
{
int i,j,l,r;
bs=bss[rd()%];
//printf("1t%llu\n",bs);
pwx[]=;
for(i=;i<=;++i)
pwx[i]=pwx[i-]*bs;
//n=250;m=250;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)
{
scanf("%s",s[i]+);
//for(j=1;j<=m;++j)
// s[i][j]=rand()%3+'a';
}
for(l=;l<=m;++l)
{
for(i=;i<=n;++i)
cs[i].clear();
for(r=l;r<=m;++r)
{
for(i=;i<=n;++i)
cs[i].add(s[i][r]-'a');
if((r-l+)&)
{
for(i=;i<=n;++i)
{
to[i]=__builtin_ffs(cs[i].odd)-;
cs[i].del(to[i]);
}
}
for(i=;i<=n;++i)
ok[i]=!cs[i].odd;
if((r-l+)&)
{
for(i=;i<=n;++i)
cs[i].add(to[i]);
}
//printf("3t%d %d\n",l,r);
//for(i=1;i<=n;++i)
// printf("4t%llu\n",cs[i].hs);
for(i=;i<=n;++i)
if(ok[i])
{
tp=;
j=i;st[++tp]=cs[i].hs;
while(j+<=n&&ok[j+])
{
++j;
st[++tp]=cs[j].hs;
}
ans+=calc(st+,tp);
i=j;
}
//printf("5t%lld\n",ans);
}
}
printf("%lld\n",ans);
return ;
}

Sonya and Matrix Beauty Codeforces - 1080E的更多相关文章

  1. Sonya and Matrix Beauty CodeForces - 1080E (manacher)

    大意: 给定$nm$字符串矩阵. 若一个子矩形每一行重排后可以满足每行每列都是回文, 那么它为好矩形. 求所有好矩形个数. 一个矩形合法等价于每一行出现次数为奇数的最多只有一个字符, 并且对称的两行对 ...

  2. 【题解】Sonya and Matrix Beauty [Codeforces1080E]

    [题解]Sonya and Matrix Beauty [Codeforces1080E] 传送门:\(Sonya\) \(and\) \(Matrix\) \(Beauty\) \([CF1080E ...

  3. Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)

    https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...

  4. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  5. Codeforces Round #495 (Div. 2) D. Sonya and Matrix

    http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...

  6. Sonya and Matrix CodeForces - 1004D (数学,构造)

    http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...

  7. Codeforces Round #495 (Div. 2) Sonya and Matrix

    正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...

  8. Sonya and Robots(CodeForces 1004C)

    Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...

  9. D. Vasya And The Matrix(Educational Codeforces Round 48)

    D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

随机推荐

  1. CSS3文字阴影实现乳白文字效果

    CSS3文字阴影实现乳白文字效果是一款有效利用css3的text-shadow属性,可以实现很多漂亮的效果,CSS3 文字阴影 文字特效,字体效果. 源码下载:http://www.huiyi8.co ...

  2. BZOJ 3043 IncDec Sequence:反向差分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3043 题意: 给定一个长度为n的数列a[i],每次可以选择一个区间[l,r],使这个区间内 ...

  3. 读取配置和动态配置(C方法)

    读取配置 无论何种配置文件,定义了配置文件之后,都统一使用系统提供的C方法(可以借助Config单词来帮助记忆)来读取已有的配置.用法:C('参数名称') 例如,读取当前的URL模式配置参数:$mod ...

  4. 30个Jquery灯箱插件

    jQuery 是非常流行的JS框架,其俨然已成了开发者的必备工具,其中的jQuery Lightbox插件更是为广大开发者所喜爱.它惊人的特征之一是jQuery Lightbox插件有很多变化. 下面 ...

  5. ES索引瘦身 禁用_source后需要设置field store才能获取数据 否则无法显示搜索结果

    在默认情况下,开启_all和_source 这样索引下来,占用空间很大. 根据我们单位的情况,我觉得可以将需要的字段保存在_all中,然后使用IK分词以备查询,其余的字段,则不存储. 并且禁用_sou ...

  6. wordpress汇总(持续更新)

    在wordpress上新建编辑了几个页面,总是不能正常发布预览.经调查是由于固定链接的设置有问题导致的.打开左侧栏目“设置”中的固定链接项,可以看到目前所选的是“自定义结构”型.将其更改为“朴素”型后 ...

  7. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  8. ACM学习历程—CodeForces 176B Word Cut(字符串匹配 && dp && 递推)

    Description Let's consider one interesting word game. In this game you should transform one word int ...

  9. Ubuntu——Python3.x——scikit-learn 安装

    修改默认Python (默认的是Python2.7) rm -rf /usr/bin/python ln -s /usr/bin/ptyhon3 /usr/bin/python 安装所需依赖: apt ...

  10. 在python 3.6的eclipse中,导入from lxml import etree老是提示,Unresolved import:etree的错误

    支持代码运行没问题,暂时没有找到真正解决办法,只能通过一下办法暂时解决.如下图: