Cody

# Problem 2264. GJam 2011 Africa Qualifier C: House, maximum area rectangle

Solution 1567766

Submitted on 23 Jun 2018 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
nc=1; str='G'; Aexp=1; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

2   Pass
nc=2; str='GSSG'; Aexp=4; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

3   Pass
nc=2; str='GTGG'; Aexp=2; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

4   Pass
nc=5; str='GGTGGTGGGGGSSGTGGGGGRWTRTRTWWTWTWRR'; Aexp=9; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

5   Pass
nc=48; str='SSGSGSSGGGWSSSGSGGGGGGSGGSGSSGGSGGGSSSSGSSSSSSGSGSSSSGSGGSGSSSGGGGGGSGSGSGSSSSSSSSGGGGGSGGGSGSSSSGGSGSSGSGSSGSSSGSGGGSGSSSGSSGGGGSGSSSSSSGGGSGGGGGGSGSGSSSSGGGSSSGGGGGSGSSSGSGSSGSGGSSSSSSGGSSGGGSGSGGGGSSGGGGSSSSSSGGSGGSGGSGSGGSSGGGGSRGSGGSGSSSSSGSGGSSSSGSGGSSSSGSSSGSGGSSGGGGSSGSSGSSGGSGGSSGSSGSGSGGSGSGGSGGGGGGGGGSGGSGSSSSSGSSSGGGSSSGSSGSGSSGGSGSSGGSGGSGSSSGSGGGSGSSSSSGGSGGGGGGGSSGGSSSSSGGGGSGSSSGGGSSGSGSGGGGGSSSGGSGGGGSSSGGGGGSGSSSSSGGSGSSSTGGSSSSSSSSSGSGRGGSSSGSGGSSGSSGGGSSGGGGGGSGGGSGGSGGGGSGSSSGSGGSSSGGGSGSGSGGGGSSSGGGSSSGSSSGGGGGGGSGSGSSSSSGSSGGSGGSGSGGSGSSGGGSGSSGSSGSSSSGSGGGGGSGGGSGSGSSSSGGSSGGSSGGSSGGGGSSGGGGGGSSSGSSGSSSG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GSSSSSSGGSSGSGSSSSGGGSSGGSGGGGSSGGSGSSGSGGGGGGGGSWSSRSSSSSGGSGSGGSGSSGSSSGGGSGSGGSSGSWSGGSSGGSSSGGGGGSGGSSSGGSSSGSGGSSGGGSSGSSGSGSSWSSSSSSSGGGGGSGGSGSSSSSSTSGSSSSSSGSGWSSGSSSSSGGGSSGSSSGGGGSSSSGSGSGWSSGSGSSGSSSGGSSSGSGSGGGSGSSGGGSSSGGGSGGSGGGSGGGGGGGSSGGGSGSGGGSSSSSRSSGSGSGGGGSGSSSGSGSSGGGGGSSSGSGSGSSGGGGSSSGSSSS'; Aexp=144; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

11   Pass
nc=35; str='SSSGGSSSSSSGSSGGGGGGSSGGGGGGGSGGSSGGSGGSGSGGGRSGSSSGSSGSGGTGSGSGGSGSSGSGSGGSGGGGSSSGGGGGGGSGSSGSGGGSGSGGSGSSSGSSSGSSGSSSGGSGSGSSSGGGGGSSSGGGSSSSSSSSGGGSSGGSGSSGGGGGGGGGSGSSSSGGGGGSSGGSGSGSSSGGSSSSSGGGGGSGSRSSGGSGSSGSSSSGSGGGSSGSGSSSSSSSGSGSSSGGG'; Aexp=150; A=House(reshape(str,nc,[])'); assert(isequal(Aexp,A))

12   Pass
% function GJam_Africa_2011C % %House % %fn='C-small-practice.in'; % fn='C-large-practice.in'; % [data] = read_file(fn); % % %fidG = fopen('C-small-output.out', 'w'); % fidG = fopen('C-large-output.out', 'w'); % tic % for i=1:size(data,1) % Cell array has N rows of cases % A = House(reshape(data{i,2},data{i,1},[])' ) ;% data matrix GWRST % toc % % continue % fprintf(fidG,'Case #%i: %i\n',i,A); % fprintf('Case #%i: %i\n',i,A); % % end % toc % % fclose(fidG); % fclose(fidC); % % end % % function [d] = read_file(fn) % %Read a numeric of lines to count % fid=fopen(fn); % fgetl(fid); % Total Count ignore % set=0; % while ~feof(fid) % nrc=str2num(fgetl(fid)); % [nc nr] % str=''; % for i=1:nrc(2) % str=[str fgetl(fid)]; % read line of data, convert to vector % end % set=set+1; % d{set,1}=nrc(1); % need to do a transpose after % d{set,2}=str; % end % fclose(fid); % end % % function A=House(m) % % GRWST: G1 R0 W0 S1 T0 [0 11 16 12 13] on G subtract % m=m-'G'; % Convert String array to binary % m(m==12)=0; % m=double(~m); % % [nr,nc]=size(m); % A=0; % % try all [1:nr,1:nc] overlay convolutions and find max % for i=1:nr % for j=1:nc % if i*j>A % speed enhance, faster than continue continue % mc=conv2(m,ones(i,j)); % if nnz(mc==i*j) % fastest array compare % A=i*j; % Current Max Rectangle % end % end % end % j % end % i % % end % House % % Data input example %10 %1 1 %G %2 2 %GS %SG %2 2 %GT %GG %8 9 %GGGSGGSG %RSGGSGGG %GSSGSGGG %GGSSSGSS %SGGGSSRS %SSWGSSSS %GGGSSGSG %SGSSSWGS %SGSGSSGS

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!