| | Precalculate pythagorean tripplesThe statement is poor. It says M*N, which is usually considered as M in x-axis and N in y-axis.But actually, for M=2,N=3 they mean
 xxx
 xxx
 (That can be infered from "The next M lines contain a matrix with nonnegative integer elements")
 And we can't understand that from Sample because it's a square!
 
 ***  So,if you always get WA2,try to swap m,n.  ***
 I changed scanf("%d %d",&m,&n) to scanf("%d %d",&n,&m) and got AC.
 Sorry for my poor English.
 
 Edited by author 15.08.2009 11:30
 
 Edited by author 15.08.2009 11:31
 Nevermind, i'm stupid... another hint for WA #2: when generate your numbers a^2+b^2=c^2, and then you invert things like (+3X, +4X) for X=1...while coordinates are valid, and then later you want to invert (+6X, +8X) — don't! Because you invert the same place once more.
 Edited by author 02.10.2015 16:50
 
 Edited by author 08.06.2009 19:23
 me too
 UPD. Oh, I understood my problem. I misunderstood the statment. Actually, there are m rows and n colums. But i thought on the contrary.
 
 Edited by author 04.01.2015 15:04
I've seen lots of guys crashed on test 2. Could anyone provide a hint for this test?1. Even number of changes does not change the color. For eg : B -> W -> B2. Odd number of changes equals to 1, B->W and vice versa
 
 Edited by author 01.10.2010 12:24
It is easy.I just two array.
 for point(x,y)
 change these point:
 x+dx,y+dy
 x+dx,y-dy
 x-dx,y+dy
 x-dx,y-dy
 
 Then you will got AC in 0.031s.
 ##########################################################
 dx:array [0..52] of longint=(0,3,4,5,6,7,8,8,9,9,10,12,12,12,12,14,15,15,15,16,16,18,20,20,20,21,21,24,24,24,24,24,27,28,28,30,30,32,33,35,36,36,36,40,40,40,42,44,45,45,48,48,48);
 dy:array [0..52] of longint=(0,4,3,12,8,24,6,15,12,40,24,5,9,16,35,48,8,20,36,12,30,24,15,21,48,20,28,7,10,18,32,45,36,21,45,16,40,24,44,12,15,27,48,9,30,42,40,33,24,28,14,20,36);
 ##########################################################
 
 Edited by author 29.05.2004 08:52
 Fuckie solution.. Just take check all points to can change it on every move. And it's not TLE !!! May be you make unnecessary changes (mod 2 just!!!)When you are reading the data input, take it by modulo 2. My solution with long long got TLE, but after processing ints by modulo 2, everything was ok.9 9WWWWWWWWW
 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
Here is my source :
 #include <stdio.h>
 
 int n,m;
 long y[60][60];
 char in[60][60],x[60][60],sel[3000];
 
 void read_data()
 {
 int i,j;
 FILE *f=stdin;
 fscanf(f,"%d%d",&m,&n);
 fscanf(f,"%c",&in[0][0]);
 for(i=0;i<m;i++)
 fgets(in[i],100,f);
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 fscanf(f,"%ld",&y[i][j]);
 }
 
 void init()
 {
 int i;
 for(i=0;i<=50;i++)
 sel[i*i]=1; //sel[i]== 1 if i==(X*X)
 //         0 else
 }
 
 void expand(int a,int b,int nr)
 {
 int i,j;
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 if(j==b || i==a || sel[((i-a)*(i-a)+(j-b)*(j-b))])
 x[i][j]=x[i][j] ^ nr;
 }
 
 void solve()
 {
 int i,j;
 init();
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 if(y[i][j])expand(i,j,y[i][j]%2);
 }
 
 void print()
 {
 int i,j;
 FILE *f=stdout;
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 if(x[i][j])
 if(in[i][j]=='B')fprintf(f,"W");
 else fprintf(f,"B");
 else fprintf(f,"%c",in[i][j]);
 fprintf(f,"\n");
 }
 }
 
 void main()
 {
 read_data();
 solve();
 print();
 }
 if in expand (i-a)=50 and (j-b)=50 then (i-a)*(i-a)+(j-b)*(j-b)=5000
 Just change sel[3000] // need more!
 
 and
 
 void init()
 {
 int i;
 for(i=0;i<=50;i++) // not 50!!! need more!!!
 sel[i*i]=1; //sel[i]== 1 if i==(X*X)
 //         0 else
 }
Why the cell [6][4] is 'W' in the output?We changed this cell 138 times.
 I think it must be 'B' as in input.
 Can U explain me?
 Please, Answer me.I know, that I'm wrong, 'cuz there are a lot of ACers.
 Can U explain me my mistake?
 Because a[2,1] can step on it
 Edited by author 27.08.2009 16:14
There are N rows And M columns. My solution with M rows and N columns has got ACI have a WA on the test 2. Who nows it, please, help me.
 My program:
 
 var  i,j,n,m,x:longint;
 s:array[1..50,1..50]of string[1];
 a:array[1..50,1..50]of integer;
 
 procedure redata;
 begin
 fillchar(a,sizeof(a),0);
 readln(n,m);
 for i:=1 to n do begin
 for j:=1 to m do
 read(s[i,j]);
 readln;   end;
 for i:=1 to n do begin
 for j:=1 to m do begin
 read(x);
 if x mod 2=1 then a[i,j]:=1; end;
 readln;   end;
 
 
 end;
 
 procedure zamena;
 var k,x,y:integer;
 begin
 for k:=1 to m do
 if s[i,k]='W' then s[i,k]:='B' else s[i,k]:='W';
 for k:=1 to n do
 if s[k,j]='W' then s[k,j]:='B' else s[k,j]:='W';
 
 if s[i,j]='W' then s[i,j]:='B' else s[i,j]:='W';
 
 for X:=1 to 50 do
 for Y:=X to 50 do
 
 if frac(sqrt((X*X)+(Y*Y)))=0 then begin
 
 if (i-x>0)and(j-y>0) then BEGIN
 if s[i-x,j-y]='W' then s[i-x,j-y]:='B' else s[i-x,j-y]:='W';END;
 
 if (i-y>0)and(j-x>0) then BEGIN
 if s[i-y,j-x]='W' then s[i-y,j-x]:='B' else s[i-y,j-x]:='W';END;
 
 if (i-y>0)and(j+x<=N) then BEGIN
 if s[i-y,j+x]='W' then s[i-y,j+x]:='B' else s[i-y,j+x]:='W';END;
 
 if (i+y<=M)and(j-x>0) then BEGIN
 if s[i+y,j-x]='W' then s[i+y,j-x]:='B' else s[i+y,j-x]:='W';END;
 
 if (i-x>0)and(j+y<=N) then BEGIN
 if s[i-x,j+y]='W' then s[i-x,j+y]:='B' else s[i-x,j+y]:='W';END;
 
 if (i+x<M)and(j-y>0) then  BEGIN
 if s[i+x,j-y]='W' then s[i+x,j-y]:='B' else s[i+x,j-y]:='W';END;
 
 if (i+x<=M)and(j+y<=N) then BEGIN
 if s[i+x,j+y]='W' then s[i+x,j+y]:='B' else s[i+x,j+y]:='W';END;
 
 if (i+y<=M)and(j+x<=M) then BEGIN
 if s[i+y,j+x]='W' then s[i+y,j+x]:='B' else s[i+y,j+x]:='W';END;
 
 end;
 end;
 
 procedure main;
 begin
 for i:=1 to n do
 for j:=1 to m do
 if a[i,j]=1 then zamena;
 end;
 
 procedure outdata;
 begin
 for i:=1 to n do begin
 for j:=1 to m do
 write(s[i,j]);
 writeln;  end;
 
 end;
 
 begin
 redata;
 main;
 outdata;
 end.
First i Think that it means horisontal and vertical num? butwhen i have written my program it did not pass that test!
 What mean integer num of meter?
 It's just simple problem but what's wrong?
 
 type longint = int64;
 
 var
 count,n,m,i,j,ii,jj:system.longint;
 Colors: array [1..50,1..50] of longint;
 a : array [1..50,1..50] of longint;
 sq : array [1..5000] of extended;
 can : array [1..5000] of boolean;
 C:char;
 
 
 begin
 assign(input,'input.txt');reset(input);
 assign(output,'output.txt');rewrite(output);
 
 readln(n,m);
 
 for i:= 1 to n do
 begin
 for j:= 1 to m do
 begin
 read(c);
 case c of
 'B': Colors[i,j] := 0;
 'W': Colors[i,j] := 1;
 end;
 end;
 readln;
 end;
 
 for i:= 1 to n do
 for j:=1 to m do
 read(a[i,j]);
 
 for i:= 1 to 5000 do sq[i] := sqrt(i);
 for i:= 1 to 5000 do can[i] := sqr(trunc(sq[i])) = i;
 
 
 for i:= 1 to n do
 begin
 for j:= 1 to m do
 begin
 count := 0;
 for ii := 1 to n do
 for jj := 1 to m do
 begin
 if (i =  ii) or (j = jj) then count := Count + a[ii,jj] else
 begin
 if can[(i - ii)*(i - ii) + (j - jj)*(j - jj)] then
 inc(count,a[ii,jj]);
 end;
 end;
 if count mod 2 = 1 then Colors[i,j] := (Colors[i,j] + 1) mod 2;
 if Colors[i,j] = 0 then write('B') else write('W');
 end;
 writeln;
 end;
 close(input);close(output);
 end.
 Edited by author 03.06.2004 14:57
 
 Edited by author 03.06.2004 14:57
const maxn=50;type hl=array[1..maxn] of 0..1;
 var data:array[1..maxn,1..maxn] of longint;
 f:array[1..maxn,1..maxn] of 0..1;
 h,l:hl;
 i,j,k,n,m:longint;
 color:array[1..maxn,1..maxn] of char;
 
 function min(r,t:longint):longint;
 begin
 if r<t then min:=r else min:=t
 end;
 
 procedure make(x,y:longint);
 begin
 for k:=min((m-i) div x,(n-j) div y) downto 1 do
 
 f[i+k*x,j+k*y]:=1-f[i+k*x,j+k*y];
 
 for k:=min((m-i) div x,(j-1) div y) downto 1 do
 
 f[i+k*x,j-k*y]:=1-f[i+k*x,j-k*y];
 
 for k:=min((i-1) div x,(j-1) div y) downto 1 do
 
 f[i-k*x,j-k*y]:=1-f[i-k*x,j-k*y];
 
 for k:=min((i-1) div x,(n-j) div y) downto 1 do
 
 f[i-k*x,j+k*y]:=1-f[i-k*x,j+k*y]
 
 end;
 
 begin
 assign(input,'input.in'); reset(input);
 readln(m,n);
 for i:=1 to m do
 begin
 for j:=1 to n do read(color[i,j]);
 readln
 end;
 for i:=1 to m do for j:=1 to n do read(data[i,j]);
 close(input);
 
 fillchar(h,sizeof(h),0); l:=h;
 fillchar(f,sizeof(f),0);
 
 for i:=1 to m do
 for j:=1 to n do
 if odd(data[i,j]) then begin
 h[i]:=1-h[i];
 l[j]:=1-l[j];
 make(3,4); make(4,3); make(5,12); make(12,5)
 end;
 for i:=1 to m do
 begin
 for j:=1 to n do
 if color[i,j]='W' then if odd(h[i]+l[j]+f[i,j]+data[i,j])
 then write('B') else write('W')
 else if odd(h[i]+l[j]+f[i,j]+data[i,j]) then write('W')
 else write('B');
 writeln
 end
 end.
 
 very obvious mistake,there are other numbers fit x*x+y*y=z*z for example 7*7+24*24=25*25 8*8+15*15=17*17 const maxn=50;My pro#include<stdio.h>
 #include<math.h>
 main()
 {
 int m,n,i,j,b[50][50],data,k,p,q,r,h,t[50][50];
 char a[50][50],c;
 scanf("%d%d",&m,&n);
 c=getchar();
 for(i=0;i<50;i++)
 for(j=0;j<50;j++)
 t[i][j]=0;
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
 c=getchar();
 if(c=='W')
 a[i][j]=0;
 else a[i][j]=1;
 }
 c=getchar();
 }
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 {
 scanf("%d",&data);
 b[i][j]=data%2;
 }
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 {
 if(b[i][j]==1)
 {
 /*  for(k=0;k<m;k++)
 {
 if(a[k][j]==1)
 a[k][j]=0;
 else a[k][j]=1;
 }
 for(k=0;k<n;k++)
 {
 if(a[i][k]==1)
 a[i][k]=0;
 else a[i][k]=1;
 }  */
 /* if(a[i][j]==1)
 a[i][j]=0;
 else a[i][j]=1;*/
 for(p=0;p<m;p++)
 for(q=0;q<n;q++)
 {
 if(p==i)
 t[p][q]++;
 else if(q==j)
 t[p][q]++;
 else{
 r=(p-i)*(p-i)+(q-j)*(q-j);
 h=sqrt(r);
 if(r==h*h)
 {
 t[p][q]++;
 
 }
 }     }
 }
 }
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 {
 t[i][j]=t[i][j]%2;
 if(t[i][j]==1)
 {
 if(a[i][j]==0)
 a[i][j]=1;
 else a[i][j]=0;
 }
 }
 
 for(i=0;i<m-1;i++)
 {
 for(j=0;j<n;j++)
 {
 if(a[i][j]==0)
 printf("W");
 else printf("B");
 }
 printf("\n");
 }
 for(j=0;j<n;j++)
 {
 if(a[i][j]==0)
 printf("W");
 else printf("B");
 }
 }
 | 
 |