オフラインどう書くE02・CodeIQ:◯はぴったり☓は無しの解答

オフラインどう書くのE02の問題と、同じ出題者の類題です。

E02の問題
問題はこちら->http://nabetani.sakura.ne.jp/hena/orde02pire/

Julia
62x62なので何とかなるかもと思いごく普通の方法で4重のfor loop(縦横の開始位置、終了位置)
を用いて解いてみました。（従って速くてループを書きやすいJuliaを使いました。）
しかし新しい長方形ごとに完全に数えなおしていてはさすがに時間がかかりすぎますので、
各行の既出の黒升の数をメモし、列が増えるごとにそれを更新しつつ
前の行までの合計(vsum)に加え新しいvsumとします。
始点が変わるたびにvsumをリセットします。


```Julia
#Julia v 1.4,1.5
str="0 	3:Oh,Be,AF,in,eG,ir,l5,Q8,mC,7T,Ty,tT 	108,1920
1 	3:00,zz,0z,z0 	-
2 	1:ho 	1,3844
3 	2:am 	-
4 	4:00,zz,0z,z0 	3844,3844
5 	4:00,11,zz,yy,1y,y1 	3600,3721
6 	2:00,01,10,11,yz,zy,yy,zz 	2,3660
7 	2:AA,AB,BA,BB,SZ,SY,TZ,TY 	2,2046
8 	3:Lw,qw,cw,Ow,2w,fw,yw,ow,Zw,iw 	7,2170
9 	4:0o,0s,0x,0C,0L,0k,0V,0y,0m,0S 	9,2852
10 	5:Tz,gz,Ez,Pz,3z,Jz,iz,Bz,ez,9z 	17,2604
11 	6:mQ,mp,mv,mW,mo,mZ,mC,mc,mt,mH 	23,3100
12 	5:a0,a4,aa,ac,ag,aB,aG,aK,aO,aY,az 	19,2480
13 	10:Ep,Jx,Qh,M7,Zr,lk,yp,Ya,aW,J3,OJ 	1938,3720
14 	5:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy 	3721,3721
15 	7:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy 	-
16 	8:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy,TE 	-
17 	11:bU,cl,d5,Fn,NW,gA,2O,YU,H4,0y,qE,Hd,ZH 	1748,3658
18 	12:SM,cf,AD,6P,cm,mo,if,s0,Mt,GJ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zx,fR,pe,w7,aj,U9,lO,kv,wL,s0 	396,2088
45 	10:JJ,LR,Xe,kg,LU,lI,3w,ZV,Td,Mu,tA,g8,VC,I7,N8,zN,kY,Ux,3t,mg,4m,FO,Ug,vQ,qY,jl,Ne,Zq,GN 	416,1794
46 	11:lQ,EN,vO,tn,qO,F3,9k,K2,UC,P0,XY,DB,QO,ps,hy,fl,Dt,ex,Vc,vF,Pf,Vk,uo,Xc,Sh,KE,9g,3H,l6 	658,1995 "

function solve(hena,n)
   memo=Array{Int}(undef,62)
   min=3844
   max=0
   for i in 1:62,j in 1:62
      fill!(memo,0)
       for i1 in i:62
           vsum=0
           for j1 in j:62
               memo[j1]=memo[j1]+hena[i1,j1]
               vsum=vsum+memo[j1]
               if vsum==n
                   ar=(i1-i+1)*(j1-j+1)
                   if min>ar
                       min=ar
                   elseif max<ar
                       max=ar
                   end
               elseif vsum>n
                   break
               end
           end
       end
   end
   return(min,max)
 end

function main()
    hena=Array{Int}(undef,62,62)
    str1=split(str,"\n")
    for s in str1
        fill!(hena,0)
        s1=split(s," ")
        s2=split(s1[2],":")
        s3=split(s2[2],",")
        for c in s3
            tmp=[]
            for i in 1:2
                cn=Int(c[i])
                if cn>96
                    push!(tmp,cn-60)
                elseif cn>64
                    push!(tmp,cn-54)
                else
                    push!(tmp,cn-47)
                end

            end
            hena[tmp[1],tmp[2]]=1
        end
        (min,max)=solve(hena,parse(Int,s2[1]))
        if max>0
            s=string(min)*","*string(max)
        else
            s="-"
        end
        if s==strip(s1[3])
            sel="pass"
        else
            sel="fail"
        end
        print(sel," ",s1[3]," ",s,"\n")
    end
end

@time main()

```
Prolog
Prologではすべての座標を調べると時間がかかりすぎますし、
一方黒点の数はそれほど多くありませんので、
縦横とも　始点・終点・黒点のある座標とその両側のみリストに入れ調べます。
それでも遅くて全問解くのに分単位かかります。
cum/5では結果的に縦横の累積和を求めています。ここはそれほど時間かかりません。
ここで矩形の(1,1):(m,n)（左上の座標:右下の座標）までの黒点の数を計算しておいて、
ju/7の部分で（直接にはcalc/6で）、黒点のかずf((a,b):(m,n))を
f((1,1):(m,n))-f((1,1):(a-1,n))-f((1,1):(m,b-1))+f((1,1):(a-1,b-1))
で求めています。
2021.7.3訂正
最大値を求めるのに黒点のある座標の上隣りは必要ありませんでした。

```Prolog
%SWI-Prolog v 7.42
%start.
%:-initialization(start).

twoar(_,0,_).      % two dimension array
twoar(F,X,Y):-arg(X,F,V),functor(V,y,Y),X1 is X-1,twoar(F,X1,Y).

data(_,X,Y,V):-(X=:=0;Y=:=0),!,V=0.
data(F,X,Y,V):-arg(X,F,C),arg(Y,C,V).

cum(_,M,N,R,F):-data(F,M,N,R),nonvar(R),!.
cum(L,1,1,R,F):-
     !,(member(1:1,L)->R=1;R=0),data(F,1,1,R).
cum(L,1,N,R,F):-
     !,(member(1:N,L)->V=1;V=0),N1 is N-1,cum(L,1,N1,R1,F),R is R1+V,data(F,1,N,R).
cum(L,M,1,R,F):-
     !,(member(M:1,L)->V=1;V=0),M1 is M-1,cum(L,M1,1,R1,F),R is R1+V,data(F,M,1,R).
cum(L,M,N,R,F):-
     (member(M:N,L)->V=1;V=0),M1 is M-1,N1 is N-1,cum(L,M1,N,R1,F),cum(L,M,N1,R2,F),
     cum(L,M1,N1,R3,F),R is R1+R2-R3+V,data(F,M,N,R).

calc(0,0,M2,N2,R,F):-
     !,data(F,M2,N2,R).
calc(0,N1,M2,N2,R,F):-
     !,data(F,M2,N1,R1),data(F,M2,N2,R3),R is R3-R1.
calc(M1,0,M2,N2,R,F):-
     !,data(F,M1,N2,R2),data(F,M2,N2,R3),R is R3-R2.
calc(M1,N1,M2,N2,R,F):-
     data(F,M1,N1,R0),data(F,M2,N1,R1),
     data(F,M1,N2,R2),data(F,M2,N2,R3),R is R3-R2-R1+R0.

ju([_],_,_,MN,MX,[MN,MX],_).
ju([H1|T1],L,N,MN,MX,R,F):-
     ju1(H1,T1,L,N,MN,MX,MN1,MX1,F),ju(T1,L,N,MN1,MX1,R,F).
ju1(_,[],_,_,MN,MX,MN,MX,_).
ju1(M1,[M2|T],L,N,MN,MX,MN1,MX1,F):-
     ju2(M1,M2,L,N,MN,MX,MN2,MX2,F),ju1(M1,T,L,N,MN2,MX2,MN1,MX1,F).
ju2(_,_,[_],_,MN,MX,MN,MX,_).
ju2(M1,M2,[N1|T],N,MN,MX,MN1,MX1,F):-
     ju3(M1,M2,N1,T,N,MN,MX,MN2,MX2,F),ju2(M1,M2,T,N,MN2,MX2,MN1,MX1,F).
ju3(_,_,_,[],_,MN,MX,MN,MX,_).
ju3(M1,M2,N1,[N2|T],N,MN,MX,MN1,MX1,F):-
     ju4(M1,M2,N1,N2,N,MN,MX,MN2,MX2,F),ju3(M1,M2,N1,T,N,MN2,MX2,MN1,MX1,F).
ju4(M1,M2,N1,N2,N,MN,MX,MN1,MX1,F):-
     calc(M1,N1,M2,N2,V,F),(V=:=N->judg(M1,N1,M2,N2,MN,MX,MN1,MX1);(MN1=MN,MX1=MX)).

judg(M,N,X,Y,MN,MX,MN1,MX1):-S is (X-M)*(Y-N),(S<MN->MN1=S;MN1=MN),(S>MX->MX1=S;MX1=MX).


ston(C,R):-C<65,!,R is C-47.
ston(C,R):-C<97,!,R is C-54.
ston(C,R):-R is C-60.

makel(L,X1:X2):-maplist(atom_codes,L,[N1,N2]),ston(N1,X1),ston(N2,X2).

/*2021.7.3訂正
add([],[],[]).
add([H|T],RX,RY):-add(T,RX1,RY1),H=ZX:ZY,RX2=[ZX|RX1],RY2=[ZY|RY1],
     X1 is ZX-1,(X1>1->RX3=[X1|RX2];RX3=RX2),X2 is ZX+1,(X2<62->RX=[X2|RX3];RX=RX3),
     Y1 is ZY-1,(Y1>1->RY3=[Y1|RY2];RY3=RY2),Y2 is ZY+1,(Y2<62->RY=[Y2|RY3];RY=RY3).
*/
add([],[],[]).
add([H|T],RX,RY):-add(T,RX1,RY1),H=ZX:ZY,RX2=[ZX|RX1],RY2=[ZY|RY1],
     X1 is ZX-1,(X1>1->RX=[X1|RX2];RX=RX2),
     Y1 is ZY-1,(Y1>1->RY=[Y1|RY2];RY=RY2).

solve(V,L,R):-
     functor(F,x,62),twoar(F,62,62),maplist(makel,L,L1),cum(L1,62,62,_,F),
     add(L1,LX,LY),LX1=[0,1|LX],LX2=[62|LX1],LY1=[0,1|LY],LY2=[62|LY1],
     sort(LX2,LX3),sort(LY2,LY3),ju(LX3,LY3,V,4000,0,R,F),!.

start:-
     str(S),split_string(S,"\n","",S1),pre(S1),!.

pre([]).
pre([S|T]):-
     split_string(S,"\s","\s",[_,B,Q]),atomics_to_string(L,",",B),L=[H|T1],
     concat_atom([X,Y],":",H),L1=[Y|T1],maplist(atom_chars,L1,L2),
     atom_number(X,V),solve(V,L2,R),disp(R,Q),pre(T).
     
disp(R,Q):-
     (R=[4000|_]->S="-";(maplist(number_string,R,L),atomics_to_string(L,",",S))),
     (S==Q->Str=" pass ";Str=" fail  "),write(Str),writeln(S).

str("0  3:Oh,Be,AF,in,eG,ir,l5,Q8,mC,7T,Ty,tT   108,1920
1       3:00,zz,0z,z0   -
2       1:ho    1,3844
3       2:am    -
4       4:00,zz,0z,z0   3844,3844
5       4:00,11,zz,yy,1y,y1     3600,3721
6       2:00,01,10,11,yz,zy,yy,zz       2,3660
7       2:AA,AB,BA,BB,SZ,SY,TZ,TY       2,2046
8       3:Lw,qw,cw,Ow,2w,fw,yw,ow,Zw,iw         7,2170
9       4:0o,0s,0x,0C,0L,0k,0V,0y,0m,0S         9,2852
10      5:Tz,gz,Ez,Pz,3z,Jz,iz,Bz,ez,9z         17,2604
11      6:mQ,mp,mv,mW,mo,mZ,mC,mc,mt,mH         23,3100
12      5:a0,a4,aa,ac,ag,aB,aG,aK,aO,aY,az      19,2480
13      10:Ep,Jx,Qh,M7,Zr,lk,yp,Ya,aW,J3,OJ     1938,3720
14      5:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy   3721,3721
15      7:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy   -
16      8:00,01,10,0y,0z,1z,y0,z0,z1,yz,zz,zy,TE        -
17      11:bU,cl,d5,Fn,NW,gA,2O,YU,H4,0y,qE,Hd,ZH       1748,3658
18      12:SM,cf,AD,6P,cm,mo,if,s0,Mt,GJ,9m,Sp,lA,x4,NE         1806,3186
19      2:00,I0,c0,z0,0I,II,cI,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       19,2520
20      3:00,I0,c0,z0,0I,II,cI,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       39,2562
21      5:00,I0,c0,z0,0I,II,cI,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       -
22      6:00,I0,c0,z0,0I,II,cI,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       741,3660
23      7:00,I0,c0,z0,0I,II,cI,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       -
24      7:00,I0,c0,z0,0I,II,cJ,zI,0c,Ic,cc,zc,0z,Iz,cz,zz       1178,2623
25      13:Lk,y3,uO,Gk,sF,7y,ED,FP,rK,vw,Lo,kT,ib,MR,sC,Cu,xQ   1794,3472
26      1:lz,en,81,M2,M1,8p,7m,ND,m0,gd,3v,hr,hA,Yr,XB,x2,AR,5Q,3V,B3   1,1785
27      2:s1,Dx,yu,H8,c4,6C,95,FK,xV,Q7,h2,Wk,BI,i0,bl,9Q,KF,1q,52,PS,Jh        6,1824
28      2:0R,20,fz,0a,0X,zp,P0,0b,0S,zw,e0,0G,g0,06,a0,Zz,zW,zn,00,z6,zq,U0     2,3660
29      3:H5,jF,AT,HH,k7,Ho,Mz,07,Tt,Sq,Zh,Yt,e5,oS,qf,YY,JD,bP,s4,hB,TC,PW     28,1224
30      4:oe,pg,Np,zP,ho,pe,OV,S0,oM,wO,pM,Ah,Vq,9d,6U,3I,C9,AR,1L,rg,69,as,Nx  12,1989
31      2:n0,V0,zL,i0,4z,Nz,xz,z0,z1,0f,P0,zw,80,zC,zB,Az,0P,50,k0,rz,0D,jz,qz,E0       2,2928
32      2:tz,0F,0y,zo,0K,01,qz,zU,gz,Xz,zc,0m,zD,Q0,Yz,zb,0a,zp,zW,z7,0o,h0,1z,0p       2,3660
33      5:8r,NI,gL,3z,EK,hy,L9,g2,Kh,Gw,Dg,ZB,Sg,LY,ig,sS,I8,U0,DI,cq,Bu,qJ,C4,jP       143,1520
34      2:7s,z7,so,zw,X2,59,r1,0Q,70,q2,C6,J6,wz,at,2w,Vq,f9,st,sI,rf,wG,zg,f3,L2,4j    4,2340
35      2:kw,Gz,zp,se,8e,2S,C7,1A,B9,5v,AM,sN,zH,m8,Cx,rG,4w,q2,W0,ta,AC,G5,y0,Vq,3i    4,2080
36      3:Lr,pX,y7,2Y,qI,6w,t5,R6,e8,57,5f,R1,Up,9q,33,1Z,05,Eu,6S,AW,au,7S,zd,CA,R7    7,2120
37      3:ut,0C,6p,5w,9M,uj,I6,sq,Yr,Tz,Bp,p7,Rt,JB,6O,Bw,T1,tY,pn,MA,7I,GC,BO,m0,ts    12,2016
38      4:sE,Wy,Oo,uY,4t,os,B1,xq,4j,ex,s7,y7,54,ud,Cj,0L,S7,fx,11,cs,zc,tn,S6,Zq,2r    56,2400
39      6:eZ,5V,xT,2x,W7,vy,yT,8R,XT,4c,yX,s9,3E,KZ,tp,Sj,Su,wp,4F,BV,aC,qw,cJ,Gl,aA    192,1849
40      7:6Q,av,UZ,0c,IV,fo,Vv,mg,no,qM,06,zy,jW,R0,Qo,sK,wQ,1b,De,Iy,zI,cx,rn,ot,cN,45         250,2303
41      4:0A,15,5k,Bi,mz,0f,vr,EZ,4z,vj,6p,vP,8X,16,x7,S3,2z,zJ,wI,wY,Wv,ky,9K,8u,Eo,4s,y0      48,2700
42      8:zN,2J,ta,HL,Dg,up,Qn,W8,8K,k4,Is,uL,dT,tA,PN,UQ,DB,gA,OO,lv,4h,Rv,D6,23,Tg,4S,Zb      418,1763
43      5:px,sp,cr,dB,fz,65,gq,zb,sN,42,o0,y3,iE,pv,sn,Al,RE,48,l0,7X,DE,xL,wC,qQ,w5,C3,P3,i1   102,2397
44      9:Ic,Dk,Ef,6R,GK,NZ,76,L0,oQ,9f,S3,oL,lX,7v,8d,pX,dZ,z7,zx,fR,pe,w7,aj,U9,lO,kv,wL,s0   396,2088
45      10:JJ,LR,Xe,kg,LU,lI,3w,ZV,Td,Mu,tA,g8,VC,I7,N8,zN,kY,Ux,3t,mg,4m,FO,Ug,vQ,qY,jl,Ne,Zq,GN       416,1794
46      11:lQ,EN,vO,tn,qO,F3,9k,K2,UC,P0,XY,DB,QO,ps,hy,fl,Dt,ex,Vc,vF,Pf,Vk,uo,Xc,Sh,KE,9g,3H,l6      658,1995").
```
CodeIQ61:◯はぴったり☓は無し

問題とテストケースはこちらのお世話になりました（解答もあります）。
https://blog.goo.ne.jp/r-de-r/e/487149841278c89bbff90a717866cd33

Juliaです。
〇の場合と☓の場合に分けて列ごとの累積和をとって配列henaに入れています。

```Julia
#Julia v 1.1.0,1.4.1,1.5.3

str="1 Bb Ab,Ba,Cb,Bc 1
   5 Oh,Be,Af,In,Eg,Rl Aa 650
   2 Ky,Zd,Yi,Av,Tk,Lz,Jk,Vx,Ga,Um,Ho Yr,Wc,Cb,Tf,Io,Bk,Yh,Yl,Bp,Qf,Ur 198
   1 Le,Dq,Qa,Qs,Sl,Xa,Nf,Qb,Ur,Sc,Ei,Mq Kw,Qe,Rv,Ry,Ih,Aq,Jb,Px,Yx,Lu,Kq,Qm 154
   3 Bl,Aq,Vl,Iu,Iy,Om,Te,Js,Fu,Xj,Kr,Ja,Nm He,Ki,Yu,Mr,Ua,Vw,Ha,Xy,Bv,Tp,Lw,Jr,Th 147
   0 Zy,Ze,Va,Yn,Hb,Cv,Co,Kh,Ml,Wh,Zr,Vh,Mm,Vj Hc,Pw,Ne,Iu,Jt,If,Wm,Dy,Uc,Lx,Xs,Sa,Hv,Ao 136
   2 Dn,Ve,Cf,Rh,Jg,Na,Bh,Ad,Xz,To,Fw,Ml,Bp,Vd,Go Py,Ol,Px,Qc,Bg,Ss,Vm,Xr,Eh,Kz,Dr,Kc,Tb,Vu,Ov 154
   4 Mg,Qb,Ae,Wo,Fg,Ke,Zx,Na,Us,Ky,Zm,Mi,Ls,Py,Ye,Ya Ux,Kj,Fo,Jw,Ug,Mt,Aw,Tb,El,Oo,Rv,Ri,Zd,Am,Bu,Il 126
   3 Ti,Oq,Wy,Dz,Xb,Ys,Mk,Ym,Ae,Ii,Wu,Ol,Ta,Mm,Eq,Vs,Cg Sa,Ub,Vf,Wv,Zf,No,Up,Zo,Ws,Bb,Uy,Yn,Xv,Yh,Ob,Zu,Gt 190
   1 Tv,Sg,Js,Lb,Mu,Sz,Za,Pl,It,Bs,Cl,Bf,Ik,Du,Te,Gc,Ge,Ub Kh,Mb,La,Dz,Wa,Jg,Ra,Ca,Rm,Yo,Um,Uz,Lo,Zn,We,Bb,Vv,Gw 104
   2 Pn,We,Au,Wz,Nc,Jr,Rr,Og,Yd,Sk,Zn,Fj,Ds,Nw,Rd,Sj,Zm,Ll,Mt Dx,Bt,Xo,Tg,Iv,Kp,Oa,Av,Ve,Yx,Nb,Ku,Vr,Wl,Gr,Gf,Md,Sd,Uy 126
   9 Lv,Nd,Jw,Ps,Br,Dg,Vq,Xs,Pj,Nw,Mn,Ce,Te,Ss,Mv,Tu,Rk,Xb Eo,Gg,Nz,Mo,Wp,Pk,Jn,Os,No,Ey,Vz,Uf,Xk,Pd,Iy,Lo,Zd,Pg,Gl,Nx -"

function solve(hena,n)
   max=0
   for i in 1:26,j in 1:26
       for j1 in j:26
           osum = 0
           xsum = 0
           for i1 in i:26
               osum +=hena[i1,j1,1]
               xsum +=hena[i1,j1,2]
               if j>1
                   osum-=hena[i1,j-1,1]
                   xsum-=hena[i1,j-1,2]
               end
               if xsum>0 break end
               if osum==n
                   ar=(i1-i+1)*(j1-j+1)
                   if max<ar
                       max=ar
                   end
               elseif osum>n
                   break
               end
           end
       end
   end
   return max
 end

function main()
    function make(s2,hena,k)
        for c in s2
            tmp=[]
            for i in 1:2
                cn=Int(c[i])
                if cn>96
                    push!(tmp,cn-96)
                elseif cn>64
                    push!(tmp,cn-64)
                end
            end
            hena[tmp[1],tmp[2],k]=1
        end
    end
    str1=split(str,"\n")
    for s in str1
        hena=zeros(Int,26,26,2)
        s1=split(strip(s)," ")
        make(split(s1[2],","),hena,1)
        make(split(s1[3],","),hena,2)
        for i in 1:26,j in 2:26
            hena[i,j,1]=hena[i,j,1]+hena[i,j-1,1]
            hena[i,j,2]=hena[i,j,2]+hena[i,j-1,2]
        end
        max=solve(hena,parse(Int,s1[1]))
        if max>0
            s=string(max)
        else
            s="-"
        end
        if s==strip(s1[4])
            sel="pass"
        else
            sel="fail"
        end
        print(sel," ",s1[4]," ",s,"\n")
    end
end
main()
```