【BZOJ 4236】JOIOJI

相关链接

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4236
神犇题解:http://www.cnblogs.com/qscqesze/p/4775481.html

解题报告

如果字符集大小只有2的话,那一个搞成1另一个搞成-1就好啦!
但这题字符集大小为3,于是我们从数组拓展到三维坐标系就好啦!
然后搞一个map什么的装一装,时间复杂度:$O(nlogn)$

Code

#include<bits/stdc++.h>
#define LL long long
using namespace std;

int n,vout;
map<pair<int,int>, int> m;

inline int read() {
	char c=getchar(); 
	while (c!='J'&&c!='O'&&c!='I') c=getchar();
	if (c == 'J') return 1;
	else if (c == 'O') return 2;
	else return 3;
}

int main() {
	cin>>n;
	pair<int,int> cur(0,0);
	for (int i=1,w;i<=n;i++) {
		w = read();
		if (w == 1) cur.first++;
		else if (w == 2) cur.second++;
		else cur.first--, cur.second--;
		if (m[cur]) vout = max(vout, i - m[cur]);
		else m[cur] = i;
		if (!cur.first && !cur.second) vout = max(vout, i);
	}
	cout<<vout<<endl;
	return 0;
}

13 thoughts to “【BZOJ 4236】JOIOJI”

  1. Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. It extremely helps make reading your blog significantly easier.

  2. 109328 74185Aw, this was a extremely good post. In thought I want to put in writing like this moreover ?taking time and actual effort to make a really excellent post?even so what can I say?I procrastinate alot and definitely not appear to get 1 thing done. 109099

  3. 614608 549322I want to thank you for the superb post!! I undoubtedly liked every bit of it. Ive bookmarked your web site so I can take a look at the latest articles you post later on. 101696

  4. 194070 822672Wow, superb weblog layout! How long have you been blogging for? you make blogging appear easy. The overall appear of your web site is magnificent, as well as the content material! xrumer 743387

  5. 641746 109102Someone essentially assist to make severely posts I might state. That will be the extremely very first time I frequented your web site page and so far? I surprised with the analysis you produced to create this particular submit incredible. Magnificent task! 244374

  6. 484426 523683Greetings! Quick question thats completely off subject. Do you know how to make your internet site mobile friendly? My weblog looks weird when viewing from my iphone. Im trying to uncover a template or plugin that may be able to fix this dilemma. In case you have any recommendations, please share. Appreciate it! 331893

Leave a Reply to www.bobsseo.net Cancel reply

Your email address will not be published. Required fields are marked *