Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | few tests | esbybb | 1122. Игра | 19 фев 2017 08:17 | 2 | WBBB BBBW WBWB BBBB 101 010 101 2 BBBB BBWW BBBB WWBW 010 111 010 3 can you explain your examples | | WA #5 | Accepted | 1306. Медиана последовательности | 18 фев 2017 20:26 | 4 | WA #5 Accepted 2 мар 2013 12:05 I use priority queue,the memory that I used is 236 KB,but I still WA at test 5,but I don't know why... You need use unsigned int. could someone tell me why ? Edited by author 18.02.2017 05:40 Edited by author 18.02.2017 05:40 2^31-1 can be stored into signed int. But, when length of input is even, you need to value average, so (probably) add 2 values and receive integer overflow. It doesn't mean you must use unsigned. You can avoid overflow in any other way. | | still TLE | Mehedi Hasan | 1086. Криптография | 18 фев 2017 20:16 | 4 | Looks like you re-valuate a[] for every input number. Why? It can be valued once, before "while(t--) {...}" cycle. Formatting is weird a bit. Why? To prevent reading? Looks like you re-valuate status[] for every input number. Why? It can be valued once, before "while(t--) {...}" cycle. What do you think, why this comment is the same with previous one? Have you read previous one? | | TLE with bfs | sukhad | 1119. Метро | 18 фев 2017 03:53 | 1 | I am using bfs to solve the problem but still getting TLE. Can anyone suugest the cause? | | for those who use graph & recursion approach | Anton | 1119. Метро | 18 фев 2017 03:51 | 4 | My graph consists of vertexes, which are points, that allow diagonal crossing. Edge (a, b) exists if and only if (a) strictly south-west from (b). Since graph is built, simple dfs easily helps solve the problem ( length of the longest path in the graph - it's diagonal part of result path ). To avoid TLE#10 in this approach, memorization should be used. I know, it's not the best approach, but since constraints are relatively low, it does work. My AC - 0.015 164 КБ. I think, Longest increasing subsequence - is better in general case. how you use longest increasing subsequence in this problem ? To avoid TLE#10 in this approach, memorization should be used. Thanks, it helped me) I added functools.lru_cache() decorator for my Python program and got AC :) Shouldn't we use bfs as we require the shortest path? | | As a fixed time solutions on the server? | BrainBreaker | 1222. Chernobyl’ Eagles | 17 фев 2017 22:46 | 3 | I got AC. My time is 0.001s (This problem #1222) - Objected-oriented progarmming, call methods, cycles in cycles... But my time of Problem #1000 (A+B) (int + int) - 0.015s Why? :))) Rounding. You can get times of 0.001, 0.015, 0.031, 0.046, 0.062 etc (the step is around 15.5). And, of course, 0.015 wouldn't mean you have exactly that time; it would rather mean that you have somewhere between 0.002 and 0.015. Or around that. Thanks. Possible time interval of 15 ms, I saw a long time ago. Just do not understand, he can not keep within the 1 ms solution like С++: ----------------------------------- #include <iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<(a+b)<<"\n"; } ----------------------------------- or Pascal: ----------------------------------- var a,b: integer; begin readln(a,b); writeln(a+b); end. ----------------------------------- I think it should work many times faster than 1 ms. Time spent on the input and output? P.S. Today I passed the task of "1000 A + B Problem" of 0.001s. But usually - 0.015s. :) Hypotesis: The program may start at the beginning or end of the interval timer - and depending on this time will be different. If TLE < 0.014, repeat Submit, while not AC! ))) | | Компилятор JAVA | Ilya Shuvaloff | 1404. Легко взломать! | 17 фев 2017 17:37 | 3 | Доброго всем времени суток. Прошу помочь разобраться, в чем может состоять проблема моего кода. В NetBeans все компилируется без проблем, здесь же выдается ошибка RuntimeError. Я здесь впервые, поэтому прошу не судить (З.Ы. Руководство по написанию java скриптов прочел и до сих пор не нашел ошибки). Заранее всем спасибо. Hi all! I'm asking you for help, cause my script cannot be run by server java compiler. In NetBeans it works well, but here that's a RuntimeError. Thank you in anvance. import java.util.Scanner; import java.io.PrintWriter; public class Cryptography { final String alphabetStr = "abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) { new Cryptography().run(); } void run() { Scanner in = new Scanner(System.in, "ISO-8859-1"); PrintWriter out = new PrintWriter(System.out); String word = in.next(); out.println( descript(word) ); out.flush(); }
String descript(String word) { int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) );
if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5));
index -= alphabetStr.indexOf( word.charAt( word.length()-2 ) ); if ( index<0 ) index += 26; return descript(word.substring(0, word.length()-1)) + alphabetStr.charAt(index); }
} Edited by author 17.02.2017 16:13 Edited by author 17.02.2017 16:15 If "Runtime error" happened than your program compiled successful and crashed while running. As you have RE on 4th test your program passed first 3 tests. > int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) ); > if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5)); How should it work for string "a" for example? Just before you answered i've found exactly this problem. Thank you! | | Why I got Wrong answer at Test 2? Can anybody give me a test about it? | Dryad | 1267. Екатеринбургское метро | 17 фев 2017 14:24 | 13 | This is my program: #include <stdio.h> int len[16]; int ldist[16]; int rdist[16]; int depart; int gor,gol,iv; int N; void prelr() { int i; ldist[0]=0; for (i=1;i<N;i++) ldist[i]=ldist[i-1]+len[i-1]; for (i=N-2;i>=0;i--) rdist[i]=rdist[i+1]+len[i]; } void read() { scanf("%d",&N); int i; for (i=0;i<N-1;i++) scanf("%d",&len[i]); scanf("%d",&depart); depart--; scanf("%d%d%d",&iv,&gor,&gol); } int best; bool first; int deptime; void nexttimepoint(int&time,int&posi,int&dir) { //Test nearest shuttle int tmp; if (dir==1) { tmp=((time-ldist[posi]-gor)%iv+iv)%iv; if (tmp!=0) tmp=iv-tmp; time+=tmp; } else { tmp=((time-rdist[posi]-gol)%iv+iv)%iv; if (tmp!=0) tmp=iv-tmp; time+=tmp; } //Record if it's first if (first) { first=false; deptime=time; } //Make path if (dir==1) { time+=len[posi]; posi++; } else { time+=len[posi-1]; posi--; } //Test if reverse needed if (posi==0) dir=1; if (posi==N-1) dir=-1;
} void testdepart(int direct) { int i,time,p,delayi,dir; int last; for (i=1<<(N-2);i-->0;) { delayi=i; last=(1<<N)-1; if (direct==1) time=ldist[depart]; else time=rdist[depart]; p=i; dir=direct; p=depart; first=true; nexttimepoint(time,p,dir); while (p!=depart||dir!=direct) { if (p==0||p==N-1) time++; else if (last&(1<<p)&&p!=depart) { if (delayi&(1<<(p-1))) delayi^=1<<(p-1); else { last^=1<<p; time++; } } nexttimepoint(time,p,dir); } if (best>time-deptime) best=time-deptime; } } void process() { prelr(); if (depart!=N-1) testdepart(1); if (depart!=0) testdepart(-1); } int main() { read(); best=2147483647; if (N==1) printf("0\n"); else process(); printf("%d\n",best); return 0; } Thanks. These two absolutely random test based on my AC prog 6 7 6 3 2 8 3 12 56 34 res:96 12 1 2 45 64 31 23 128 61 2 2 7 8 11 1001 31 res:825 Edited by author 07.09.2010 23:23 Edited by author 07.09.2010 23:24 These two absolutely random test based on my AC prog 6 7 6 3 2 8 3 12 56 34 res:96 12 1 2 45 64 31 23 128 61 2 2 7 8 11 1001 31 res:825 I think it`s wrong answer, because this need at least 1 train starting in 1, and it takes 1001 minutes, but your answer less than it. Let then another AC authors apply their programs to these tests The interval between the trains is nonzero and doesn’t exceed 10^5, and the departure time from the terminal stations doesn’t exceed the interval. In your tests it is not true. Edited by author 01.04.2011 17:46 Edited by author 01.04.2011 17:46 Yes, I solved problem with more wide conditions. In my test 11 1001 31, and 1001,31>11. But my algo (DP) allow such expansion. So tests are useful. Solve problem in broader conditions and get AC in narrow case. These two absolutely random test based on my AC prog 6 7 6 3 2 8 3 12 56 34 res:96 12 1 2 45 64 31 23 128 61 2 2 7 8 11 1001 31 res:825 My AC program gives 156 and 1837 respectively. So... weak tests? Edited by author 13.10.2014 19:33 These tests are wrong as "departure time from the terminal stations doesn’t exceed the interval." not trusted. try test 1 1 100 100 100 answer is 0 :) can anyone tell me why the sample's answer is 28? | | Почему выдаёт, что неверный ответ? С# | KrulTepes | 1068. Сумма | 16 фев 2017 22:18 | 1 | using System; namespace ConsoleApplication { internal class Program { public static void Main(string[] args) { var i = Convert.ToInt32(Console.ReadLine()); var v = i; var b = v; var z = Math.Abs(i); var x = 0; if (b<0) { x = -2; } else { x = 0; } var sum = 0; while (x!=z) { sum = sum + v; if (b<0) { v++; } else { v--; } x++; } Console.WriteLine(sum); } } } | | The primality of the table for n=5 is equal to 3 ? | QProgS | 1985. Простой квадрат | 16 фев 2017 21:06 | 5 | The primality of the table for n=5 is equal to 3 ? I understood) for n=5 answer 4 ) I found Edited by author 22.10.2013 07:58 if n=5 then matrix view that: 1 20 19 18 17 2 21 22 15 16 3 24 23 14 13 4 25 8 9 12 5 6 7 10 11 ??? 13 14 17 18 19 12 15 16 21 20 11 10 9 22 23 2 1 8 7 24 3 4 5 6 25 Edited by author 16.02.2017 22:14 | | Accepted | tarashi | 1409. Два бандита | 16 фев 2017 17:46 | 7 | [code deleted] Edited by moderator 19.11.2019 23:54 Could you tell me why? Thanks in advance!! Edited by author 29.07.2008 17:35 Actually,it is a "check"... lol, your algo works as much as 0.031 seconds. but mine works 0.015: [code deleted] Edited by moderator 19.11.2019 23:55 [code deleted] //c language. 0.001 sec Edited by moderator 19.11.2019 23:55 but mine works 0.001 LOOOOL You must use smaller type: BYTE | | WA9 ! what's wrong with my code !?! my code here | Farhad Ghasemi | 1120. Сумма последовательных чисел | 15 фев 2017 18:05 | 3 | #include<iostream> #include<math.h> using namespace std; int main() { int n; int p; double a; int i; cin>>n; int flag; for(p=sqrt(n*2);p>0;p--) { a=(double)n/p-(double)(p-1)/2; if(a==(int)a && a>0) { cout<<a<<" "<<p; return 0; }
} cout<<n<<" "<<1; return 0; } Edited by author 09.10.2008 14:39 cout << (int)a << " " << p; :) | | "runtime error (access violation)" | philimonix | 1001. Обратный корень | 15 фев 2017 12:40 | 5 | #include <stdio.h> #include <math.h> #include <stdlib.h> #define SIZE 1024 int main(void) { unsigned long long int *buffer = \ (unsigned long long int *) malloc(sizeof(unsigned long long int) * SIZE); int i = 0;
while (scanf("%llu", &buffer[i]) > 0) i++;
for(i -= 1; i >= 0; i--) printf("%.4f\n", sqrt(buffer[i]));
return 0; } У меня всё работает, на тестовых данных выдаёт правильный результат. В чём косяк? Edited by author 14.02.2017 15:27 > #define SIZE 1024 Number is wrong. Max input size is much bigger. Пробовал и большие числа туда вписывать. Всё равно не работает. Точнее, оно работает, но у меня на компе.. а вот на сайте проверку не проходит > и большие числа Which one? How did you estimate max input size? By task, max input size is 256K bytes . Assuming 2 bytes per number - "1 " - max input size is 128K numbers. Btw, why raw C? Why not C++ with stl containers? Edited by author 15.02.2017 12:38 > Btw, why raw C? Why not C++ with std containers? Не интересует С++ с его чрезмерной сложностью и нагромождением какой-то невероятной кучи всякого-разного :) Мне как-то больше по душе чистый и простой С. А задачу, кстати, всё-таки решил. Действительно, нужно было просто сильно увеличить размер массива. Я сделал #define SIZE 10241024. Большое спасибо за помощь! Edited by author 15.02.2017 12:42 | | anyone give some hints?? | Shen Yang | 1693. Задача Лойда | 13 фев 2017 14:16 | 1 | | | WA#6, help me plz!!! | quangduytr | 1011. Кондукторы | 13 фев 2017 12:43 | 1 | #include <bits/stdc++.h> using namespace std; float p,q,t1,t2,t3,l1,l2; int main() { cin>>p>>q; for(int i=1; i<=1000000; i++){ t1=(p*(float)i)/(float)100; t2=(q*(float)i)/(float)100; l1=(int)t1; l2=(int)t2; if(l1==t1||l2==t2||l1!=l2){ if(l1!=t1) l1=l1+1; for(int j=l1; j<=l2; j++){ t3=((float)j/(float)i)*(float)100; if(p-0.000001<t3&&t3<q+0.000001){ cout<<i; return 0; } } } } } | | how does sample works? | Shen Yang | 1649. Абстракционизм в массы | 13 фев 2017 11:50 | 2 | I can only get 2 3 1 3 4 3 2 3 2 according to the sample output... understand now... four populated adjcent cells | | O(n) | wefgef | 1069. Код Прюфера | 12 фев 2017 15:50 | 8 | O(n) wefgef 4 июн 2006 18:45 has anyone done it in O(n)? Re: O(n) Cybernetics Team 5 июн 2006 16:13 But this solution is O(n^2) becouse of ... 7 for each value i in a 8 for each node j in T ... maybe I don't understand whi it is O(n) so I ask you tell me why please. Sorry for bad English. Никто с форума не знает решение O(N), т.к. в рейтинге решений у всех время 0.015, которое соответствует N*logN (я сам так решил). Идея задачи проста-на очередном шаге находить ещё не использованные вершинки (а также отсутствующие в оставшемся списке),и среди всех таких вершины с минимальным номером. Это как раз и будут "очередные" в "оставшемся" дереве висячие вершины. Стандартное решение с использованием кучи работает O(N*logN). Если кто-нибудь ДЕЙСТВИТЕЛЬНО знает решение за O(N), то напишите на общем форуме. Edited by author 28.08.2015 00:24 I'm implemented O(N) algo, and got 0.001s AC!. You can easily do it in O(N) with counting sort. | | For whom, who get WA 4 | Gleb_Kazantaev(NNSTU) | 1084. Пусти козла в огород | 12 фев 2017 14:06 | 2 | if(a/2. >= r) { printf("%.3lf", pi*r*r); return 0; } This is 4th test, use only "%.3lf" ! Yeah, thanks a lot. There are terrible tests | | WA3 | 💻Evgeny Nemtsev [UrFU]` | 1371. Грузоперевозки | 11 фев 2017 17:09 | 1 | WA3 💻Evgeny Nemtsev [UrFU]` 11 фев 2017 17:09 Don't forget about cargo delivery time: 4 1 2 1 2 3 10 2 4 1 ------ 6 Edited by author 11.02.2017 17:10 | | Memory Limit. Dont know why. Pls help me to understand where i am wrong. | intueor | 1220. Stacks | 10 фев 2017 14:56 | 3 | I hope somebody will explain me what's wrong with my program, cause I really dont understand why i get out of memory (900KB) when my program should use only about 700KB (no more than 750KB definetly!). So pls help me smb. Now i try to explain my problem. The only memory i use, i define out of main scope and i dont use any dynamic allocations. So, the definition looks like: unsigned int length[MAXIMUMSTACKS]; unsigned int maxlength[MAXIMUMSTACKS]; unsigned int base[MAXIMUMSTACKS]; unsigned int stackPtr[MAXIMUMSTACKS]; unsigned char opbuf[OPSIZE * MAXOP]; unsigned int stack[MAXOP / 2]; where MAXIMUMSTACKS = 1000, OPSIZE = 5, MAXOP = 100000. So, let's count all memory we may use: 4*1000 + 4*1000 + 4*1000 + 4*1000 + 500000 + 4*50000 = 16*1000 + 500000 + 200000 = 716000 bytes! I is about 700KB to be honest. So, i dont inderstand, why my program get Memory Limit Error and use (as Timus says) 900KB(!). Pls, help me to fix it. Tell me what i dont understand. I give you the code of programm below. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MASK(k) ((1 << k) - 1) #define OPSIZE 5 #define POPCODE 1000000001 #define MAXIMUMSTACKS 1000 #define MAXOP 100000 unsigned int N; unsigned int length[MAXIMUMSTACKS]; unsigned int maxlength[MAXIMUMSTACKS]; unsigned int base[MAXIMUMSTACKS]; unsigned int stackPtr[MAXIMUMSTACKS]; unsigned char opbuf[OPSIZE * MAXOP]; unsigned int stack[MAXOP / 2]; char op[5]; unsigned short stnum; unsigned int value; unsigned int indx; int main(int argc, char *argv[]) { // freopen("input.txt", "r", stdin); // init scanf("%u", &N); memset(opbuf, 0, N * OPSIZE); memset(length, 0, MAXIMUMSTACKS * sizeof(unsigned short)); memset(maxlength, 0, MAXIMUMSTACKS * sizeof(unsigned short)); // fill opbuf for (unsigned int i = 0; i < N; ++i) { scanf("%s%hu", op, &stnum); --stnum; indx = OPSIZE * i; opbuf[indx] = *((unsigned char*)&stnum); opbuf[indx + 1] = *((unsigned char*)&stnum + 1) & MASK(2); if (op[1] == 'U') { scanf("%u", &value); value = (value << 2); for (unsigned int j = 0; j < 4; ++j) opbuf[indx + 1 + j] += *((unsigned char*)&value + j); ++length[stnum]; if (length[stnum] > maxlength[stnum]) { maxlength[stnum] = length[stnum]; if (maxlength[stnum] > MAXOP / 2) maxlength[stnum] = MAXOP / 2; } } else { value = (POPCODE << 2); for (unsigned int j = 0; j < 4; ++j) opbuf[indx + 1 + j] += *((unsigned char*)&value + j); --length[stnum]; } } // create big memory block for stacks unsigned int prevLength = 0; unsigned int prevBase = 0; for (unsigned int i = 0; i < MAXIMUMSTACKS; ++i) { if (maxlength[i] == 0) continue; base[i] = prevBase + prevLength; stackPtr[i] = base[i]; prevBase = base[i]; prevLength = maxlength[i]; } // process through opbuf for (unsigned int i = 0; i < N; ++i) { stnum = 0; value = 0; indx = OPSIZE * i; stnum += opbuf[indx]; stnum += ((opbuf[indx + 1] & MASK(2)) << 8); for (unsigned int j = 0; j < 4; ++j) *((unsigned char*)&value + j) = opbuf[indx + 1 + j]; value = ((value >> 2) & 0x3fffffff); if (value == POPCODE) { if (stackPtr[stnum] == base[stnum]) { stackPtr[stnum] = base[stnum] + maxlength[stnum] - 1; } else { stackPtr[stnum]--; } printf("%u\n", stack[stackPtr[stnum]]); } else { stack[stackPtr[stnum]] = value; if (stackPtr[stnum] == base[stnum] + maxlength[stnum] - 1) stackPtr[stnum] = base[stnum]; else stackPtr[stnum]++; } } return 0; } Edited by author 20.08.2015 16:44 source program only uses about 300KB + 700 = MLE. So you should use about 520000 Byte = 500 KB .My advice is to use a chunk of memory that we split into pieces (for example size 8) in the first part where you keep information about previous segment of the current stack and keep the information in the stack remaining 7.Be excused my english, if you do not clear reply and will present in more detail. Allocated big buffers: commands - 5*MAXOP = 500K stack - 4*MAXOP/2 = 250K Total - 750K buffers only As empty C++ program takes about 100K you have MLE If you wont analyze save commands stack - 4*MAXOP = 500K (all pushes) + some chunks info How your program will work if input sequence is something like 33K * "PUSH 1 100" // less then MAX_OP/2 33K * "PUSH 2 100" // less then MAX_OP/2 33K * "PUSH 3 100" // less then MAX_OP/2 POP 1 POP 2 POP 3 Your program should allocate 3 stacks with total 99K size in the 50K array. |
|
|