Common Board#include<stdio.h> long mx,Matrix[1010][1010],i,j,k,y,sum,dim; int main() {
while(scanf("%ld",&dim)==1) { mx=-99999;sum=0; for(i=0;i<101;i++) for(j=0;j<101;j++) Matrix[i][j]=0; for(i=1;i<=dim;i++) for( j = 1 ; j <= dim ; j++) { scanf("%ld", &Matrix[i][j]); Matrix[i][j]+= Matrix[i][j-1] + Matrix[i-1][j] - Matrix[i-1][j-1]; if(mx < Matrix[i][j]) mx = Matrix[i][j]; } for(i = 1; i <= dim ; i++) for(j = 1; j <= dim ; j++) for( y = 1; y < i ; y++) for( k = 1 ; k < j ; k++) { sum = Matrix[i][j] - Matrix[i][k-1] - Matrix[y-1][j] + Matrix[y-1][k-1]; if(mx < sum) mx = sum; sum = 0; } printf("%ld\n",mx); } return 0; } Edited by author 28.04.2010 16:00 Edited by author 28.04.2010 16:01 Edited by author 28.04.2010 16:01 What's wrong with my program??? #include <iostream> using namespace std; pair<int,int> FindAnswer(const char *arr, const int &N, const int K); int main(void) { // Inputs data int N, K; (cin >> N >> K).get(); // Creates an extra array char *arr=new char[N]; int length=0; int pos=-1; pair<int,int> res(-1,-1); char ch[1]; while(pos!=N-1) { while(pos!=N-1 && cin.read(ch, 1) && cin) { // Reads the next character if(ch[0]=='\n') continue; ++pos; // Inserts the digit to the array if(ch[0]!='*') arr[length++]=ch[0]; // Resets the array and finds the result else { if(length>=K) { pair<int,int> tmp=FindAnswer((const char *)arr, length, K); if(tmp.first<res.first) { res.first=tmp.first; res.second=pos-length+tmp.second; } } length=0; } } } // Outputs the result if(res.second==-1) cout << 0 << endl; else cout << res.second+1 << endl; return 0; } // Function determines the result pair<int,int> FindAnswer(const char *arr, const int &N, const int K) { int best=0; int res=0; int i; for(i=0; i<K; ++i) best+=arr[i]-'0'; int prev=best; for(i; i<N; ++i) { int tmp=prev-arr[i-K]+arr[i]; if(tmp<best) { best=tmp; res=i-K+1; } prev=tmp; } return make_pair(best, res); } Edited by author 14.03.2007 16:08 If you have WA#3 try to use this simple test: 1 1 9 Right answer is "1", of course. i've got tl on tets 7 cannot you say why? i just calculate gcd of all numbers Edited by author 26.04.2010 21:02 Edited by author 26.04.2010 21:03 How is this possible? I get different results with same code and same test cases? Cheers! Help Edited by author 25.04.2010 21:50 Edited by author 25.04.2010 21:50 Of course You can't solve this in O(n). Limitations is to high. Just try to find out a O(1) solution! =) program p1028; var s,l:array[0..16000] of longint; x,y,n,tot,i:longint; procedure ins(x,left,right:longint); var mid:longint; begin mid:=(left+right) div 2; if x>mid then begin inc(tot,s[mid]); ins(x,mid+1,right); end; if x=mid then begin inc(tot,s[mid]); inc(s[mid]); end; if x<mid then begin inc(s[mid]); ins(x,left,mid-1); end; end; begin readln(n); for i:=1 to n do begin readln(x,y); tot:=0; ins(x,0,32002); inc(l[tot]); end; for i:=0 to n-1 do writeln(l[i]); end. Thx a lot!!! Edited by author 17.08.2009 09:40 i also WA#9 Orz So do I. It solves with binary tree or sqrt-decomposition. 9 9 WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 correct answer WBWWBWWBW BWWWBWWWB WWWWBWWWW WWWWBWWWW BBBBBBBBB WWWWBWWWW WWWWBWWWW BWWWBWWWB WBWWBWWBW > '[%]' like '[%]' In the template [%] presents literally just '%' as single char. String however is literally is '[%]' And those obviously are not the same ;) What right answer on sample test data? 0.007142857143 on corners, 0.011904761905 on sides and 0.019047619048 on the center 7x7 square Edited by author 24.04.2010 23:37 After wa1 many times i submit programms that should got CE (i print some strings,not numbers) but got wa1. Also i print nothing - again wa1,but not CE. It's very strange. May be checker to this problem is incorrect? X## O#X XOO MY AC CODE SAY: DRAW (BUT IT CROSSES WIN) MAY BE IT WA11? Edited by author 22.03.2009 16:51 VERY THANKS! I'v got AC after your mess!) I submit prim's realization that got AC at olympiads.ru. Also i submitted kruskal's realization that got AC at some past contest. Why both AC programms can't pass test #1? can somebody give me tricky test cases? Hi! I used greedy, but I get WA on #12! Can somebody help me? Me 2...So,what's the matter? Nevermind, I found my problem in the code. Edited by author 24.04.2010 02:55 ...Выяснилось, то данный модуль был написан 8 лет назад, к первому Чемпионату Урала, и его исходные коды за это время успели потерятся... нужен мягкий знак в слове "потерятЬся" It is my program. program sad; var tu:array[1..100,1..100] of int64; d,p:array[1..1000] of int64; f:array[1..1000] of boolean; k,pre,pree:array[1..1000] of int64; a:array[1..90,1..6,1..8] of int64; ii,jj,w,i,j,m,n,u,v,bit,l,r,t,q,sum,g,i1,i2,i3,i4,n1,n2,n3,n4:longint; c:char;s:string; function pd:boolean; var w:longint; begin for w:=1 to 4 do if a[i,j,w]<>a[ii,jj,w] then exit(false); exit(true); end; procedure spfa(s:longint); var i,j,k,h,t,x:longint; begin fillchar(f,sizeof(f),false); fillchar(p,sizeof(p),0); for i:=1 to n do d[i]:=maxlongint shr 1; f[s]:=true; t:=1; h:=0; d[s]:=0; p[t]:=s; while h<>t do begin h:=(h mod n)+1; x:=p[h]; f[x]:=false; for j:=1 to n do if (tu[x,j]<>0) and (d[x]+tu[x,j]<d[j]) then begin d[j]:=d[x]+tu[x,j]; if not f[j] then begin t:=(t mod n) +1; p[t]:=j; f[j]:=true; pre[j]:=x; end; end; end; end; begin readln(n); for i:=1 to n do begin readln(k[i]); for j:=1 to k[i] do begin readln(s); g:=pos('.',s);val(copy(s,1,g-1),i1);delete(s,1,g); g:=pos('.',s);val(copy(s,1,g-1),i2);delete(s,1,g); g:=pos('.',s);val(copy(s,1,g-1),i3);delete(s,1,g); g:=pos(' ',s);val(copy(s,1,g-1),i4);delete(s,1,g); g:=pos('.',s);val(copy(s,1,g-1),n1);delete(s,1,g); g:=pos('.',s);val(copy(s,1,g-1),n2);delete(s,1,g); g:=pos('.',s);val(copy(s,1,g-1),n3);delete(s,1,g); val(s,n4); a[i,j,1]:=i1 and n1; a[i,j,2]:=i2 and n2; a[i,j,3]:=i3 and n3; a[i,j,4]:=i4 and n4; end; end; for i:=1 to n do for ii:=1 to n do for j:=1 to k[i] do for jj:=1 to k[ii] do begin if not pd then break; tu[i,ii]:=1; tu[ii,i]:=1; end; readln(l,r); spfa(l); q:=r; sum:=0; while q<>0 do begin inc(sum); pree[sum]:=q; q:=pre[q]; end; if (sum>1) and (sum<>0) then begin writeln('Yes'); for i:=sum downto 1 do write(pree[i],' '); end else write('No'); writeln; end. WA at 5# ~~ Help me~! I found my stupid mistake! need have only one: #include <cmath> Edited by author 30.04.2010 02:30 I think, that there was no adjustment to the "order of the computers" for output in problem "Output" paragraph. I think, that it was no difference between direct path and reverse path. So, for example code, that printed Yes 1 3 5 6 was Accepted, but code, that printed Yes 6 5 3 1 was rejected. |
|