EZOJ #387字符串
分析
似乎ttl的模拟赛t3总是折半搜索?
先把所有串转化为每个字母的0/1状态
之后我们将所有字符串分为两半
分别枚举状态
我们发现只有左右两边的字母状态相等才能保证这个集合合法
所以我们在搜左半边的时候每次加入一个pair
表示异或值为x用了y个数
搜完后先将它排序
然后搜右边的时候每次lower_bound一下即可
似乎ttl的数据比较强我的代码常数又很大,所以要开O2才能过/kk
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pi pair<int,int>
#define int long long
pi a[(<<)+];
int ans,wh[],n,m,sum[],cnt1,mx;
char s[];
inline void dfs1(int p,int lim,int now,int tot){
if(p>lim){
a[++cnt1]=mp(now,tot);
return;
}
dfs1(p+,lim,now^wh[p],tot+);
dfs1(p+,lim,now,tot);
return;
}
inline void dfs2(int p,int lim,int now,int tot){
if(p>lim){
pi *le=lower_bound(a+,a+cnt1+,mp(now,-1ll));
pi *ri=lower_bound(a+,a+cnt1+,mp(now+,-1ll));
ans+=(ri-le);
ri--;
if((ri->fi)==now)mx=max(mx,(ri->se)+tot);
return;
}
dfs2(p+,lim,now^wh[p],tot+);
dfs2(p+,lim,now,tot);
return;
}
signed main(){
int i,j,k;
scanf("%lld",&n);
for(i=;i<=n;i++){
memset(sum,,sizeof(sum));
scanf("%s",s);
m=strlen(s);
for(j=;j<m;j++)sum[s[j]-'a']^=;
for(j=;j<;j++)
wh[i]|=((<<j)*sum[j]);
}
dfs1(,n/,,);
sort(a+,a+cnt1+);
dfs2(n/+,n,,);
printf("%lld %lld\n",ans-1ll,mx);
return ;
}
EZOJ #387字符串的更多相关文章
- 前端与算法 leetcode 387. 字符串中的第一个唯一字符
目录 # 前端与算法 leetcode 387. 字符串中的第一个唯一字符 题目描述 概要 提示 解析 解法一:双循环 解法二:Set法单循环 算法 传入测试用例的运行结果 执行结果 GitHub仓库 ...
- Java实现 LeetCode 387 字符串中的第一个唯一字符
387. 字符串中的第一个唯一字符 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 案例: s = "leetcode" 返回 0. s = ...
- LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String
题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. Given a string, find the first non-repeating charact ...
- LeetCode初级算法之字符串:387 字符串中的第一个唯一字符
字符串中的第一个唯一字符 题目地址:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 给定一个字符串,找到它的第 ...
- Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符
/* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...
- C#LeetCode刷题-字符串
字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.6% 中等 5 最长回文子串 22.4% 中等 6 Z字形变换 35.8% 中等 8 字符串转整数 (atoi) ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- 精选 TOP 面试题
1 两数之和 46.5%简单2 两数相加 35.5%中等3 无重复字符的最长子串 31.1%中等4 寻找两个有序数组的中位数 35.9%困难5 最长回文子串 2 ...
- C#LeetCode刷题-哈希表
哈希表篇 # 题名 刷题 通过率 难度 1 两数之和 C#LeetCode刷题之#1-两数之和(Two Sum) 42.8% 简单 3 无重复字符的最长子串 24.2% 中等 18 四数之和 ...
随机推荐
- repr_str方法
该方法可以改变字符串的显示格式 class School: def __init__(self,name,addr,type): self.name = name self.addr = addr s ...
- github廖雪峰git
gitHub地址: https://github.com/DickyQie/Tool-use/tree/git-learning-document
- VSCode工具插件推荐
一:VSCode简介 VSCode( Visual Studio Code)是微软出的一款轻量级代码编辑器 ,重要的是它在Windows, OS X 和Linux操作系统的桌面上均可运行.Visual ...
- [2019杭电多校第一场][hdu6579]Operation(线性基)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题目大意是两个操作,1个是求[l,r]区间子序列的最大异或和,另一个是在最后面添加一个数. 如果 ...
- [集合]List
List 存取有序,有索引,可以重复 ArrayList去除集合中字符串的重复值(字符串的内容相同) public static void main(String[] args) { ArrayLis ...
- P4643 [国家集训队]阿狸和桃子的游戏
传送门 这题看一眼就很不可做 考虑对于任意一个最终状态,对于一条边的贡献分成三种情况 如果此边连接的两点属于 $A$,那么对 $A$ 的贡献就是边权 $w$,即对答案的贡献为 $+w$ 如果两点都属于 ...
- spark复习笔记(4):RDD变换
一.RDD变换 1.返回执行新的rdd的指针,在rdd之间创建依赖关系.每个rdd都有一个计算函数和指向父rdd的指针 Spark是惰性的,因此除非调用某个转换或动作,否则不会执行任何操作,否则将触发 ...
- eclipse hibernate配置文件(*.hbm.xml)加上自动提示功能
转自:https://blog.csdn.net/u012217085/article/details/17397843?utm_source=blogkpcl3 1. 标签:hibernate 在编 ...
- 2018-9-21-dot-net-core-使用-usb
title author date CreateTime categories dot net core 使用 usb lindexi 2018-09-21 19:53:34 +0800 2018-0 ...
- linux 验证 NFS 是否成功
服务器端----->>客户端 1. 服务器端 [root@allentuns ~]# ifconfig |grep "Bcast" inet addr:192.168. ...