Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program skobki;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type
- pr = record
- b, e: integer;
- end;
- var
- a: array [1..500005] of pr;
- b: array [1..500005] of integer;
- i, r, t, n, k: integer;
- f: pr;
- s: string;
- function skob(j: integer): integer;
- var
- f : integer;
- begin
- f := 1;
- inc(j);
- while (f <> 0) and (j <= length(s)) do
- begin
- if (s[j] = '(') then inc(f)
- else dec(f);
- inc(j);
- end;
- if (f = 0) then skob := j - 1
- else skob := 0;
- end;
- begin
- readln(s);
- n := -1;
- i := 1;
- r := 0;
- k := 0;
- while (i <= length(s)) do
- if (s[i] = ')') or (skob(i) = 0) then inc(i)
- else
- begin
- inc(r);
- a[r].b := i;
- a[r].e := skob(i);
- i := a[r].e + 1;
- end;
- if(r <> 0) then f := a[1];
- t := 1;
- for i := 2 to r do
- if (f.e = a[i].b - 1) then f.e := a[i].e
- else
- begin
- b[t] := f.e - f.b + 1;
- f := a[i];
- inc(t);
- end;
- if (r <> 0) then b[t] := f.e - f.b + 1;
- for i := 1 to t do
- if (n = b[i]) then inc(k)
- else if (n < b[i]) then
- begin
- n := b[i];
- k := 1;
- end;
- if (n = -1) then writeln('0 1')
- else writeln(n, ' ', k);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement