Chef and Sign Sequences


Chef found a strange string yesterday – a string of signs $s$, where each sign is either a ‘<‘, ‘=’ or a ‘>’. Let $N$ be the length of this string. Chef wants to insert $N+1$ positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign ‘<‘ is preceded by the integer $a$ and followed by an integer $b$, then $a$ should be less than $b$. Likewise for the other two signs as well.
Chef can take some positive integers in the range $[1, P]$ and use a number in the range as many times as he wants.
Help Chef find the minimum possible $P$ with which he can create a valid sequence.


数据范围:$1 \le |s| \le 10^5$。






#include <iostream>
#include <algorithm>
using namespace std;
int n, ans, len, out;
string s;
int main()
  cin >> n;
  while (n--) {
    cin >> s;
    ans = out = 0;
    len = s.length();
    for (int i = 0; i < len; ++i) {
      if (s[i] == '<') {
        if (ans < 0) ans = 0;
      if (s[i] == '>') {
        if (ans > 0) ans = 0;
      out = max(out, abs(ans) + 1);
    cout << out << endl;
  return 0;

RegMs If

418 I'm a teapot

Leave a Reply

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