Common BoardGive me some tests please Not related to WA5, but to WA4 - perhaps it helps anyway: I got wa4 when forgot to add the advantage of each apartment, to the total value, before comparing to current max. I got WA5. But I have passed it. My error was in copypast. When I was comparing current maximum, I used wrong massive. I want to calculate maximum living along in 2 bedroom apartment massive , but I took values from one bedroom apartment massive :( #include <stdio.h> #include <stdlib.h> struct Team { int id; int m; }; int main() { int n; struct Team * res;
scanf ("%d", &n); res = (struct Team*)malloc( n * sizeof(struct Team) );
for (int i = 0; i < n; i++) scanf ("%d %d", &res[i].id, &res[i].m); struct Team tmp; for (int i = 0; i < n-1; i++) for (int j = 0; j < n-1; j++) if (res[j].m < res[ j+1 ].m) { tmp = res[j]; res[j] = res[ j+1 ]; res[ j+1 ] = tmp; } for (int i = 0; i < n; i++) printf ("%d %d\n", res[i].id, res[i].m); return 0; } Simple test for programs with verdict WA #14: Sample input: 0 2 1 1 Sample output 1 2 Your program outputs "-1"? Find your simple stupid mistake!!! Edited by author 05.11.2005 18:58 Thank you!I got AC!!!Before testing your testcase,my program outputed "2" :) It helps a lot. Thank you! BTW. It's not a valid test case. Here's a valid one. input: 3 3 3 1 1 output: 2 3 How to prevent TLE? I use LinkedList (can AddFirst and AddLast) and use max size of set = n. I'll give you the same hint that helped me see the way: Note that there are a maximum of 10^6 operations. I use this fact: when copy operation occurs then I copy not whole set but only part of set (so size of set always <= n). But this doesn't prevent from TLE. So, how to copy rapidly (I copy element by element)? Hmm that sounds like the right idea, you might double check that your code matches your idea correctly. > 1.031 32 120 KB Looking at your submit data, you may need to be more aggressive in implementing your idea. Edited by author 24.10.2012 17:26 Now I use array with length 2*n instead of LinkedList. So, I decrease memory: >1.015 5 912 КБ But how to decrease time? =) Copy operation takes most time, but each time size of my array (amount of useful elemenets that can be pop) is not more than (n - i) elements. So, how to optimize copy operation? It's really hard to say without seeing code. If you're correctly managing copies like you say, you shouldn't TLE. Seems like you have a simple bug somewhere. Try creating more perosnal test cases that focus on copies to start with. I've overwritten my code from C# to C++ and use memcpy for quick copying but TLE42 again =). So, could you please send me your solution or tell me your mail to check my solution? My mail is on my profile page (hyperlink) From the site FAQ on C/C++: An example of how to use input/output is given above. C++ programmers may always choose between two input/output libraries: standard (scanf, printf) or stream (cin, cout) input/output. Stream input/output is easy to use, but it works much slower than standard input/output. This may even cause receiving the Time limit exceeded verdict. Therefore, if you see that a problem requires reading a lot of input data (for example, more than a megabyte) or a large output is expected, then you should better use standard input/output. Thank you, using of scanf and printf leads to AC. This is bad problem when your algorithm is not so neccessary as quick reading and writing. For C# coders: use Console.In.ReadToEnd - for reading whole input file, and use only once Console.Write for writing answer, and you'll get AC. I just can't understand, when I submit my code using g++4.7.2 c++11, I got TLE42, but vc++2010 or g++4.7.2, I can AC 0.64s. Then I try other problems I find g++4.7.2 is the best. Edited by author 26.04.2013 15:20 In Java use PrintWriter instead System.out.println. I have TLE 1.015 with System.out.println, and I have time 0.703 with PrintWriter. you can use to check "YES" that simple DSU algorithm. because DSU algorithm gives us all cycle, knot, multigraph ... so on
Можете отправить работающую программу,если не сложно.Долго уже пытаюсь,не получается:( Вот код: #include <iostream> using namespace std;
int main() { int k, n; cin >> k >> n;
int a; int sum = 0; for( int i = 0; i < n; i++ ) { cin >> a; sum += a; }
if( ( sum - n * k ) < 0 ) cout << 0; else cout << sum - n * k;
return 0; } на тесте 6 загибается в чом проблемма? 4 3 1 5 6 Answer isn't 0, True Answer is 3. почему 3? 4 3 1 5 6 Потому что в первую минуту прошла только 1 машина. Во вторую прошли 4 машины и 1 осталась на 3ью минуту. А в 3ью минуту Должны пройти 6+1=7 машин, а может только 4. 7-4=3. У меня ответ 3. А тест не проходит. Can you tell me why the answer is 3 but 0? use Google translate))) They tell about answer))) I tested it offline,and I got WA 90. But when I submited it.I got Crash(Access Violation). There's another question. For this input: 98 146 1 2 1 2 3 300 3 4 1 4 5 300 5 6 1 6 7 300 7 8 1 8 9 300 9 10 1 10 11 300 11 12 1 12 13 300 13 14 1 14 15 300 15 16 1 16 17 300 17 18 1 18 19 300 19 20 1 20 21 300 21 22 1 22 23 300 23 24 1 24 25 300 25 26 1 26 27 300 27 28 1 28 29 300 29 30 1 30 31 300 31 32 1 32 33 300 33 34 1 34 35 300 35 36 1 36 37 300 37 38 1 38 39 300 39 40 1 40 41 300 41 42 1 42 43 300 43 44 1 44 45 300 45 46 1 46 47 300 47 48 1 48 49 300 50 51 300 51 52 1 52 53 300 53 54 1 54 55 300 55 56 1 56 57 300 57 58 1 58 59 300 59 60 1 60 61 300 61 62 1 62 63 300 63 64 1 64 65 300 65 66 1 66 67 300 67 68 1 68 69 300 69 70 1 70 71 300 71 72 1 72 73 300 73 74 1 74 75 300 75 76 1 76 77 300 77 78 1 78 79 300 79 80 1 80 81 300 81 82 1 82 83 300 83 84 1 84 85 300 85 86 1 86 87 300 87 88 1 88 89 300 89 90 1 90 91 300 91 92 1 92 93 300 93 94 1 94 95 300 95 96 1 96 97 300 97 98 1 1 50 5 2 51 5 3 52 5 4 53 5 5 54 5 6 55 5 7 56 5 8 57 5 9 58 5 10 59 5 11 60 5 12 61 5 13 62 5 14 63 5 15 64 5 16 65 5 17 66 5 18 67 5 19 68 5 20 69 5 21 70 5 22 71 5 23 72 5 24 73 5 25 74 5 26 75 5 27 76 5 28 77 5 29 78 5 30 79 5 31 80 5 32 81 5 33 82 5 34 83 5 35 84 5 36 85 5 37 86 5 38 87 5 39 88 5 40 89 5 41 90 5 42 91 5 43 92 5 44 93 5 45 94 5 46 95 5 47 96 5 48 97 5 49 98 5 50 49 3 -1 My answer is:49 98 97 And I think it was quit correct. But the output is: 49 50 1 2 51 52 3 4 53 54 5 6 55 56 7 8 57 58 9 10 59 60 11 12 61 62 13 14 63 64 15 16 65 66 17 18 67 68 19 20 69 70 21 22 71 72 23 24 73 74 25 26 75 76 27 28 77 78 29 30 79 80 31 32 81 82 33 34 83 84 35 36 85 86 37 38 87 88 39 40 89 90 41 42 91 92 43 44 93 94 45 46 95 96 47 48 97 98 Can anybody tell me how to solve these questions. Thank you very much Same code get stuck at test #18 due to TLE, then at #17, but got accepted when I submit it again. What magic is this :) Please provide some test cases. Thanks I tried solve this problem 6 times and 3 of their are WA15, This WA is expects when uses binsearch, when I replaced type of numbers from long to BigInteger in java, I got AC, in this 15' test intermediate(промежуточные) numbers bigger than 2000000000 or lower than -2000000000, that is why we have wrong answers )) Good luck! Edited by author 27.01.2009 21:59 I use binsearch and long long in C++, all is ok. by finding value with BS you can take for example 10^9 and if the previous value is 10^9 then you get the following sequence 10^9, 10^9, 2*10^9, 3*10^9, 5*10^9, and so on. by overflowing the integer and long types the answer is wrong I used next hint: for (.........) { .... if (fib[i] > 2*10^9) fib[i] = 2*10^9 +1; if (fib[i] < -2*10^9) fib[i] = -2*10^9 -1; } Edited by author 01.06.2010 16:57 Edited by author 01.06.2010 16:57 Thank you very much, it is just the reason why I got a WA at #15. I tried what you say, but also WA15. I can't understand why?? Well,that was worse....Thanks for hint 40 минут я сабмитил код который точно проходит первый тест (проверял на трех компиляторах на CF) После, я просто добавил еще одно условие которое я изначально не рассмотрел, это когда в строке ничего менять не надо, или эта строка из нулей и надо добавить 0 или убрать. И ПОЧЕМУ-ТО Я СРАЗУ ПОЛУЧИЛ AC!!! Как это понимать, если эти случаи никак не влияют на ответ на первом тесте ???? В этой задаче первый тест не совпадает с примером из условия 1) Let's imagine, that there are n boxes and 1 another box with extra balles, which you didn't place in the first n. So, in fact you have n+1 boxes. 2) We can count the ways of putting red balles separatelly from blue ones. And blue ones separatelly from red. Than just multiply these answers. A brand new equipment has been installed in meat store recently - the electronic seller. Now the customer can simply come and press the button, and the seller will select the meat piece automatically. The pieces are stored in a special container inside the seller. Different pieces have different weights (all weights are distinct). There are N pieces of meat in the container. The seller works the following way. There is a special register X in seller circuit, with initial value set to 0. In order to satisfy the customer the seller does the following: All pieces are numbered from 0 to N-1 in order of weight increase. The piece with number equal to register X value is selected. The seller retrieves the selected piece from the container and hands it to the customer. A request for a new piece is sent to a special warehouse. There are M pieces of meat at the warehouse initially (all weights are distinct). When a request comes, a piece with maximal weight is selected and sent to the container. Thus, the total number of pieces in container remains the same, and the warehouse gets empty after serving M requests. A new value XAB is written into register X which is calculated like this: XAB = (X · A + B) mod N Suppose, that the customer requires K pieces. You must write a program that will calculate the sequence of pieces given out by the seller. Input The first line contains 5 integer numbers N, M, A, B, K (2 ≤ N, M ≤ 2^16; 1 ≤ K ≤ M; 0 < A < N; 0 ≤ B < N). The second line contains N integers - weights of pieces in the container. The third line contains M integers - weights of pieces in the warehouse. All weights are distinct. All weights are between 1 and 231-1 inclusively. Output Output K numbers separated by spaces - weights of pieces in order of giving out. Input 1 Output 1 3 2 1 1 2 5 1 3 4 2 1 4 Input 2 Output 2 3 3 2 1 3 5 2 3 1 4 6 2 5 3 //Already I compiled programm but n=65536 time limited This is meat store`s code in c++ #include <iostream.h> #include <conio.h> #include <algorithm> using namespace std; void qs(int* y, int first, int last) { int i = first, j = last, x = y[(first + last) / 2],xx; do { while (y[i] < x) i++; while (y[j] > x) j--; if(i <= j) { if (y[i] > y[j]) {xx=y[i];y[i]=y[j];y[j]=xx;} i++; j--; } } while (i <= j); if (i < last) qs(y, i, last); if (first < j) qs(y, first, j); } int main() { int n,m,k,a,b; cin>>n>>m>>a>>b>>k; int *y,*z,xx; y=new int[n+1]; z=new int[m+1]; for(int i=0;i<n;i++) cin>>y[i]; for(int j=0;j<m;j++) cin>>z[j]; qs(y,0,n-1); qs(z,0,m-1); int x=0; cout<<y[0]<<" "; int pp; for(int t=1;t<k;t++) { pp=z[m-t]; y[x]=y[n/2]; y[n/2]=pp; qs(y,0,n-1); x=(x*a+b) % n; cout<<y[x]<<" "; } //getch(); // return 0; } Edited by author 03.11.2014 22:16 Edited by author 03.11.2014 22:21 |
|