Codeforces Beta Round #98 (Div. 2) E
说实话这次cf应该是我做过的最简单的一场。虽然每次都是div2:-(
比赛的时候d明显有一个O(n^3)的算法,但是不敢写,500的立方应该不算小吧。后面题解直接说了就是这样。崩溃。
e我一直在YY线性的算法,但是没想出来。后面证明不存在。反正后面一个多小时什么也没弄出来。2b了。
e我把它转换成了求最长和>=0的子序列。因为受最大字段和的干扰,所以一直以为有限性的算法。。。nlogn的算法就是一个二分。标程说就是这样,你能咋地。撞墙。
其实昨天二分比赛的时候我已经写出来了,但是有点小错误。而且也是最后一分钟写完的没交上。rating降了不少,好遗憾。
突然发现用二分搜索第一个大于等于某一个值的位置都不会写了,本来会的不多的东西全忘干净了。
/* ID: like_091 PROG: fence LANG: C++ */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <cmath> #include <ctime> #include <set> #include <map> #include <stack> #include <queue> #include <string> #include <bitset> #include <vector> #include <deque> #include <utility> #include <list> #include <sstream> #include <iostream> #include <functional> #include <fstream> #include <numeric> #include <algorithm> using namespace std; //TEMPLATE_BY_LIKE #define EP 1E-10 #define CLR(arr, v) memset(arr, v, sizeof(arr)) #define SQ(a) ((a)*(a)) #define DEBUG(a) printf("%s = %s\n", #a, toStr(a).c_str()) #define FOR(i,s,e) for( int (i)=(s); (i) < (e) ; i++) #define SIZE(X) ((int)(X.size())) #define LENGTH(X) ((int)(X.length())) #define two(X) (1<<(X)) #define twoL(X) (((int64)(1))<<(X)) typedef long long ll; typedef unsigned long long ull; const double PI = acos(-1.0); int toInt(string s) {int r=0; istringstream sin(s); sin>>r; return r;} ll toInt64(string s) {ll r=0; istringstream sin(s); sin>>r; return r;} double toDouble(string s){double r=0; istringstream sin(s); sin>>r; return r;} double dist(double x1, double y1, double x2, double y2){return sqrt(SQ(x1-x2)+SQ(y1-y2));} bool isUpperCase(char c){return c >= 'A' && c <= 'Z';} bool isLowerCase(char c){return c >= 'a' && c <= 'z';} bool isLetter(char c) {return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z';} bool isDigit(char c) {return c >= '0' && c <= '9';} char toLowerCase(char c){return (isUpperCase(c))?(c + 32) : c;} char toUpperCase(char c){return (isLowerCase(c))?(c - 32) : c;} template<class T> inline T strTo(string s){istringstream is(s);T v;is>>v;return v;} template<class T> inline string toStr(const T& v){ostringstream os;os<<v;return os.str();} template<class T> inline int cMin(T& a, const T& b){return b<a?a=b,1:0;} template<class T> inline int cMax(T& a, const T& b){return a<b?a=b,1:0;} template<class T> inline int cBit(T n){return n?cBit(n&(n-1))+1:0;} template<class T> inline T lowbit(T n){return (n^(n-1))&n;} template<class T> inline T GCD(T a, T b) {if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);} template<class T> inline T LCM(T a, T b) {if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));} //TEMPLATE_BY_LIKE char s[200005]; bool is_ok(char c){ if (c == 'a' || c == 'A' || c == 'o' || c == 'O' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'u' || c =='U') return true; return false; } int a[200005]; struct node{ int sum; int i; }d[200005]; bool cmp(node a, node b){ if (a.sum == b.sum) return a.i < b.i; return a.sum < b.sum; } int sum[200005]; int search(int i, int j, int v){ int mid, ans = j; while (i <= j){ mid = (i + j) / 2; if (d[mid].sum <= v) j = mid - 1; else i = mid + 1; } return d[i].i; } int main(){ scanf("%s", s); int len = strlen(s); int k = 0; for (int i = 0; i < len; i++){ if (is_ok(s[i]))a[i] = -1; else a[i] = 2; if (i == 0)sum[i] = a[i]; else sum[i] = a[i] + sum[i - 1]; if (i == 0){ d[k].sum = sum[i]; d[k].i = 0; } else if (sum[i] < d[k].sum){ d[++k].sum = sum[i]; d[k].i = i; } } int maxf = 0; int l = 0; for (int i = 0; i < len; i++){ int temp; if (sum[i] >= 0){ temp = i + 1; }else { temp = i- search(0, k, sum[i]); } if (temp > maxf){ maxf = temp; l = 1; } else if (temp == maxf){ l++; } } if (maxf == 0){ cout << "No solution" << endl; } else cout << maxf << " " << l << endl; return 0; }