I tried today’s Google Kick Start round F problem 1(ATM Queue). I wrote a code which I will attach below. When I ran it on my laptop to verify if sample cases were running fine, I got the right answer. Then I submitted the solution on Google Kick Start site and I got Sample Failed:WA . When I ran the given sample input on their site, I got a different output than what I got on my local machine. Can anyone tell me what might be the reason for this.
The outputs on my machine and google server are as follows:
for case in range(1, int(input())+1):
n,x=map(int,input().split())
people=list(map(int, input().split()))
order=[]
if not any(i>x for i in people):
print(people)
continue
people={people.index(i)+1:i for i in people}
while len(list(people.keys()))>0:
k=list(people.keys())[0]
j=people[k]
if j<=x:
order.append(k)
people.pop(k)
else:
people[k]=(people.pop(k))-x
print("Case #{}: {}".format(case," ".join(list(map(str, order)))))
I do not use python, but one common mistake for getting different output on two different servers, on the same input is declaring an array/integer without any value in it
Eg.
int n; //declaring n as an integer
cin >> n; //inputting n
int a[n + 1]; //declaring an array of length n+1
cout << a[0] << endl; //outputting a[0]
The above code can give 0 as a result, and some other garbage value on another server too.
The key here is to initialize all the array values with 0 or any other suitable integer.
So
for(int i = 0; i <= n; i++) { //for loop from 0 to n
a[i] = 0; //initializing a[0], a[1], a[2]....a[n] to 0
} //end of for loop
This code does the work.
If this wasn’t your problem, ignore this reply please xD.
Hi @aryan12
I appreciate your help but there is no concept of garbage value in Python. With Python, we need not worry about the garbage value thing like in C++.
nop, that’s what I’m I telling, the order the items present in the dictionary may be not the same in your machine than in judge system. It’s just a casuality that for this particular testcase your dict arrange the items in such a way that the answer is correct but I will not work on other testcases or other systems configurations