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 316699

Submitted on 9 Sep 2013 by Paul Berglund

Correct

4000Size
Leading solution size is 69.
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',4000);

                    
2
Pass
 
%%
tic
urlwrite('http://contest.usc.edu/index.php/Fall12/Home?action=download&upname=pranks.in.txt','pranks.in.txt')
toc
ans =
/users/msssystem13/pranks.in.txt
Elapsed time is 0.528172 seconds.
3
Pass
 
%%
 fid=fopen('pranks.in.txt','r');
 v_expect=[.37 .26 1.11 .02 .89 .79 .01 .17 .37 1.05 .28 .04 .02 .09 .14 .49 .71 .06 .01];
 qty=fscanf(fid,'%i',1);
 t1=0;
 for q=1:qty %qty
  n = fscanf(fid,'%f %f \n',2)'; % num_rocks, time
  t=n(2);
  A=zeros(2*n(1),2); % Format is rows, columns
  for i=1:2*n(1)
   r = fscanf(fid,'%f %f \n',2)';
   A(i,:) = r;
  end
  tic
  ta=clock;
   [v]=Pranks(A,t) ;
  t1=t1+etime(clock,ta)*1000; % Time in msec
fprintf('%2i  vel %.2f  Sum Time %.0f \n',q,v,t1)
  assert(isequal(v,v_expect(q)));
 end
 fprintf('Processing Complete\n')
 fclose(fid);
t2=min(4000,t1);
fprintf('Actual Time = %.0f msec\n',t1)
feval(@assignin,'caller','score',floor(t2));
1  vel 0.37  Sum Time 417
 2  vel 0.26  Sum Time 421
 3  vel 1.11  Sum Time 431
 4  vel 0.02  Sum Time 442
 5  vel 0.89  Sum Time 2311
 6  vel 0.79  Sum Time 2326
 7  vel 0.01  Sum Time 2412
 8  vel 0.17  Sum Time 3678
 9  vel 0.37  Sum Time 5669
10  vel 1.05  Sum Time 7311
11  vel 0.28  Sum Time 9855
12  vel 0.04  Sum Time 12455
13  vel 0.02  Sum Time 14610
14  vel 0.09  Sum Time 14616
15  vel 0.14  Sum Time 14645
16  vel 0.49  Sum Time 14646
17  vel 0.71  Sum Time 14652
18  vel 0.06  Sum Time 16747
19  vel 0.01  Sum Time 17916
Processing Complete
Actual Time = 17916 msec