请教更优写法。
  • 板块题目总版
  • 楼主Ufowoqqqo
  • 当前回复6
  • 已保存回复6
  • 发布时间2015/4/1 19:34
  • 上次更新2023/10/22 10:19:01
查看原帖
请教更优写法。
2699
Ufowoqqqo楼主2015/4/1 19:34

题目是T311,本人的代码只有50分,其他的点都TLE了。求大神帮优化。

[codep]

var
        a, t, tt:array [0..100000] of integer;
        i, j:longint;
        ch:char;
begin
        repeat
                read(ch);
                inc(a[0]);
                a[a[0]] := ord(ch) - 48
        until eoln;
        t := a;
        for i := 1 to a[0] do
                a[i] := t[a[0] - i + 1];
        t := a;
        inc(a[1]);
        i := 1;
        while a[i] >= 10 do
        begin
                dec(a[i + 1], 10);
                inc(a[i + 2]);
                inc(i)
        end;
        if i > a[0] then
                a[0] := i;
        for i := 1 to a[0] do
                for j := 1 to t[0] do
                begin
                        inc(tt[i + j - 1], a[i] * t[j]);
                        if tt[i + j -1] >= 10 then
                        begin
                                inc(tt[i + j], tt[i + j - 1] div 10);
                                tt[i + j - 1] := tt[i + j - 1] mod 10
                        end
                end;
        tt[0] := a[0] + t[0];
        while tt[tt[0]] = 0 do
                dec(tt[0]);
        fillchar(t, sizeof(t), 0);
        for i := 1 to tt[0] do
        begin
                inc(t[i], tt[i] * 5);
                if t[i] >= 10 then
                        begin
                                inc(t[i + 1],t[i] div 10);
                                t[i] := t[i] mod 10
                        end
        end;
        if t[tt[0] + 1] > 0 then
                t[0] := tt[0] + 1
        else
                t[0] := tt[0];
        for i := t[0] downto 2 do
                write(t[i])
end.
[/codep]
2015/4/1 19:34
加载中...