Page 1 of 2

541 - Error Correction

Posted: Wed Feb 05, 2003 11:59 am
by mido
Is there something I can't see here...here's my code:
[cpp]
#include <iostream.h>

void main()
{
int list[100][100];
int row[100];
int col[100];
int dim;
int i,j,badrow_count,badrow_index,badcol_count,badcol_index;
while (cin>>dim && dim>0)
{
badrow_count=0;
badcol_count=0;
for (i=0;i<dim;i++)
row=col=0;
for (i=0;i<dim && badrow_count<2;i++)
{
for (j=0;j<dim;j++)
{
cin>>list[j];
row+=list[j];
col[j]+=list[j];
}
if (row%2==1)
{
badrow_count++;
badrow_index=i;
}
}
for (j=0;j<dim && badcol_count<2 && badrow_count<2;j++)
{
if (col[j]%2==1)
{
badcol_count++;
badcol_index=j;
}
}
if (badrow_count>=2 || badcol_count>=2 || badrow_count!=badcol_count)
cout<<"Corrupt\n";
else if (badrow_count==badcol_count && badrow_count==1)
cout<<"Change bit ("<<badrow_index+1<<","<<badcol_index+1<<")\n";
else if (badrow_count==badcol_count && badrow_count==0)
cout<<"OK\n";
cout.flush();
}
}[/cpp]

Posted: Thu Feb 06, 2003 10:53 am
by turuthok
For each test-case, ... read the input thoroughly. Eventhough you detect bad stuff way before you read the whole array ... you still need to read all the array-elements.

-turuthok-

Posted: Thu Feb 06, 2003 10:56 am
by turuthok
One suggestion to improve speed and save some memory:

You don't really need to allocate list[][], do you ??? A simple int should be sufficient.

-turuthok-

Posted: Thu Feb 06, 2003 1:24 pm
by mido
I did just that...major thanks!!!!

541 - Error Correction - I am getting a little confused

Posted: Wed Apr 23, 2003 1:28 pm
by Almost Human
why is it P.E ? any suggestion will be appreciated

Code: Select all

#include <stdio.h>

char array[100][100] , count[2][100] ;
int MaxArr ;

char isfutile ( void ) ;

int main ( )
{
  int i , j , note ;
  char flag ;

/*  freopen ( "541.in" , "r" , stdin ) ;
  freopen ( "541.out" , "w" , stdout ) ;*/

  while ( 1 )
  {
	 scanf ( "%i" , &MaxArr ) ;

	 if ( MaxArr < 1 ) break ;

	 for ( i = 0 ; i < MaxArr ; i ++ )
		for ( j = 0 ; j < MaxArr ; j ++ )
		  scanf ( "%i" , &array[i][j] ) ;

	 flag = 0 ;

	 for ( i = 0 ; i < MaxArr ; i ++ )
	 {
		for ( count[0][i] = count[1][i] = 0 , j = 0 ; j < MaxArr ; j ++ )
		  count[0][i] += array[i][j] , count[1][i] += array[j][i] ;
		if ( count[0][i] % 2 || count[1][i] % 2 ) flag = 1 ;
	 }

	 if ( !flag )
	 {
		printf ( "OK\n" ) ;
		continue ;
	 }

	 if ( isfutile ( ) )
		printf ( "Corrupt\n" ) ;
	 else
	 {
		for ( i = 0 ; count[1][i] % 2 == 0 ; i ++ ) ;
		for ( j = 0 ; count[0][j] % 2 == 0 ; j ++ ) ;

		printf ( "Change bit ( %i , %i )\n" , j + 1 , i + 1 ) ;
	 }
  }

  return 0 ;
}

char isfutile ( void )
{
  char flag ;
  int i ;

  for ( flag = 0 , i = 0 ; i < MaxArr ; i ++ )
	 if ( count[0][i] % 2 ) flag ++ ;

  if ( flag > 1 ) return 1 ;

  for ( i = 0 , flag = 0 ; i < MaxArr ; i ++ )
	 if ( count[1][i] % 2 ) flag ++ ;

  if ( flag > 1 ) return 1 ;

  return 0 ;
}

Posted: Wed Apr 23, 2003 1:42 pm
by Eric
printf ( "Change bit ( %i , %i )\n" , j + 1 , i + 1 ) ;
There is no space between the numbers.

Posted: Wed Apr 23, 2003 2:18 pm
by Almost Human
allright !!! it is accepted ..

many many thanks

541

Posted: Tue Sep 30, 2003 5:54 am
by kuloch2
Hey, I'm pretty new here. I've had trouble getting the memory usage low enough with problem 541. A couple C++ solutions I've seen used a char[100][100], so I can't imagine how my solution would be in excess when those wouldn't...

Anyway, here's the code. I'd appreciate any suggestions.

[java]
import java.io.*;
import java.util.*;

class Main {

public static void main(String args[]) {

while (true) {

byte n = Byte.parseByte(ReadLn(5));
if (n == 0)
System.exit(0);

String input;
byte[] sumRow = new byte[n], sumCol = new byte[n];

for (int i=0; i<n; i++) {
input = ReadLn(255);
for (int j=0; j<n; j++) {
byte tmp = (byte)(input.charAt(j*2) - '0');
sumRow += tmp;
sumCol[j] += tmp;
}
}

byte row = 0, numR = 0, col = 0, numC = 0;
for (int i=0; i<n; i++) {
if (sumRow % 2 != 0) {
row = (byte)(i + 1);
numR++;
}
if (sumCol % 2 != 0) {
col = (byte)(i + 1);
numC++;
}
}

if (numR == 0 && numC == 0) {
System.out.println("OK");
} else if (numR == 1 && numC == 1) {
System.out.println("Change bit ("+ row +","+ col +")");
} else {
System.out.println("Corrupt");
}
}
}

static String ReadLn(int maxLg) {
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
String line = "";
try {
while (lg < maxLg) {
car = System.in.read();
if ((car < 0) || (car == '\n'))
break;
lin[lg++] += car;
}
} catch (IOException e) {
return (null);
}
if ((car < 0) && (lg == 0))
return (null); // eof
return (new String(lin, 0, lg));
}
}
[/java]

Posted: Mon Oct 13, 2003 11:42 pm
by Kuloch
I finally realized (haven't looked at it for a couple weeks) that I was needlessly creating a byte[][] array (since you never look at each cell but once). But not only is it still giving me a "Too much memory" error, but the Judge says I'm using the exact same 135152 Kbytes as before. There's no way that removing a byte[][] array had no effect on memory usage.

Please someone help me here... I'm utterly clueless about what to do.

541 wa help me

Posted: Mon Nov 10, 2003 6:09 pm
by problem
here is my source code.i dont find any kind of problem.help me about this problem.judge reply wa.





/* @JUDGE_ID: xxxxxx 541 C++ */


#include<stdio.h>
#include<string.h>
main()

{
freopen("c:\\error.in","r",stdin);
// freopen("d:\\on","w",stdout);
int i;

while(scanf("%d",&i)==1)
{
if(i==0)break;
int p=0,li1=0,li2=0,sto=0,sto1=0,pot=0;
// scanf("%d",&i);
int a[10][10];
for(int j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
scanf("%d",&a[j][k]) ;
}
}
int check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[j][k];
}
if(p%2)
{ check=0;
li1++;
pot=0;
pot=li1;
//pot=0
} //check=1;
if(pot==1&&check!=1)
{
sto=j;
pot++;
check=1;
}
p=0;

}
check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[k][j];
}
if(p%2)
{
check=0;
li2++;
int pot2=li2;
if(pot2==1&&check!=1)
{
sto1=j;
pot2++;
check=1;
}
}
p=0;
}
if(sto==0&&sto1==0)
printf("OK\n");
if(li1==1&&li2==1)
printf("Change bit (%d,%d)\n",sto+1,sto1+1);
if(li1>1||li2>1)
printf("Courupt\n");

}
fclose(stdin);
}

541 wa help me plz

Posted: Tue Nov 25, 2003 11:27 am
by problem
error correction i m frustrated.wa.plz help me.
[cpp]
/* @JUDGE_ID: xxxxxx 541 C++ */


#include<stdio.h>
#include<string.h>
main()

{
//freopen("c:\\error.in","r",stdin);
// freopen("d:\\on","w",stdout);
int i;

while(scanf("%d",&i)==1)
{
if(i==0)break;
int p=0,li1=0,li2=0,sto=0,sto1=0,pot=0;
// scanf("%d",&i);
int a[10][10];
for(int j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
scanf("%d",&a[j][k]) ;
}
}
int check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[j][k];
}
if(p%2)
{ check=0;
li1++;
pot=0;
pot=li1;
//pot=0
} //check=1;
if(pot==1&&check!=1)
{
sto=j;
pot++;
check=1;
}
p=0;

}
check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[k][j];
}
if(p%2)
{
check=0;
li2++;
int pot2=li2;
if(pot2==1&&check!=1)
{
sto1=j;
pot2++;
check=1;
}
}
p=0;
}
if(sto==0&&sto1==0)
printf("OK\n");
if(li1==1&&li2==1)
printf("Change bit (%d,%d)\n",sto+1,sto1+1);
if(li1>1||li2>1)
printf("Courupt\n");

}
fclose(stdin);
}
[\cpp]

541 Why WA?

Posted: Wed Mar 17, 2004 4:00 pm
by Kamanashish
Cut

541(error crrection)-but i'm in error(WA)

Posted: Fri Oct 13, 2006 6:28 am
by nahid
Pleas help the little programmer
. I have solved a number of promlem but most of them are wrong by on-line judge. please help me about 541. here is my code

Posted: Sun Oct 15, 2006 9:01 am
by Tariq Shahriar
the mistake is
int i,j,n,m,er=0,row,col,ec=0;
you need to initialize er,ec for every input set.
so place the initialization here.

Code: Select all

while(scanf("%d",&n)) 
   { 
      if(n==0) 
         break; 
      er=ec=0;
     .........
Be careful about initialization error.

541-error correction --help is wanted

Posted: Fri Mar 23, 2007 5:26 pm
by Rushow
I think it is an easy problem to solve. But I can't understand what is problem with my code, that make me to get WA. Here is my code. Is there anybody to help me?