Cody

# Problem 1907. Capture the flag(s)

Solution 327239

Submitted on 1 Oct 2013 by Paul Berglund
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
%% % test cases randn('seed',0); rand('seed',0); N=randi([1000 4000],50,1); S=randi([1,50],50,1); Boards=arrayfun(@(s)convn(randn(100),ones(s)/s^2,'same'),S,'uni',0); FLAGSLEFT=0; DOPLOT=false; tic; for board=1:50 B=Boards{board}; sB=sort(B(:)); B=double(B>sB(round(numel(sB)*.9))); n=N(board); path=capture_the_flag(B,n); assert(size(path,1)<=n,'too many steps'); assert(all(sum(abs(diff([1,1;path])),2)<=1),'no jumping allowed'); if DOPLOT imagesc(B); hold on; plot(path(:,2),path(:,1),'y-'); hold off; axis equal; axis off; set(gcf,'color',0*[1 1 1]); colormap(.5*gray); drawnow; end B(1)=0; B((path-1)*[1;size(B,1)]+1)=0; fprintf('test %d; left %d flags\n',board,nnz(B)); FLAGSLEFT=FLAGSLEFT+nnz(B); end toc; assignin('caller','score',10000); assert(FLAGSLEFT<=10000,sprintf('Left %d flags',FLAGSLEFT)); assignin('caller','score',FLAGSLEFT);

test 1; left 200 flags test 2; left 288 flags test 3; left 0 flags test 4; left 0 flags test 5; left 0 flags test 6; left 0 flags test 7; left 0 flags test 8; left 0 flags test 9; left 340 flags test 10; left 148 flags test 11; left 0 flags test 12; left 0 flags test 13; left 471 flags test 14; left 0 flags test 15; left 422 flags test 16; left 0 flags test 17; left 0 flags test 18; left 0 flags test 19; left 0 flags test 20; left 0 flags test 21; left 0 flags test 22; left 112 flags test 23; left 0 flags test 24; left 0 flags test 25; left 0 flags test 26; left 0 flags test 27; left 0 flags test 28; left 410 flags test 29; left 283 flags test 30; left 0 flags test 31; left 0 flags test 32; left 0 flags test 33; left 0 flags test 34; left 0 flags test 35; left 0 flags test 36; left 45 flags test 37; left 0 flags test 38; left 0 flags test 39; left 0 flags test 40; left 0 flags test 41; left 117 flags test 42; left 0 flags test 43; left 0 flags test 44; left 17 flags test 45; left 0 flags test 46; left 0 flags test 47; left 0 flags test 48; left 72 flags test 49; left 36 flags test 50; left 15 flags Elapsed time is 29.813675 seconds.