1
I wrote the code below to solve the problem 1112 from the site Urionlinejudge and apparently the logic employed is perfect, but I’m getting an error of time exceeded. I’m having trouble identifying the error. It appears to be in the first scanf(), since when I run the program I can type an endless sequence of 0’s and spaces that the program will only return zero and end when the ENTER key is pressed, but I don’t know what to do for it, when you read 3 consecutive zeroes in the first entry, now close. I believe that it is necessary that, when reading these three data, even without pressing the ENTER key, the program already closes if there are three zeros.
#include <stdio.h>
int main (){
int X, Y, P, Q;
int i, j, k, l;
char carac;
while(1){
scanf("%d %d %d", &X, &Y, &P);
if(X==0 && Y==0 && P==0){
return 0;
}
int campo[X][Y];
for(i=0;i<X;i++){
for(j=0;j<Y;j++){
campo[i][j]=0;
}
}
scanf("%d", &Q);
int N=0, Z, W, qtd;
for(i=0;i<Q;i++){
qtd=0;
scanf(" %c", &carac);
if(carac=='A'){
scanf("%d %d %d", &N, &X, &Y);
campo[X][Y]+=N;
}
else{
scanf("%d %d %d %d", &X, &Y, &Z, &W);
for(j=X;j<=Z;j++){
if(Y>W){
l=Y;
Y=W;
W=l;
}
for(k=Y;k<=W;k++){
qtd+=campo[j][k];
}
}
printf("%d\n", qtd*P);
}
}
}
}
I opened the link, took a look at the problem and noticed that at the top of the page there is the indication of a maximum time limit: "timelimit 4". That is, probably, the problem is not in the code and you have simply run out of time to present the solution.
– user142154