Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 345932

Submitted on 6 Nov 2013 by Alfonso Nieto-Castanon

Correct

393Size
Leading solution size is 166.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
feval(@assignin,'caller','score',1000);

                    
2
Pass
 
%%
urlwrite('http://contest.usc.edu/index.php/Fall12/Home?action=download&upname=pits.in.txt','pits.in.txt');

                    
3
Pass
 
%%
 fid=fopen('pits.in.txt','r');
 t_expect=[19 2 2 3 -1 7 14 23 401 200 42 -1 27 -1];
 t1=0;
 qty=fscanf(fid,'%i',1);
for q=1:qty %qty
  n = fscanf(fid,'%f %f\n',2)'; % array size
  A=zeros(n);
  for i=1:n(1)
   strv=fgetl(fid);
   %A(i,:)=strv-'.';
   A(i,:)=strv;
  end
  ta=clock;
   [t]=Pits(char(A)) ;
  t1=t1+etime(clock,ta)*1000; % Time in msec
  fprintf('%2i  Cmds %3.0f  Sum Time %.0f \n',q,t,t1)
  %isequal(t,t_expect(q))
  assert(isequal(t,t_expect(q)));
end % q
t2=min(1000,t1);
fprintf('Actual Time = %.1f msec\n',t1)
feval(@assignin,'caller','score',floor(t2));
1  Cmds  19  Sum Time 52
 2  Cmds   2  Sum Time 53
 3  Cmds   2  Sum Time 55
 4  Cmds   3  Sum Time 57
 5  Cmds  -1  Sum Time 58
 6  Cmds   7  Sum Time 60
 7  Cmds  14  Sum Time 61
 8  Cmds  23  Sum Time 81
 9  Cmds 401  Sum Time 249
10  Cmds 200  Sum Time 306
11  Cmds  42  Sum Time 333
12  Cmds  -1  Sum Time 350
13  Cmds  27  Sum Time 372
14  Cmds  -1  Sum Time 394
Actual Time = 393.8 msec