program solitario; (*con procedura ricorsiva*)
var N,M, soluzione:longint;
griglia:array[0..10,0..10] of longint;
function gioca(r, c: longint): boolean;
begin
(*tris orizzontale*)
if (c-2>=0) and (griglia[r][c-2]=1) and (griglia[r][c-1]=1) then gioca:=false
(*tris verticale*)
else if (r-2>=0) and (griglia[r-2][c]=1) and (griglia[r-1][c]=1) then gioca:=false
(* Tris diagonale in alto a sx*)
else if (r-2>=0 ) and (c-2>=0) and (griglia[r-2][c-2]=1) and (griglia[r-1][c-1]=1) then gioca:=false
(* Tris diagonale in alto a dx*)
else if (r-2>=0) and (c+2<=M) and (griglia[r-2][c+2]=1) and (griglia[r-1][c+1]=1) then gioca:=false
else gioca := true;
end;
Procedure riempi (riga:longint; colonna:longint; tot:longint);
begin
if colonna=M then begin riga:=riga+1; colonna:=0; end;
if riga=N then begin if tot>soluzione then soluzione:=tot; exit end;
(*Se posso, metto la X*)
if gioca (riga,colonna)=true then
begin
griglia[riga][colonna]:=1;
Riempi(riga,colonna+1, tot+1);
(* Reset della griglia[riga][col]*)
griglia[riga][colonna]:=0;
end;
if (tot+((M*N-(riga*M + colonna +1))))<soluzione then exit; (*condizione per uscire dalla procedura ricorsiva ed evitare di andare in TLE quando N*M>30;
se le x di questa soluzione + i 2/3 delle caselle libere < il totale che ho già trovato in un' altra soluzione esco perchè non ha senso continuare*)
(* Non metto la X*)
Riempi(riga,colonna+1, tot);
end;
begin
readln(N,M);
soluzione:=0;
riempi(0,0,0);
writeln(soluzione);
end.
cHJvZ3JhbSBzb2xpdGFyaW87ICgqY29uIHByb2NlZHVyYSByaWNvcnNpdmEqKQp2YXIgTixNLCBzb2x1emlvbmU6bG9uZ2ludDsKICAgIGdyaWdsaWE6YXJyYXlbMC4uMTAsMC4uMTBdIG9mIGxvbmdpbnQ7CiAgICAKZnVuY3Rpb24gZ2lvY2EociwgYzogbG9uZ2ludCk6IGJvb2xlYW47CmJlZ2luCiAgICAgICgqdHJpcyBvcml6em9udGFsZSopCiAgIGlmIChjL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AgICAgICAgYmVnaW4gCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBncmlnbGlhW3JpZ2FdW2NvbG9ubmFdOj0xOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUmllbXBpKHJpZ2EsY29sb25uYSsxLCB0b3QrMSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgqIFJlc2V0IGRlbGxhIGdyaWdsaWFbcmlnYV1bY29sXSopCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBncmlnbGlhW3JpZ2FdW2NvbG9ubmFdOj0wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbmQ7CiAgICAgaWYgKHRvdCsoKE0qTi0ocmlnYSpNICsgY29sb25uYSArMSkpKSk8c29sdXppb25lICB0aGVuIGV4aXQ7ICgqY29uZGl6aW9uZSBwZXIgdXNjaXJlIGRhbGxhICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJvY2VkdXJhIHJpY29yc2l2YSBlZCBldml0YXJlIGRpIGFuZGFyZSBpbiBUTEUgcXVhbmRvIE4qTT4zMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2UgbGUgeCBkaSBxdWVzdGEgc29sdXppb25lICsgaSAyLzMgZGVsbGUgY2FzZWxsZSBsaWJlcmUgPCBpbCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b3RhbGUgY2hlIGhvIGdpw6AgdHJvdmF0byBpbiB1bicgYWx0cmEgc29sdXppb25lIGVzY28gcGVyY2jDqCBub24gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoYSBzZW5zbyBjb250aW51YXJlKikKICAgICAgICgqIE5vbiBtZXR0byBsYSBYKikKICAgIFJpZW1waShyaWdhLGNvbG9ubmErMSwgdG90KTsKZW5kOyAgICAgICAgICAgICAgICAgICAKYmVnaW4KCXJlYWRsbihOLE0pOwoJc29sdXppb25lOj0wOwogICAgICAgIHJpZW1waSgwLDAsMCk7IAogICAgICAgIHdyaXRlbG4oc29sdXppb25lKTsJCmVuZC4K