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.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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.
Название |
---|
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://codeforces.me/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 >.