Thứ Ba, 3 tháng 5, 2022

PARITY PASCAL

var a,s:array[0..200000] of longint;
    d:array[-200000..200000] of longint;
    n:longint;

procedure doc_va_dem;
var i:longint;
begin
    readln(n);
    s[0]:=0;d[0]:=1;
    For i:=1 to n do
    begin
        read(a[i]);
        if a[i] mod 2=0 then s[i]:=s[i-1]+1
        else
            s[i]:=s[i-1]-1;
        inc(d[s[i]]);
    end;
end;

procedure giai;
var res,i:longint;
begin
    res:=0;
    for i:=0 to n do
        res:=res+d[s[i]]-1;
    writeln(res div 2);
end;

BEGIN
    assign(input,'PARITY.INP');reset(input);
    assign(output,'PARITY.out');rewrite(output);
    doc_va_dem;
    giai;
END.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.