相关链接
题目传送门: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; }
You have brought up a very fantastic points, thanks for the post.
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.
317229 421696Yay google is my world beater aided me to discover this outstanding internet site ! . 722451
342117 859519bmmzyfixtirh cheapest phentermine zero health professional prescribed qrdzoumve buy phentermine diet pill iixqnjouukkebr 309480
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
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
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
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
45342 191511Hi my friend! I want to say that this post is awesome, good written and incorporate almost all significant infos. Id like to see far more posts like this . 247499
385513 8237Thanks – Enjoyed this post, can you make it so I receive an e-mail when you make a fresh post? From Online Shopping Greek 78194
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
242782 815174U never get what u expect u only get what u inspect 670357
77958 662820Hosting a weblog composing facility (in a broad sense) requires unlimited space. So I suggest you to discover such web hosting (internet space provider) that supply flexibility inside your internet space. 86480