0

I posted it before, but it got closed, I hope I fixed it.

I wrote a solution in google kickstart 2021 round C "Aliens Generator" problem. The problem is that my solution works perfectly fine in the Code Blocks IDE, but the kickstart environment returns a runtime error when given the same set of input data. Google Kickstart platform didn't provide any message with the error.

Link to the problem: https://codingcompetitions.withgoogle.com/kickstart/round/0000000000435c44/00000000007ec1cb

My code in C:

#include<stdio.h>

int main(){
    int T;
    int G;
    int x;
    int y;
    scanf("%d",&T);
    for(x=1; x<=T; x++){
        scanf("%d",&G);
        y=1;
        for(int k=1; k<G/2.0; k++){
            if((2*k-1)*(2*k-1) + 8*G > 0 ){
                float d = sqrt((2*k-1)*(2*k-1)+8*G);
                if(d==floor(d) && (1-2*k+d)>0 && (1-2*k+(int)d)%2==0){
                    y++;
                }
            }
        }
        printf("Case #%d: %d\n", x, y);
    }
    return 1;
}

Input:

5
4
5
6
9
15

Related output obtained in the Code Blocks IDE:

Case#1: 1
Case#2: 2
Case#3: 2
Case#4: 3
Case#5: 4

The Kickstart platform returnes a Runtime Error with no messages.

Andrze
  • 11
  • 4
  • `d==floor(d)` comparing float values is usually not a good sign. See [What is the most effective way for float and double comparison?](https://stackoverflow.com/questions/17333/what-is-the-most-effective-way-for-float-and-double-comparison?page=2&tab=active#tab-top). That's a C++ question but the issue is generic - using the equality operator is not guaranteed to produce the right result for floats. – kaylum Aug 06 '21 at 00:49
  • Are you sure it used the same data? Usually these sites use really big inputs to see if your program exceeds the time limit - and exceeding the time limit is a common reason for a runtime error. – Jerry Jeremiah Aug 06 '21 at 02:31
  • Your code has two loops so has a runtime of O(GT) but on the page you linked under the analysis tab they say that binary searching can speed it up to O(G log(G)) so I figure you are exceeding the time limit for large inputs. – Jerry Jeremiah Aug 06 '21 at 02:35
  • 1
    If you write `return 0`, instead of `return 1`, then it is not giving a runtime error. – Mahedi Kamal Aug 06 '21 at 03:33
  • If your former question was closed, there is a hint what to do to get it reopened. There is no need to post the same issue again. You might like to repeat the [tour] to refresh your understanding how this site works. – the busybee Aug 06 '21 at 06:19
  • Huge thx to @MahediKamal, I feel silly now. – Andrze Aug 07 '21 at 07:31
  • @thebusybee this is what i tried to do, no that much of a hint though. All i got is: [quote]This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.[quote] I edited the question, but it didn't trigger any actions, Moderator didn't sign his work and i couldnt find any links that would ask for a review of changes I made. Link that you included in your comment does't clarify much in this matter either. – Andrze Aug 07 '21 at 07:31
  • Well, there is not a single moderator that decides whether to close or reopen a question. It all depends on multiple community members, and if enough votes for either action are given, the action takes place. Your question will not really be forgotten, it will be on one of the queues to work on. So, to get one of your questions reopened, "repair" according to the comments and hint, and hope the best. This is how this site works. – the busybee Aug 07 '21 at 14:35

0 Answers0