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 181001

Submitted on 22 Dec 2012 by Tim

Correct

304Size
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 23
 2  Cmds   2  Sum Time 23
 3  Cmds   2  Sum Time 23
 4  Cmds   3  Sum Time 24
 5  Cmds  -1  Sum Time 24
 6  Cmds   7  Sum Time 24
 7  Cmds  14  Sum Time 24
 8  Cmds  23  Sum Time 28
 9  Cmds 401  Sum Time 227
10  Cmds 200  Sum Time 262
11  Cmds  42  Sum Time 282
12  Cmds  -1  Sum Time 303
13  Cmds  27  Sum Time 304
14  Cmds  -1  Sum Time 304
Actual Time = 304.2 msec