BZOJ 4236: JOIOJI map瞎搞
分别记录J,O,I,的个数
cnt[char][i] 表示处理到第i位,char的个数
显然当且仅当
cnt[J][i] - cnt[O][i] == cnt[J][j-1] - cnt[O][j-1] && cnt[O][i] - cnt[I][i] == cnt[O][j-1] - cnt[I][j-1] 时
i到j位是一个长为i-j+1的合法串
于是把状态压到一个 long long 里 map瞎搞就行
没去掉调试输出导致WA了四次QAQ
#include<cstdio>
#include<iostream>
#include<map>
#define R register int
using namespace std;
map<long long,int>mp;
int n,ans,cnt[];
inline int fx(char ch) { if(ch=='J') return ; if(ch=='O') return ; if(ch=='I') return ;}
signed main() {
register char ch;
scanf("%d",&n); R nn=n;
mp[]=-;
while(!isalpha(ch=getchar()));
do { --n;
++cnt[fx(ch)]; //cout<<ch<<" "<<fx(ch)<<endl;
R pos=mp[(cnt[]-cnt[])*+cnt[]-cnt[]+];
if(!pos) mp[(cnt[]-cnt[])*+cnt[]-cnt[]+]=nn-n;//,cout<<nn-n<<endl;
else ans=max(ans,nn-n-pos+(pos==-?-:));//,cout<<"aaasskk:"<<ans<<endl; cout<<"ans:"<<ans<<endl;
//cout<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<" "<<(cnt[0]-cnt[1])*800000+cnt[1]-cnt[2]+1000000000000000<<endl;
//cout<<mp[(cnt[0]-cnt[1])*800000+cnt[1]-cnt[2]]<<endl;
} while(n>=&&isalpha(ch=getchar()));
//cout<<"^^^^^^"
printf("%d\n",ans);
}
2019.04.05
BZOJ 4236: JOIOJI map瞎搞的更多相关文章
- BZOJ 4236: JOIOJI MAP
4236: JOIOJI Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.ph ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- bzoj 4236: JOIOJI【前缀和+map】
设sj,so,si分别是J O I的个数前缀和,然后要求求最长(l,r)满足sj[r]-sj[l-1]==so[r]-so[l-1]==si[r]-si[l-1],化简一下就是满足so[r]-so[l ...
- BZOJ 4236 "JOIOJI"(前缀和+map+pair)
传送门: [1]:BZOJ [2]:洛谷 •题解 定义数组 a,b,c 分别表示 'J' , 'O' , 'I' 的前缀和: 要想使区间 (L,R] 满足条件当且仅当 a[R]-a[L] = b[R] ...
- BZOJ 4236 JOIOJI(前缀和)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4236 [题目大意] 给出一个只包含三种字母的字符串,求出三种字母数量相等的最长子串 [ ...
- BZOJ 4236: JOIOJI
Description 给出一个字符串,只包含3个字母,询问最长的一个子串,3个字母出现次数相同. Sol map. 如果一个子串满足条件,那么它端点处的三个字母的个数两两差值都是一样的,直接存个状态 ...
- bzoj 2456: mode【瞎搞】
这题加个#include都会MLE-- 神思路,每个数抵消宇哥和它不同的数,最后剩下的就是众数 #include<cstdio> int n,la,x,tot; int main() { ...
- BZOJ 4236~4247 题解
BZOJ 4236 JOIOJI f[i][0..2]表示前i个字符中′J′/′O′/′I′的个数 将二元组<f[i][0]−f[i][1],f[i][1]−f[i][2]>扔进map,记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
随机推荐
- SpringBoot_00_资源汇总贴
一.精选 1.Spring Boot文档 二.参考资料 1.springboot-learning-example 2.Spring boot 那些事 3.Spring Boot干货系列 4.Spri ...
- ActorModel 概念翻译
学习 skynet 时初次接触到 ActorModel 模型,始终觉得有必要从宏观上了解 ActorModel 的概念,所以以维基上这篇文章为参考,把文章中的部分内容翻译成中文,好让自己体会一下 Ac ...
- python+selenium自动化测试环境搭建
selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于不同的语 ...
- Dubbo配置设计
配置分类 配置格式 配置加载 可编程配置 配置缺省值 配置一致性 配置覆盖 配置继承 配置向后兼容 配置分类 首先,配置的用途是有多种的,大致可以分为: 环境配置,比如:连接数,超时等配置. 描述配置 ...
- SIP业务基本知识
1.SIP业务基本知识 1.1 业务介绍会话初始协议(Session Initiation Protocol)是一种信令协议,用于初始.管理和终止网络中的语音和视频会话,具体地说就是用来生成.修改和终 ...
- 【转】unittest执行测试用例的N种姿势总结
原文地址:https://www.cnblogs.com/fighter007/p/9514453.html 1.我们写几个方法,用来做测试用例 2.我们在另一文件中引用这个模块下面的所有类方法,先看 ...
- In-App Purchase Configuration Guide for iTunes Connect---(一)----Introduction
Introduction In-App Purchase is an Apple technology that allows your users to purchase content and s ...
- day6 面向对象(2)
static关键字 1:如果没有static会怎样? 1:定义Person类 1:姓名.年龄.国籍,说话行为 2:多个构造,重载形式体现 2:中国人的国籍都是确定的 1:国籍可以进行显示初始化 cla ...
- C# 写 LeetCode easy #1 Two Sum
1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...
- C++ - main()函数参数
main()函数及其参数说明 main()函数主要形式: int main(void) int main(int argc, char *argv[]) = int main(int argc, ch ...