| Show all threads Hide all threads Show all messages Hide all messages |
| Proof of solution | Ilian | 1082. Gaby Ivanushka | 21 Aug 2013 22:07 | 1 |
Everybody who knows quick sort will recognize that the tsar's program is quick sort of N numbers. Let we have a sorted array with n numbers. Let l-r+1=k. Then function P() will increase the value of c by k+1 because it will visit all x elements to distribute them into part smaller than or equal to x and part greater or equal to x. That increases c by k. But the i and j iterators must be equal so there is also one additional increase of c. Because we have a sorted array function P() will partition him into part consisting of 1 element and part consisting of l-r elements. The part consisting of 1 element will be ignored and there won't be any increase of c. In the part with l-r elements it will do the same - partitioned it into 1 and l-r-1. So let begin with l-r+1=N. Then the function Q() will go to l-r+1=N-1 and so on to l-r+1=2. For those calls of function Q() c will be increased with: N+1 + N + N-1 + ... + 5 + 4 + 3 = (N+1)*(N+1+1)/2 - 1 - 2 = N*N + 3*N + 2/2 - 3 = =N*N + 3*N + 2 - 3*2/2 = N*N + 3*N - 4 / 2. So if we give a sorted array to the tsar's program it will print what we want. What is more, we prove that for sorted array quick sort is very bad algorithm with such bad complexity. Note: If the median element was chosen in a different way the solution won't be so easy. But it can be done if we try all permutations of array with elements from [1;n] and check for c. Edited by author 21.08.2013 22:19 |
| WA #5 | R. Dubinin | 1869. New Year Cruise | 20 Aug 2013 17:50 | 1 |
WA #5 R. Dubinin 20 Aug 2013 17:50 please give me some tests |
| Pascal Compilation error. Why? | Michael | 1820. Ural Steaks | 20 Aug 2013 16:38 | 1 |
It works on my laptop! I have Pascal ABC. var a,b,c:integer; begin readln(a,b); if a>b then c:=ceil(2*a/b) else c:=2; write(c); end. |
| Thanks a lot for author! Very fun problem! | EfremovAleksei | 1540. Battle for the Ring | 20 Aug 2013 00:14 | 4 |
It's the 3rd day I'm trying do break that "fun"... :D can anyone provide any idea? I personally solved in a bruteforce manner with DSU. |
| Как это решать? | AlexDevyatov | 1784. Rounders | 19 Aug 2013 16:50 | 2 |
|
| WA 19! Somebody, help me, please! | ONU_Antananarivu | 1635. Mnemonics and Palindromes | 19 Aug 2013 13:38 | 2 |
Edited by author 08.09.2011 17:57 Give me your code ! I also WA 19,but I find write wrong dp[i]>dp[j-1]+1 to dp[i]>dp[j]^…… |
| Cantonese is hard to learn | raven | 1964. Chinese Dialects | 19 Aug 2013 00:11 | 1 |
|
| wa #2 | ahmet terzi | 1068. Sum | 18 Aug 2013 19:03 | 2 |
wa #2 ahmet terzi 25 Aug 2012 15:05 what's wrong in my code: #include <stdio.h> main() { int a; scanf("%d",&a); if( a >= 0 ) printf("%d",a*(a+1)/2); else { a = -a; printf("-%d",a*(a+1)/2-1); } return 0; } Edited by author 25.08.2012 15:05 Edited by author 25.08.2012 15:06 If a is 0,the answer IS 1, not 0. |
| WA31 why? | zzyzzy12 | 1558. Periodical Numbers | 18 Aug 2013 15:17 | 2 |
ok...Im AC now...if u wa , u can try this data (13681872) (95650177) ans=(50093320)49 |
| WA9 | PrankMaN | 1795. Husband in a Shop | 18 Aug 2013 02:42 | 1 |
WA9 PrankMaN 18 Aug 2013 02:42 I had a stupid mistake Instead of: shop[want] -= q[r].amount; I had: shop[want] = q[r].amount; |
| Problem 1116 "Piecewise Constant Function" has been rejudged. | Sandro (USU) | 1116. Piecewise Constant Function | 17 Aug 2013 14:42 | 1 |
New tests were added, and time limit was decreased to 0.5 sec. 183 authors lost AC after rejudge. |
| To admins. | szczepi | 1116. Piecewise Constant Function | 17 Aug 2013 11:49 | 3 |
I think that second test contains line which begins with 0. This case is not allowed because in problem statement is written that (1 ≤ N ≤ 14999). Please check if I'm right. In one of my solution I checked (using assert from cassert) if N is greater than 0 and I received WA2. When I removed assert I've received AC. |
| a test for wa 8 | binwin20 | 1424. Minibus | 17 Aug 2013 08:12 | 1 |
|
| A good optimize! | moji | 1147. Shaping Regions | 16 Aug 2013 21:07 | 1 |
My solution way getting TLE - on test 32 - while my complexity was O(n ^ 2) I think; but by changing some parameters - coordinates for example - from int to short int, (a 4 byte variable to a 2 byte one) got AC in .3 s. I thought may help you! Good luck :) |
| Как на самом деле должна звучать задача! | gwire | 1083. Factorials!!! | 16 Aug 2013 19:08 | 2 |
Определение: n!!…! = n(n−k)(n−2k), где k - количество знаков "!". При расчете на любом этапе не должно получатся отрицательного числа. И все. Я только с таким условием получил "Accepted". Спасибо. Условие было действительно странное и непонятное, а, как показала практика, так ещё и неправильное. |
| Time limit on Test 2 Help. (C++) | Ivailo | 1021. Sacrament of the Sum | 16 Aug 2013 12:36 | 3 |
Where do I have a problem? I used binary search and got time limit on test 2. But when I use N*N1 speed I pass test 2 and get time limit on test 10. Can you please check my code. I believe it is correct. #include <iostream> using namespace std; bool binary_search (long* b , long a , long from ,long to) { while (from != to) { long mid = (from + to )/2; if (b[mid] + a == 10000) return true; if (b[mid] + a > 10000) { from = mid; } if (b[mid] + a < 10000) { to = mid; } } return false; } int main () { long n , n1; long* a , *b; cin >> n; a = new long[n]; for (int i =0 ; i < n ; i++) { cin >> a[i]; } cin >> n1; b = new long[n1]; for (int i =0 ; i < n1 ; i++ ) { cin >> b[i]; } bool tr = false; for (int i = 0 ; i < n ; i++) { tr = binary_search (b , a[i] , 0 , n1); if (tr) break; } if(tr) cout << "YES"; else cout << "NO"; } "Where do I have a problem?" You've got TLE. That is a problem Ok my bad. Why do I get TLE when I use binary, but don't get TLE when I use n1*n? Isn't binary faster? |
| I need help(WA 17) | Mad man | 1011. Conductors | 15 Aug 2013 20:42 | 8 |
I do not see error here, but didn't pass the 17'th test var p,q: extended; a,b: longint; BEGIN read(p,q); p:=p/100; q:=q/100; a:=1; while (true) do begin b:=1; while (a/b>=q) do inc(b); if (a/b>p) then begin write(b); halt(0); end else inc(a); end; END. Me, too. I'm getting insane. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!! Use epsilon! Instead of >= q and > p use >= q-eps and > p+eps and you'll get AC. Good luck! ;) ??? Use epsilon! Instead of >= q and > p use >= q-eps and > p+eps and you'll get AC. Good luck! ;) who can say me, what is epsilon??? how to use it Thank You!!! I got AC!!! with eps! |
| How to get AC | Ilian | 1007. Code Words | 15 Aug 2013 16:57 | 1 |
I read some previous topics because my soluton was getting WA1. I tried this test which was Leo's test with some empty lines: 4 0 00 0 0 11 10 1 1 11 011 And then I fixed my program. Edited by author 15.08.2013 16:58 Edited by author 15.08.2013 16:59 |
| Test #3 -Time limit exceeded (C#) | Arantir | 1209. 1, 10, 100, 1000... | 14 Aug 2013 15:52 | 3 |
Why it is so slowly??? I use standard formula with "sqrt(8*N-7)". int L = int.Parse(Console.ReadLine()); string answer = ""; for (int i = 0; i < L; i++) { if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 "; else answer += "0 "; } Console.Write(answer); I can't imagine shortest solution... What's the matter? Many people has used C# successful in problem 1209. Edited by author 28.11.2011 03:09 I don't know c# but I think it's correct. why you don't use c++? Why it is so slowly??? I use standard formula with "sqrt(8*N-7)". int L = int.Parse(Console.ReadLine()); string answer = ""; for (int i = 0; i < L; i++) { if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 "; else answer += "0 "; } Console.Write(answer); I can't imagine shortest solution... What's the matter? Many people has used C# successful in problem 1209. Edited by author 28.11.2011 03:09 Compare with this code static void Main(string[] args) { int len = int.Parse(Console.ReadLine()); int[] mas = new int[len]; int max = 0; for (int f = 0; f < len; f++) { mas[f] = int.Parse(Console.ReadLine()); if (mas[f] > max) max = mas[f]; } foreach (long i in mas) { double ig = (Math.Sqrt(8*i-7))%1; if (ig == 0) Console.Write("1 "); else Console.Write("0 "); } } |
| It`s absolutely amazing problem! | I_love_alyona | 1737. Mnemonics and Palindromes 3 | 14 Aug 2013 15:16 | 1 |
|