Problem: 433B - Kuriyama Mirai's Stones
This is my solution: 11326002
I use partial sums for initial array and then for sorted. Don't understand where can be a bottleneck.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Problem: 433B - Kuriyama Mirai's Stones
This is my solution: 11326002
I use partial sums for initial array and then for sorted. Don't understand where can be a bottleneck.
Name |
---|
Your approach and implementation of the problem are correct but you seem to use scanner class for taking input which is slow (though i am not a regular JAVA user but that is the only fault i can find in your code) . Try to use faster I/O methods. I think it will get accepted after that because your approach and implementation are correct. For faster I/O you can refer to codes of top rated coders who use JAVA as their language.
Oh, thank you very much. I think you are right. I even forgot about FastScanner.
The bottleneck is quite well-known. Should not use Arrays.sort for primitive types.
http://mirror.codeforces.com/contest/433/submission/11329247
And so how to sort arrays?
Shuffle before sorting or use Objects.
How shuffling can help in this case? Arrays.sort function never wraps primitive type in Integer/Long objects.
There is a testcase where the sort is O(n2). If you do not shuffle then of course you are going to get O(n2) perfomance. But if you shuffle the probability that your array is the same as the testcase is very very small.
Ok. Now it looks more rationally :-)
Even changing array of int's to ArrayList did help. I have 717ms at max test now. For me it's really very strange.
Collections.sort is O(nlogn) in the worst case.
The source code of Collections.sort http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/Collections.java?av=f#153 I see that is uses Arrays.sort in its implementation
I will answer here.
Because ArrayList is a list of Objects. You can't create ArrayList< int >.