| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| A good optimize! | moji | 1147. Цветная бумага | 16 авг 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. Факториалы!!! | 16 авг 2013 19:08 | 2 |
Определение: n!!…! = n(n−k)(n−2k), где k - количество знаков "!". При расчете на любом этапе не должно получатся отрицательного числа. И все. Я только с таким условием получил "Accepted". Спасибо. Условие было действительно странное и непонятное, а, как показала практика, так ещё и неправильное. |
| Time limit on Test 2 Help. (C++) | Ivailo | 1021. Таинство суммы | 16 авг 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. Кондукторы | 15 авг 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. Кодовые слова | 15 авг 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 авг 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. Мнемоника и палиндромы 3 | 14 авг 2013 15:16 | 1 |
|
| What's the problem mean? | laughinghao | 1230. Интроспективная программа | 14 авг 2013 13:12 | 2 |
what is the problem's requirement? |
| I don't think this is a good problem. | Element | 1380. Остаповские шахматы | 14 авг 2013 13:11 | 2 |
Bad statement and poor testdata. |
| Runtime error | Mukund | 1001. Обратный корень | 14 авг 2013 13:10 | 2 |
Hi I am getting a runtime error. Is thr a way to check in which line and what the error is/ Regards Mukund |
| Wrong Answer - test 6 | Viktor Serov | 1970. 皇后像廣場 | 14 авг 2013 12:38 | 2 |
Give a clue - why? Edited by author 14.08.2013 00:48 |
| WA case 6 | Paul Cruz | 1263. Выборы | 12 авг 2013 13:32 | 2 |
#include <iostream> #include <cmath> #include <fstream> #include <sstream> using namespace std; int main(){ int n; int m; cin >> n; cin >> m; //double md=6.6; double votes[10001]; for(int i=0;i<m;i++){ int k; cin >> k; votes[k-1]++;
} for(int i=0;i<n;i++){ double chance = (double)votes[i]*100/m; printf("%2.2f",chance); cout << "%" << endl; } } why do i have WA on case 6? I'm stuck before using array add these lines: for(int i=0; i<n; i++) votes[i] = 0 |
| AC java | d_anconia | 1567. SMS-спам | 12 авг 2013 04:51 | 1 |
AC java d_anconia 12 авг 2013 04:51 import java.util.*; public class Test{ public static void main(String [] args){
Scanner scan = new Scanner(System.in); String s = scan.nextLine(); char c [] = s.toCharArray(); int sum = 0; for(int i=0;i<s.length();i++){ switch(c[i]){ case 'a':case'd':case 'g':case 'j':case 'm':case 'p':case 's':case 'v':case 'y':case '.':case ' ':sum=sum+1;break; case 'b':case'e':case 'h':case 'k':case 'n':case 'q':case 't':case 'w':case 'z':case ',':sum=sum+2;break; case 'c':case'f':case 'i':case 'l':case 'o':case 'r':case 'u':case 'x':case '!':sum=sum+3;break; } } System.out.println(sum); } } |
| Solution | Carbon | 1452. Pascal против C++ | 12 авг 2013 04:17 | 6 |
Sorry for my impudence but my AC program has O(N^2*ln(N)) and takes 234 ms with GREAT optimization (and with memory too). Your solutions (by velocity characteristics) has O(N^2) difficulty and O(N) memory. First, we should watch all differences between elements (O(N^2)) and then find greatest sequence (O(ln(N))). In process of finding such sequence we should know all differences (O(N^2) memory). Am I mistaken in something? Could you tell me, in what destination I should think to get quick solution. I have thought up O(N^2) algo! Now time is 0.109 ms. But it eats O(N^2) memory:( Edited by author 28.07.2016 15:40 I only store N minimal differences, initially a1-a0,a2-a1,...,a(n-1)-a(n-2) (given a0..a(n-1) sorted sequence). Store it in heap (pyramide), get top (minimal) difference and change it from a(j)-a(i) to a(j+1)-a(i) and push down to the heap's bottom. My N*N*logN runs in 0.125 |
| Best complexity | Furtuna Dan Emanuel | 1395. Pascal против C++. Версия 2 | 12 авг 2013 03:58 | 4 |
Can you please tell me the time complexity of the official solution? I now have a correct program that works in about 0.7 seconds and a wrong one that got AC in 0.234 sec. Complexity of my solution also can not be defined strictly but I believe it is not slower than O(N^2)... Edited by author 05.11.2008 00:01 Edited by author 05.11.2008 00:02 How do u know it is impossible to find faster than O(N^2) |
| I got AC 0.093 48 Kb. No random | Furtuna Dan Emanuel | 1219. Symbolic Sequence | 11 авг 2013 21:55 | 5 |
var i:longint; function car(k:longint):char; begin car:=chr(k+ord('a')); end; begin for i:=0 to 333332 do begin write(car((i div 676) mod 26),car((i div 26) mod 26),car(i mod 26)); end; write('a'); end. I got AC 0.078 25 Kb var i:longint; begin for i:=1 to 333333 do write(chr(97+((i div 676) mod 26)),chr(97+((i div 26) mod 26)),chr(97+(i mod 26))); write('a'); end. Thank you,it's really amazing!!!!!!!!!! me too. forn(26) fornj(26) fornk(26) { if (i == j && j==k) continue; if (M[i][j][k]) continue;
M[i][j][k]=true; M[k][i][j]=true; M[j][k][i]=true; //and stuff here; } } |
| But, Why it work? | Denis | 1082. Иванушка-дурачок | 11 авг 2013 20:02 | 7 |
The 1st time P is called, c is increased by N+1 The 2nd time P is called, c is increased by N The 3rd time P is called, c is increased by N-1 ... The (N-1)th time P is called, c is increased by 3 So, the final value of C is (sum of A.P.) ((N+1)+3)*(N-1) div 2 =(N*N+3*N-4) div 2 But I really don't know how it's thought out. Thanks for your comments. Here is what I thought: ** I see it is quicksort ** I know that when the input is sorted, quicksort become a bubblesort(only one side is split each time), that make it easier to think about ** then, use recursive function which fill the entire array, and the result is just a sorted array. If start from 1, it will be 1 2 3 4 .......N But you provide a math provef of how they match:) What a wonderful explanation! Edited by author 06.01.2008 17:36 The 1st time P is called, c is increased by N+1 The 2nd time P is called, c is increased by N The 3rd time P is called, c is increased by N-1 ... The (N-1)th time P is called, c is increased by 3 I don't get it how You came to this analysis? Did You write a program to get how much is c increased the 1st the 2nd and the 3rd time? Why is P called N-1th times? Can somebody please explain me how QS works - I know it divides the array in left:medium:right But I guess medium is just always only one element. Am I correct? Please enlighten me. Thanks ... Edited by author 03.03.2011 16:54 Edited by author 03.03.2011 16:54 Hi, The iteration stops always after 3 comparisons for the pivot element in quicksort. Hence last element of AP is 3. First time iteration is always (N+1). Now number of elments of AP is N-1. Thus the formula proves to be true. Regards Anupam In an ideal case first you should have paid attention to N*N in c's expression. then u realize that answer should be some of the wort-case inputs for QS (one of which being already sorted array). then u copy the procedure and check ur hyphothesis for all N = 1 to 1000. no need to think it over really. |
| Help, please. p1387 - Vasya's Father. | Victor Barinov (TNU) | 1387. Папа у Васи | 11 авг 2013 16:38 | 5 |
What is answer for n = 8? Mine is 117, but I have WA on test #8. I can't find a mistake in my code :( Thanks! I have WA#8 too. Where was your mistake? Some values I calculated: "1", "1", "2", "4", "9", "20", "49", "117", "297", "746", "1947", "5021", "13378", "35237", "95123", "254825", "694987", "1882707", "5184391", "14177587", "39289183", "108337723", "301997384", "837774846", "2347293253", "6546903307", "18417850843", "51617715836", "145722478875", ... right is 1, 1, 2, 4, 9, 20, 48, 115,.. My mistake was for n = 7: Your think that there f(7) = f(6) + f(5)*f(1) + f(4)*f(2) + f(3)*f(3) + f(4)*f(1)*f(1) + ... But correct is: f(7) = f(6) + f(5)*f(1) + f(4)*f(2) + f(3)*(f(3)+1)/2! + f(4)*f(1)*(f(1)+1)/2! + ... so we will take not f(3)*f(3) = 2*2 = 4, but f(3)*(f(3)+1)/2! = 2*(2+1)/2! = 3, and f(7) = 48. Edited by author 04.11.2005 18:12 Thank you (+) UXMRI: Sergey Baskakov, Raphail Akhmedisheff and Denis Nikonorov 14 ноя 2005 16:29 Thank you very much for your hint! It turned out to be very-very useful for me. Without it I would have spent many hours debugging... can you let me see you code ? i just can not ac it ,,,thanks,,, |
| What is mean of "any three consecutive digits"? | stat958 | 1586. Трипростые числа | 11 авг 2013 12:09 | 2 |
" Pasha calls an integer a threeprime number if any three consecutive digits of this integer form a three-digit prime number"? For example,if a number a1a2a3a4, a1a2a3 is a prime number ,the number a2a3a4 must be a prime number?? yes or no, please help me! thank you ! yes. In general: For an n-digit number = a(1)a(2)a(3)a(4)...a(n-1)a(n) define p(i) = 3-digit number a(i)a(i+1)a(i+2) where 1 <= i <= n-2. Then each p(i) has to be a prime number *AND* for each p(i) holds: 100 <= p(i) <= 999 Edited by author 11.08.2013 12:11 |
| If "wheel can be rotated only counter-clockwise" | ძამაანთ [Tbilisi SU] | 1370. Волшебник | 11 авг 2013 03:47 | 1 |
then how the heck does it happen that "after one click the first digit will go out of site and the 11-th digit will become visible." Edited by author 11.08.2013 03:47 |