2095. 多折较差验证/Fold

临海听潮意,入林闻籁鸣。这是一座依山傍水、宁静祥和的小镇,在这里人们很少担心自己家里的物品故障损坏,因为 Kanan 总能帮大家修好。Kanan 是这片地区首屈一指的机械师;虽然她还年轻,但是娴熟的技艺加上慷慨的性格使得她平时总会收到人们的修理委托,据说就连那位遗世独立的魔王遇到了问题都得求助她。在帮人修理时, Kanan 会接触到千奇百怪的使用说明书。其中一些说明书有着不可思议的折叠结构,Kanan 为了理解机械的构造会在修理之前展开说明书,可在修好之后按照原来的折痕折回原状却比修理本身更费劲。

对于所有折痕互相平行的说明书,可以按照说明书上文字的阅读顺序从上到下给每条折痕分别编号 1, 2, \cdots, N,这 N 条折痕将说明书分成了 (N+1) 条纸带。每条折痕可能为两种形态之一:一种是垂直纸面向内凸出,对应将纸的上下两半向前对折;一种是垂直纸面向外凸出,对应将上下两半向后对折。根据折痕截面的形状,分别使用小写字母 v 表示向内凸出的折痕,^ (ASCII 码为 94)表示向外凸出的折痕。假设所有纸带的宽度都是一样的,并且折纸的过程中说明书不发生形变,那么沿着一条折痕对折后两侧的纸能够重合,当且仅当两侧的折痕是相反的;即,如果沿着第 k 条折痕折叠,那么对于所有满足 1\le k-m 的正整数 m,第 (k-m) 条折痕和第 (k+m) 条折痕的形态是相反的。例如,对于折痕依次为 v^v^^^^v 的说明书,可以沿其第 7 条折痕进行折叠。根据定义可知,一张说明书总能沿着第一条或最后一条折痕进行折叠。折叠之后的说明书可以用被折叠的折痕两侧中,剩余折痕数量较多一侧的折痕表示,如 v^v^^^^v 沿着第 7 条折痕折叠后得到 v^v^^^。如果被折叠的折痕两侧折痕数量相等,那么用哪一侧的折痕表示折叠后的纸都可以,因为折痕在三维空间中是旋转对称的。特别地,对只剩下一条折痕的说明书,即 v^ 进行折叠后,所有 (N+1) 条纸带都重叠在一起,此时称这张说明书被折叠整齐。

虽然按顺序依次折叠每一条折痕,总能将说明书折叠整齐,但 Kanan 觉得这样并不美观。一种美观的折法应该尽量少折,并且每次折的时候折痕两侧应该尽可能的对称。定义一种折法的不对称程度为每次折叠时,被折叠的折痕两侧的折痕数量之差的总和。给出一张说明书的折痕,Kanan 想知道最少需要折多少次才能将这张说明书折叠整齐,以及所有折叠次数最少的折法中,不对称程度的最小值。

The sea and the tides, the forest and the music. A quiet, peaceful town surrounded by mountains and water, where people rarely have to worry about what's broken in their homes because Kanan, the region's premier mechanic, is still young, but her skill and generosity of character have led to her receiving requests for repairs, and it's rumored that even the Demon King turns to her when he encounters a problem. When helping people with their repairs, Kanan comes into contact with a myriad of manuals. Some of these manuals have a strange folding structure, and Kanan unfolds them before repairing them in order to understand the structure of the machine, but folding them back to the original folds after repairing them is even more difficult than repairing the machine itself.

For a manual with all the folds parallel to each other, each fold can be numbered 1, 2, \cdots, N in the order in which the text on the manual is to be read, from top to bottom, and these N folds divide the manual into (N+1) strips of paper. Each crease may take one of two forms: either a vertical paper face protrudes inward, corresponding to folding the top and bottom halves of the paper forward, or a vertical paper face protrudes outward, corresponding to folding the top and bottom halves backward. Depending on the shape of the crease cross-section, lowercase v is used to denote inwardly projecting creases, and ^ (ASCII code 94) is used to denote outwardly projecting creases, respectively. Assuming that all paper strips are of the same width, and that the instructions do not deform during the folding process, then the two sides of the paper can overlap after folding along a crease if and only if the two sides are opposite; that is, if the paper is folded along the kth crease, then for all positive integers m that satisfy the requirement that 1\le k-m < k+m\le N, the (k-m)th crease and the ( k+m) creases are of opposite shape. For example, an instruction manual with creases v^v^^^^v in order can be folded along its 7th crease. By definition, an instruction sheet can always be folded along the first or last crease. The folded instruction manual can be represented by the crease on the side of the folded crease that has the greater number of remaining creases, e.g., v^v^^^^v is folded along the 7th crease to obtain v^v^^^. If there are an equal number of creases on both sides of the folded crease, then it is fine to represent the folded paper by the creases on either side, since the creases are rotationally symmetric in three-dimensional space. In particular, after folding an instruction sheet with only one crease remaining, i.e., v or ^, all (N+1) strips of paper overlap, and the sheet is then said to be neatly folded.

Although folding each crease in sequence always results in a neat fold, Kanan feels that this is not aesthetically pleasing. An aesthetically pleasing fold should be made as few times as possible, and each fold should be as symmetrical as possible on both sides of the crease. Define the degree of asymmetry of a fold as the sum of the differences in the number of creases on either side of the folded crease each time it is folded. Given the folds of an instruction booklet, Kanan wants to know the minimum number of folds needed to fold the booklet neatly, and the minimum amount of asymmetry among all the folds with the fewest number of folds.

输入

输入的第一行包含一个正整数 N,表示折痕的条数。保证 1\le N\le 5000

输入的第二行包含一个字符串 s,按顺序表示每条折痕。保证 |s|=N,且 s 仅由 v^ 组成。

The first line of the input contains a positive integer N indicating the number of bars in the crease. It's guaranteed 1\le N\le 5000.

The second line of the input contains a string s representing each crease in order. It is guaranteed that |s|=N and that s consists only of v and ^.

输出

输出仅一行,包括两个非负整数,分别表示最少的折叠次数和最小化折叠次数的前提下的最小不对称程度,两个数之间用一个空格隔开。

The output is one line only and consists of two non-negative integers representing the minimum number of folds and the minimum degree of asymmetry subject to minimizing the number of folds, separated by a space.

样例

标准输入 复制文本
3
^vv
标准输出 复制文本
2 0
标准输入 复制文本
8
v^v^^^^v
标准输出 复制文本
6 15
标准输入 复制文本
40
v^vv^v^^v^^vvvv^v^^v^^^vv^^vvvv^v^^v^^^v
标准输出 复制文本
14 201

提示

如果先沿着中间的折痕对折,那么两侧的纸恰好重合,此时再对折一次即可将说明书折叠整齐。

对于所有数据,保证 1\le N\le 5000|s|=Ns 仅由 v^ 组成。

If you first fold along the center crease, then the two sides of the paper coincide, at which point you can fold the instructions neatly by folding once more.

For all data, it is guaranteed that 1\le N\le 5000, |s|=N and s consists only of v and ^.

登录以提交代码。
单点时限 3 秒
内存限制 512 MB
提交 3
通过 2