10188 - Automated Judge Script

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

monmobear
New poster
Posts: 2
Joined: Sat Jun 21, 2003 11:18 pm

10188 Runtime eroor Invalid memory reference

Post by monmobear »

What's wrong with this ??

I got Runtime error ... [ Invalid memory reference ]

I have tried many test data .. It is correct .. but .. >< |

Help me plz ..

[cpp]

#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
#include<math.h>
void main(){

//ifstream cin("10188.in");
int i,j,k,q;
int state;
int an,in,idx=0;
int exit=0;

char ta,tb;
char **a,**id;
char *temp;

while(1)
{
cin>>an;
{
if(an)
idx++;
else
{
exit=1;
break;
}
cin.gets(&temp,'\n');
// cout<<an<<endl;
for(i=0;i<an;i++)
a = new char*[1000];

for(i=0;i<an;i++)
{
cin.gets(&a,'\n');
// cout<<a<<endl;
}
}

cin>>in;
{
cin.gets(&temp,'\n');
// cout<<in<<endl;
for(i=0;i<in;i++)
id = new char*[1000];

for(i=0;i<in;i++)
{
cin.gets(&id,'\n');
// cout<<id<<endl;
}
}

state=1;
for(i=0;i<in;i++)
{
if(strcmp(a,id)!=0)
state=0;
}
cout<<"Run #"<<idx<<": ";

if(state)
cout<<"Accepted"<<endl;
else
{
i=0;j=0;k=0;q=0;
state=0;
while(1)
{
while(1)
{
ta='!';
if(a[j]=='\0')
{
i++;
j=0;
}
j++;

if(i==an)
break;

if(a[j]>='0'&&a[j]<='9')
{
ta=a[j];
break;
}
}

while(1)
{
tb='!';
if(id[k][q]=='\0')
{
k++;
q=0;
}
q++;

if(k==in)
break;

if(id[k][q]>='0'&&id[k][q]<='9')
{
tb=id[k][q];
break;
}
}
if(ta=='!'||tb=='!')
break;
// cout<<"ta:"<<ta<<" tb:"<<tb<<endl;
if(ta!=tb)
state=1;
}
if(state)
cout<<"Wrong Answer"<<endl;
else
cout<<"Presentation Error"<<endl;
}
delete[] id;
delete[] a;
}
// cin.get();
}
//@END_OF_SOURCE_CODE
//28/06/03 03:18

[/cpp]
Last edited by monmobear on Mon Jun 30, 2003 4:33 pm, edited 1 time in total.

szymcio2001
New poster
Posts: 38
Joined: Mon Dec 09, 2002 1:53 pm
Location: Poznan, Poland

Re: 10188 Runtime eroor Invalid memory reference

Post by szymcio2001 »

[cpp]

state=1;
for(i=0;i<in;i++)
{
if(strcmp(a,id)!=0)
state=0;
}

[/cpp]

I think that if 'in > an' you can got RE, but I'm not sure.

And don't send to board posts with your ID with suffix! At UVA site the suffix works similar to password.

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro »

Oh please mr accepted guy (s) :)

Give me the CORRECT output for my sample :

Code: Select all

2
                                                                                
                                                                                
2
                                                                                
                                                                                
2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 15
2
The answer is: 10
The answer is:  5
2
The answer is: 10
The answer is: 5
3
                     Input Set #1: YES
Input Set #2: NO
Input Set #3: NO
3
Input Set #0: YES
Input Set #1: NO
            Input Set #2: NO
1
1 0 1 0
1
1010
1
                                                                                
1
                                                                                
1
The judges are mean!
1
The judges are good!
3
Input Set #1: YES
Input Set #2: NO
Input Set #3: NO
4
123
ABCDE FG
hij k
lmn
1
alskjdflajksdf;lkjas;dfj
1
1
2
 d 3
 
1
 d 3
3
adfs df 1 dasf adf df
2
fs aaaaaaaaaaaa 3
3
aa1
2
3
0

my *WA* output for this is :

Code: Select all

Run #1: Accepted
Run #2: Accepted
Run #3: Wrong Answer
Run #4: Presentation Error
Run #5: Wrong Answer
Run #6: Presentation Error
Run #7: Accepted
Run #8: Presentation Error
Run #9: Presentation Error
Run #10: Presentation Error
Run #11: Presentation Error
Run #12: Presentation Error
You can just copy & paste the code, i've tested it :-)
[]s
Mauricio Oliveira Carneiro

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

hello carneiro...

Code: Select all

Run #1: Accepted
Run #2: Accepted
Run #3: Wrong Answer
Run #4: Presentation Error
Run #5: Wrong Answer
Run #6: Presentation Error
Run #7: Accepted
Run #8: Presentation Error
Run #9: Presentation Error
Run #10: Wrong Answer
Run #11: Presentation Error
Run #12: Presentation Error
thanks...
Istiaque Ahmed [the LA-Z-BOy]

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro »

Ok, let's be straight :)

The only difference was this test case :

Code: Select all

1
alskjdflajksdf;lkjas;dfj
1
1

By what I understood from the problem description :
We want you to give "Presentation Error" if all NUMERIC charaters match (and in the same order) but there is at least one non-numeric character wrong (or in wrong order)

In this case, we don't have any numeric characters at all, so all of them (none) were matched. Inspite of the caracter 1 in the team's response.

But I understood the correct interpratation of this and changed my program so the output is exactly like yours now, but I still get WA :-(

I did a quite simple solution for that, let me explain:
  • 1. Read the inputs with fgets, concatenating all lines in one string (for the answer and the team's attempt)

    2. strcmp(answer, team), if they are perfect ( 0 ), print ACCEPTED.

    3. if they aren't, read the both strings into two new strings composed only by numbers (in the order they appear of course) without spaces or other characters between them.

    4. strcmp(newanswer, newteam), if they are perfect ( 0 ), print PRESENTATION ERROR.

    5. otherwise, just print Wrong Answer.
And it works for your example. Any ideas ? Is there a special input I'm not aware of ?

Thank you
[]s
Mauricio Oliveira Carneiro

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro »

Oh god ... found the problem.

my fgets(s, 102, stdin) was not enough. I raised it to 190 and got accepted.

god damn!!!

And it says : " NO LINE WILL HAVE MORE THAN 100 CHARACTERS "

liars ;-)
[]s
Mauricio Oliveira Carneiro

klokflicka
New poster
Posts: 1
Joined: Wed Sep 24, 2003 9:44 am
Location: Seattle, WA
Contact:

Can't find non working test case

Post by klokflicka »

I keep getting WA in my submissions but can't find of a test case that generates a wrong answer. Could someone propose a test case that generates a wrong answer for this program?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void numberInString (char *string, char *number){


int index =0;
memset (number, 0, 100);
for (int i =0; i<strlen (string); i++){
if (string =='0' ||string=='1' || string=='2' ||string =='3' ||string=='4' || string=='5' ||string =='6' ||string=='7' || string=='8' || string =='9' ||string[i]=='0'){
number[index]= string[i];
index++;
}

}
number[index]='\0';


}

main(){
int nthCase = 1;
int nLines;
// scanf ( "%d", &nLines);
char number [101];
memset(number, 0, 101);
gets (number);
nLines=atoi(number);
char *orig= new char [10105];
char *sample= new char [10105];
while (nLines>0){
// char c[100];
// gets(c);
int nLinesResult;
memset ( orig, 0, 10105);
memset ( sample, 0, 10105);
// printf ("nLines %d char: %c:",nLines, c);
for ( int i =0; i<nLines; i++){
char temp[101];
memset(temp, 0, 101);
gets ( temp);
//printf ("temp :%s\n", temp);
strcat( orig, temp);
strcat(orig, "\n");
}
// printf ( "orig: %s", orig);
// scanf("%d", &nLinesResult);
memset(number, 0, 101);
gets (number);
nLinesResult=atoi(number);
for ( int i =0; i<nLinesResult; i++){
char temp[101];
memset (temp, 0, 101);
gets(temp);
strcat (sample, temp);
strcat(sample, "\n");
}
// printf ( "samp: %s", sample);
char *numberOrig =new char[10105];
memset (numberOrig, 0, 10105);
numberInString (orig, numberOrig);
char *numberSample = new char[10105];
memset (numberSample, 0, 10105);
numberInString (sample, numberSample);
bool wrong =false;
bool formatError = false;
bool different = false;
if ( strlen (numberOrig)!=strlen(numberSample)){different=true;}
if (!different){
for ( int m =0; m<strlen(numberOrig); m++){
if (numberOrig[m]!=numberSample[m]){
different = true;
}
}}
if (different){
printf ("Run #%d: Wrong Answer\n",nthCase);
wrong = true;
}
if (!wrong && strlen (orig)!=strlen(sample)){
formatError = true;
printf ("Run #%d: Presentation Error\n",nthCase);
}
else if (!wrong && !formatError){
for ( int j =0; j<strlen(orig); j++){
if(orig[j]!=sample[j]){
formatError = true;
printf ("Run #%d: Presentation Error\n",nthCase);
break;
}
}
}
if (!wrong && !formatError){
printf ("Run #%d: Accepted\n",nthCase);

}

memset(number, 0, 101);
gets (number);
nLines=atoi(number);
// scanf ("%d", &nLines);
nthCase++;
}
}


Thanks

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

:)

Post by Sajid »

Hi all. I got AC with the 1st time submission.

It's mentionable that, I used

Code: Select all

while(scanf("%d",&n)==1 && n)
and getchar(); after every scanf()

8)
Sajid Online: www.sajidonline.com

weituskywalker
New poster
Posts: 1
Joined: Tue Mar 30, 2004 12:38 am

10188..WA..frustrated..

Post by weituskywalker »

Been working on this for a long time and it passes all the test cases on the board but i still get a WA...can anyone help please?

Thanks..

[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#define MAXL 200
#define MAXC 200
#define ACCEPT 1
#define PERROR 2
#define WRONG 3

int keyl, ansl, keynuml, ansnuml, output, num, error;
char key[MAXL][MAXC];
char ans[MAXL][MAXC];
char keynum[MAXL * MAXC];
char ansnum[MAXL * MAXC];
char temp[MAXL];

void readinput()
{
int i,j;
/* read key */
for (i = 0; i < keyl; i++)
gets(key);

if (gets(temp) == NULL) {
error = 1;
return;
}
ansl = temp[0] - '0';
if (ansl == 0) {
error = 1;
return;
}
for (i = 0; i < ansl; i++)
gets(ans);

/* read keynums */
for (i = 0; i < keyl; i++) {
for (j = 0; j < strlen(key) ; j++) {
if (isdigit(key[j])) {
keynum[keynuml] = key[j];
keynuml++;
}
}
}

/* read ansnums */
for (i = 0; i < ansl; i++) {
for (j = 0; j < strlen(ans) ; j++) {
if (isdigit(ans[j])) {
ansnum[ansnuml] = ans[j];
ansnuml++;
}
}
}

}

void check()
{
int i;
if (keyl == ansl) {
for (i = 0; i < keyl; i++) {
if (strcmp(key, ans))
break;
}
if (i == keyl) {
output = ACCEPT;
return;
}
}

if (keynuml == ansnuml) {
for (i = 0; i < keynuml; i++) {
if (keynum[i] != ansnum[i])
break;
}
if (i == keynuml) {
output = PERROR;
return;
}
}

output = WRONG;


return;
}

void printout()
{
printf ("Run #%d: ", num);

switch (output) {

case ACCEPT:
printf ("Accepted\n");
break;
case PERROR:
printf ("Presentation Error\n");
break;
default:
printf ("Wrong Answer\n");
break;
}

}


int main ()
{
num = 1;
error = 0;
while (gets(temp) != NULL) {
keyl = temp[0]-'0';
if (keyl == 0) {
break;
}
keynuml = ansnuml = 0;

readinput();
if (error == 1) break;

check();

printout();

num++;
}
return 0;

}[/c][/c]

kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm

Post by kiha »

Hello,

after several submissions I got AC. I would add that the number of numerical characters in judge output and team output has to be the same!
Good luck those who get WA ...
kiha

b42
New poster
Posts: 1
Joined: Mon Aug 08, 2005 7:38 pm
Location: Coimbra, Portugal

correct output?

Post by b42 »

What is the correct output to this case:
2
The answer is:10
The answer is: 5
2
The answer is: 10
The answer is: 3
3
The answer is:10
The answer is: 5
The answer is: 1
3
The answer is: 10
The answer is: 3
The answer is: 2
3
The answer is:10
The answer is:5
The answer is: 1
3
The answer is: 10
The answer is: 5
The answer is: 2
0
I suppose that if the number of wrong answer is superior to the number of presentation error, the correct answer is WA.
And if the opossite occur the correct answer will be PE, right?

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: correct output?

Post by tan_Yui »

b42 wrote:What is the correct output to this case:
2
The answer is:10
The answer is: 5
2
The answer is: 10
The answer is: 3
3
The answer is:10
The answer is: 5
The answer is: 1
3
The answer is: 10
The answer is: 3
The answer is: 2
3
The answer is:10
The answer is:5
The answer is: 1
3
The answer is: 10
The answer is: 5
The answer is: 2
0
I could solve this problem just now.
Correct output for your input is the following :

Code: Select all

Run #1: Wrong Answer
Run #2: Wrong Answer
Run #3: Wrong Answer
And, following is the input which I prepared.
If you keep getting WA in your submissions, please try to check by them.
Input :

Code: Select all

3
     
     
     
3
          
          
          
2
ACM10188
2005November
2
ACM101
882005November
1
EndlessGame
2
Endless
Game
3
987
654
321
2
98765
4321
4
**********
* ********
* ********
**********
4
**********
******** *
******** *
**********
5
**********
* 0 ******
* 0 ******
* 1 ******
**********
5
**********
****** 0 *
****** 0 *
****** 1 *
**********
5
          
* 0 ******
* 0 ******
* 1 ******
          
3
* 0 ******
* 0 ******
* 1 ******
2
     
  7
2
     
  7
2
     
  8
2
  8
     
1

1

1

2


3



3


WA12
1
1 + 2 + 3 = 6
2
1 + 2 = A;
A + 3 = 6;
0
Output should be :

Code: Select all

Run #1: Presentation Error
Run #2: Presentation Error
Run #3: Presentation Error
Run #4: Presentation Error
Run #5: Presentation Error
Run #6: Presentation Error
Run #7: Presentation Error
Run #8: Accepted
Run #9: Presentation Error
Run #10: Accepted
Run #11: Presentation Error
Run #12: Wrong Answer
Run #13: Presentation Error
By the way, I think the description of this problem is incorrect.
Each input set begins with a positive integer n < 100, alone in a line, which describes the number of lines of the standard solution. The next n lines contain the standard solution. Then there is a positive integer m < 100, alone in a line, which describes the number of lines of the team output. The next m lines contain the team output.
At first, I define the limitation of the n and m to 99 because of n, m < 100.
Then I got 'Runtime Error'.
After changed 99 to 100, I could avoid 'Runtime Error'.

How do the people who challenged this problem think for this matter?

liangchene
New poster
Posts: 12
Joined: Thu May 19, 2005 6:07 am

Time limit exceeds (I checked all the test cases)

Post by liangchene »

#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>

using namespace std;
//ifstream cin("test.txt");

string input[100];
string output[100];
int counter=1;
bool pass;
string dummy;
string numerical1,numerical2;
int main()
{
int num1,num2;
int x,y;
char line[101];

while(1)
{
cin>>num1;
if (num1==0) break;

cin.getline(line,100,'\n');

for (x=0;x<num1;x++)
{
cin.getline(line,100,'\n');
input[x]=line;
}

cin>>num2;
cin.getline(line,101,'\n');
for (x=0;x<num2;x++)
{
cin.getline(line,101,'\n');
output[x]=line;

}

//accepted.
cout<<"Run #"<<counter++<<": ";

pass=true;

if (num1==num2)
{
for (x=0;x<num1;x++)
{
if (input[x]!=output[x])
{
pass=false;
break;
}
}
if (pass)
{
cout<<"Accepted";
}
}
else
{
pass=false;
}

if (pass==false)
{
numerical1="";
numerical2="";

for (x=0;x<num1;x++)
{
for (y=0;y<input[x].size();y++)
{
if (input[x][y]>=48 && input[x][y]<=57)
{
numerical1+= char(input[x][y]+48);
}
}
}

for (x=0;x<num2;x++)
{
for (y=0;y<output[x].size();y++)
{
if (output[x][y]>=48 && output[x][y]<=57)
{
numerical2+= char(output[x][y]+48);
}
}
}

if (numerical1==numerical2)
{
cout<<"Presentation Error";
pass=true;
}

}

if (pass==false)
{
cout<<"Wrong Answer";
//find the numberical values.
}

cout<<endl;
}

system("pause");
return 0;
}

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: Time limit exceeds (I checked all the test cases)

Post by tan_Yui »

Hi, liangchene.
I believe your code was failed because of Output Limit Exceeded not TLE.

Problem statement.
No line will have more than 120 characters.
Change according to it, you will get Accepted.

Best regards.

liangchene
New poster
Posts: 12
Joined: Thu May 19, 2005 6:07 am

Post by liangchene »

??? the problem says "No line will have more than 100 characters."

Post Reply

Return to “Volume 101 (10100-10199)”