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. BZOJ 1647 [Usaco2007 Open]Fliptile 翻格子游戏:部分枚举 位运算

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1647 题意: 在一个n*m(1 <= n,m <= 15)的棋盘上,每一个格子 ...

  2. PHPexcel把数据库数据直接转化为excel表格

    运行文件  index.php <?php$dir =dirname(__FILE__); //获取当前文件的路径require $dir.'/Classes/phpexcel.php'; // ...

  3. css书写规则

    无规矩不成方圆,不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的 不要在自闭合(self-closing)元素的尾部添加斜线 不要省略可选的结束标签(closing tag)(例 ...

  4. bzoj2673

    限制这么多 肯定是网络流 考虑连边 首先我们计算出每行最多放的棋子数$sx[i]$,每列最多放的棋子数$sy[i]$ 首先由源点向第$i$行连流量为$sx[i]$费用为$0$的边,第$i$列向汇点连流 ...

  5. POJ1006Biorhythms——中国剩余定理

    题目:http://poj.org/problem?id=1006 用扩展欧几里得算法求逆元,使用中国剩余定理: 本题较简单,可以手算直接写出,不过我仍使用了模板. 代码如下: #include< ...

  6. java 基础知识学习 内存泄露(memory leak) VS 内存溢出(out of memory)以及内存管理

    内存泄露(memory leak) VS 内存溢出(out of memory) 内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory ...

  7. 计算机网络HTTP、TCP/IP包

    参考: TCP-IP数据包结构详解 HTTP报文格式详解 Http协议报文格式 HTTP请求/响应报文结构 [Java知识]GET和POST请求的区别

  8. [翻译]Nativescript 中 Web 视图与 Android/IOS 的双向通信

    English document From http://shripalsoni.com/blog/nativescript-webview-native-bi-directional-communi ...

  9. 2014年第五届蓝桥杯国赛试题(JavaA组)

    1.结果填空 (满分15分)2.结果填空 (满分45分)3.代码填空 (满分30分)4.程序设计(满分30分)5.程序设计(满分80分)6.程序设计(满分100分) 1.标题:海盗分金币 有5个海盗, ...

  10. Linux 系统初始化和服务

    系统的初始化和服务 1. Linux 系统启动流程 打开计算机,从主板 BIOS(Basic Input/Out System)读取其中所存储的程序,引导你找到存储系统的硬件(如光盘.硬盘等) 接下来 ...