445 - Marvelous Mazes

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

Moderator: Board moderators

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

445 > Time Limit Exceeded

Post by _.B._ »

Greetings!.
I'm trying to solve Problem 445 in Free Pascal, but I got the "Time Limit Exceeded" response for it.
There is no limit to the number of rows in a maze or the number of mazes in a file, though no row will contain more than 132 characters.
Which rows contain no more than 132 chars?, the INPUT rows?, or the output rows??.
And also, could any of you show me a good input/output for this problem?.
Thanks in advance!.
osan
New poster
Posts: 47
Joined: Tue Jul 29, 2003 12:03 pm
Location: Bangladesh,Dhaka.
Contact:

Post by osan »

you could take input by using gets.

for get input by using gets.

you can write like that:

gets (str);
gets can hold space.
& ur 1st while don't break in right time
this time WA
what next...............?
Dejarik
New poster
Posts: 32
Joined: Sun Mar 07, 2004 1:23 pm
Location: Barcelona, SPAIN
Contact:

445 - Why Output Limit Exceeded??

Post by Dejarik »

I'm not a supporter of posting code in the board. However in this case the code works correct in my computer but i don't know what can i do to solve the Output Limit Exceeded received in my submissions of problem 445 - Marvelous Mazes.

I've never found this error in my other programs, and I cannot find the mistake in my implementation. Please help!

[c]#include <stdio.h>
int main(){
char source[132];
int total;
int i,ind,lon;
while(scanf("%s",source)!=EOF){
total=0;
lon=strlen(source);
for(ind=0;ind<lon;ind++){
if(isdigit(source[ind])){
total=total+atoi(&source[ind]);
}else if(source[ind]=='b'){
for(i=0;i<total;i++) printf(" ");
total=0;
}else if(source[ind]=='!'){
if(ind<lon-1)printf("\n");
total=0;
}else{
for(i=0;i<total;i++) printf("%c",source[ind]);
total=0;
}
}
printf("\n");
}
}[/c]

Thanks in advance! Joan
CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: 445 - Why Output Limit Exceeded??

Post by CDiMa »

Dejarik wrote:I'm not a supporter of posting code in the board. However in this case the code works correct in my computer but i don't know what can i do to solve the Output Limit Exceeded received in my submissions of problem 445 - Marvelous Mazes.
Probably you didn't check for a particular type of input. What's strange is that the sample input has such a case, probably you didn't notice that. Anyway here is the problem statement:
If there are multiple digits in a number before a character, then the number of times to repeat the character is the sum of the digits before that character.
Your program doesn't handle this case correctly:
Dejarik wrote:[c]
for(ind=0;ind<lon;ind++){
if(isdigit(source[ind])){
total=total+atoi(&source[ind]);[/c]
atoi converts a string to an integer. This is not what you want!
For example in the sample input you have
11X21b1X
Your program will write 11+1 X, 21+1 blanks and 1 X instead of 2 X, 3 blanks and 1 X

Ciao!!!

Claudio
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

There's a post further down that answers that question.

By the way, before switching to Free Pascal I solved this with Turbo Pascal
(got a Presentation Error, though, no idea why).

Why don't you read the input on a character by character basis?
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Thanks.

Post by _.B._ »

Thanks WR!.
Betty wrote:i have a feeling that the 132 size limit was on the width of the maze not the input.
I already read char by char in this one, but will check for anything else.
Keep posting!.
_.
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

The main loop starts with
[pascal] while not eof(input) do begin
read(input,ch);[/pascal]

and I'm treating "!" and line feed alike, so [pascal]if ((ch = '!') or (ch = #10)) then
writeln(output)[/pascal]
Maybe that could be one reason for the presentation error???
Anyway I think the carriage return should be simply ignored.

Hope it helps.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Finally AC!.

Post by _.B._ »

Greetings.
Got me AC!.
WR, I am using now eoLn and eoF instead #13 / #10 or #26, and getting ACs in problems I used to have TLE or WA.
Your PE might be because of printing one extra line at the end of the output. It happened to me a couple of times, but now I do stuff like
[pascal]if not eoF then
writeLn;[/pascal]
or so, if necessary.
Thanks again!.
_.
Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Problem 445 (Marvelous Mazes)...Output Limit Exceeded

Post by Ferdous »

I can't understand why I am getting "Output Limit Exceeded", this is new for me. I would be glad if someone can help me. Here's my code:

deleted later.....
Last edited by Ferdous on Wed Mar 16, 2005 7:42 am, edited 1 time in total.
I am destined to live on this cruel world........
Dejarik
New poster
Posts: 32
Joined: Sun Mar 07, 2004 1:23 pm
Location: Barcelona, SPAIN
Contact:

Post by Dejarik »

The problem is in your gets() call.

Replace:

Code: Select all

while(gets(str)){
with:

Code: Select all

while(scanf("%s\n",&str)==1) {
should work.

Good luck,
Joan
Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

In problem description it's stated that
Descriptions for different mazes will be separated by a blank line.
How can I detect the blank line while taking input with the help of scanf()?
I am destined to live on this cruel world........
JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

445 wrong sample output or incorrect judgement

Post by JiaYun »

output the same with sample output got PE

http://acm.uva.es/p/v4/445.html

Code: Select all

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T
 
XX   X
XXXX X<end of line>
this one got AC

Code: Select all

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T
 
XX   XXXXX X<no end of line>
I opine that the judgement is incorrect, because of this description in problem.

Code: Select all

The descriptions for different rows in the maze will be separated by an exclamation point (!), or by an end of line.
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

My program does the same thing. PE w/ sample. AC w/o the newline.
RustB
New poster
Posts: 16
Joined: Mon Jun 14, 2004 5:08 pm

445 Marvelous Mazes Sample I/O needed

Post by RustB »

My program seems to work fine with the test input, but fails with the OJ (W.A.)

Can anyone please give me some sample input and the ouput for this problem?
Cahoun
New poster
Posts: 13
Joined: Mon Jan 03, 2005 2:34 pm
Location: Czech Republic
Contact:

445 - Nightmare

Post by Cahoun »

I spend 12 hours of my life to fix a mistake of this problem. I got every time Presentation Error. I solved this problem correctly. But I want Accepted answer not Presentation Error. I use method by array and spaces, ! and \n(new line) and every time I got only Presentation Error. I used 132 characters lines. But I didnt find solution to Accepted answer. I am really unhappy and Can anyone tell me some new idea of solution to get Accepted this problem?
I got about 30 Presentation Error and I used method to solve in this thread but I got Presentation Error.

OT: Some links on http://acm.uva.es/problemset/ page are broken in section HOWTOs. It will be good to fix it.
Learn, learn, learn.
Post Reply

Return to “Volume 4 (400-499)”