Maybe your algorithm is not optimized enough?
Salut Ă tous! Je suis nouveau sur CG. Yâa des tests supplĂ©mentaires dans horse-racing, je ne sais pas comment les passer. Qcqn a une iddĂ©e?
Hi there !
Is someone using Kotlin for this puzzle ?
I passed all the tests except the âhugeâ onesâŠ
It seems that I canât even store the int in array without timeout.
this code :
for (i in 0 until N) {
//val pi = input.nextInt()
lesdadas+= input.nextInt()
}
without anything else make a timeout.
Is someone succeed in Kotlin?
thanks
I wanted to make a liste with the pi
I putted
10. liste.append(pi)
but it doesnt work, I got the message
SyntaxError: Non-ASCII character â\xc3â in file Answer.py on line 10, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
at Answer.py. not in a function on line 10
someone can explain ??
Did you try to use a non-ASCII character in Python 2?
what 's non ASCII character (sorry Im begginer)
Something like Ă©, @ ??
No I didnt
Ok I found the problem. It was because I putted : " # We create a liste ".
I delete it and it worked.
But I dont understand whyâŠ
Nothing special in â# We create a listeâ but maybe you printed an no-break space.
Iâve used lists instead of arrays and it worked. This is the only difference between your algo and mine.
Aaaaaaarg ! I just did it and itâs fine !
Thanks a lot !
Hello , can i get the validator test by private message too. I am facing the same error for âShorter difference on the first 2 horsesâ. Thanks
Hi guys, just solved this in java. But found an odd misbehavior of the iteration through array list via for cycle.
See here :
import java.util.*;
import java.io.*;
import java.math.*;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
ArrayList<Integer> powers = new ArrayList<Integer>();
for (int i = 0; i < N; i++) {
int pi = in.nextInt();
powers.add(pi);
//DEBUG
//System.err.println(pi);
}
//sort numerically
Collections.sort(powers);
// go through array, remembering the smallest differnce
int diff = -1, prev = -1;
int curr = -1;
for (int i = 0; i < N-1; i++) {
// for (int curr : powers) {
//DEBUG
//System.err.println(curr);
prev = powers.get(i);
curr = powers.get(i+1);
//first horse
if (prev == -1) {
prev = curr;
}
else
//second horse
if (diff == -1) {
diff = curr - prev;
prev = curr;
} else
// third and more ....
if (curr - prev < diff) {
diff = curr - prev;
prev = curr;
}
}
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
System.out.println(diff);
}
}
When I try to use the iteration (commented out) via the for (item : array) construct, then the 3rd test fails by giving different result than it is supposed to. First 2 tests work normally.
Hello, Iâm using C and I get time out at many horses and numerous horses.
I used Quicksort and single for loop comparison everything in itâs own function.
Hi
Iâm using C# and I canât do the last one of the many horses it says it takes to much time.
Using 2 for loops to search na array with the values.
HELP PLS!
Hi, I also used Quicksort and then a loop iterating over all sorted values to find the lowest difference. I failed the last test at first then I changed the way i choose my Pivot element to be the median of three values, for those values i chose index 0, index size - 1 and index size / 2 then it worked out for me. btw i was using c++
Hey,
In JS, I obtain a difference in power that is less (30) than the one the test suggests (47). Is this a bug ?
Best.
Hi, I am desperately trying to understand why this code get the segmentation fault error when I test it. As a noob trying to learn, I d like to understand why, more than to find a workaround without first a comprehension of the error.
Thanks for any help!
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
int N;
vector <int> MyN(N);
cin >> N; cin.ignore();
for (int i = 0; i < N; i++) {
int Pi;
cin >> Pi; cin.ignore();
MyN[i]=Pi;
}
sort(begin(MyN), end(MyN));
int minSpace = 10000000;
int currentSpace = `Preformatted text`0;
for (int i = 0; i < N-1; i++)
{
currentSpace = MyN[i+1]-MyN[i];
if (currentSpace > minSpace)
{
minSpace=currentSpace;
}
}
cout << minSpace << endl;
//action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
}
hey, why cant i use Arrey.sort?
maybe because it is âArray.sortâ ?
Possibly because you initialize myN before you have read N, so the value of N is random and may exceed the allowed memory size.