Sonya and Matrix Beauty Codeforces - 1080E
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的更多相关文章
- Sonya and Matrix Beauty CodeForces - 1080E (manacher)
大意: 给定$nm$字符串矩阵. 若一个子矩形每一行重排后可以满足每行每列都是回文, 那么它为好矩形. 求所有好矩形个数. 一个矩形合法等价于每一行出现次数为奇数的最多只有一个字符, 并且对称的两行对 ...
- 【题解】Sonya and Matrix Beauty [Codeforces1080E]
[题解]Sonya and Matrix Beauty [Codeforces1080E] 传送门:\(Sonya\) \(and\) \(Matrix\) \(Beauty\) \([CF1080E ...
- Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)
https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...
- codeforces 495D Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...
- Codeforces Round #495 (Div. 2) D. Sonya and Matrix
http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...
- Sonya and Matrix CodeForces - 1004D (数学,构造)
http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...
- Codeforces Round #495 (Div. 2) Sonya and Matrix
正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...
- Sonya and Robots(CodeForces 1004C)
Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...
- 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 ...
随机推荐
- Smarty模板重点汇总
Smarty模板重点回顾:1.功能:前后端分离:2.实现方法:通过使用Smarty的核心类来实现,利用display方法来读取模板文 件,用正则进行替换,替换完保存到临时文件,再将临时文件加载到当前页 ...
- Redis常用数据结构和操作
1.String 存入字符类型 Set name luowen 设置name = luowen 存储 Get name 获取设置好的name的值 Setnx name luowen 设置name键值为 ...
- linux应用之bugfree的安装及配置
Bugfree3.0.4 Linux环境安装指南 bugfree系统安装的前提是,配置LAMP环境(apache+mysql+php),下面以centos6.3系统为例介绍bugfree3.0.4的安 ...
- Seal Report结合MySQL数据库 报表展现_20161011
昨天留了草稿 未来得及发 今日补发一篇 seal report 操作类似excel数据透视表也包含行标签和列标签及值标签,行列代表的是数据指标的维度,值标签代表的是度量. seal report连接M ...
- Seal Report_20160923
Seal Report算是报表工具中比较好用的一个,它提供了一个完整的从其他任何数据库产生报表的架构.该产品主要关注于容易安装和报表设计,一旦安装好,报表很快就可以建立并且发布.该组件完全开源,使用C ...
- BZOJ_2259_ [Oibh]新型计算机 _最短路
Description Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假 ...
- 关于ssh免密互访
想要通过ssh进行免密处理,细节就不赘述了,白度一搜一大把: 但是我遇到了一个情况,就是生成的公钥后无法复制到user/.ssh目录下,因为没有ssh目录(.ssh是隐藏目录,正常情况下ls都无法查看 ...
- JSON 的正确用法:Python、MongoDB、JavaScript与AjaxJSON 的正确用法:Python、MongoDB、JavaScript与Ajax
本文主要总结网站编写以来在传递 JSON 数据方面遇到的一些问题以及目前采用的解决方案.网站数据库采用 MongoDB,后端是 Python,前端采用“半分离”形式的 Riot.js,所谓半分离,是说 ...
- java的桥接模式
http://blog.csdn.net/jason0539/article/details/22568865 http://www.cnblogs.com/V1haoge/p/6497919.htm ...
- try-catch-finally中return的执行情况
在try中没有异常的情况下try.catch.finally的执行顺序 try--- finally 如果try中有异常,执行顺序是try--- catch --- finally 如果try中没有异 ...