Common Board Have anybody crash on 3 test? It's interesting, that my friend decided this problem and on tests with n>50 we have the same answer. I had. You must add in your programm something like this: if(sum/9>2*n){ printf("0"); return 0; } thanks. I just found my forgotten! my program cannot print 0 'zero' ( - -") Why is this condition required? The recursive formula takes care of this.. Without this condition my code gets WA3.. And when I add it, it gets AC.. Could you plz give a test case where this condition is really required, where the DP formula fails..?? I don't think it's DP formula's fault Perhaps when you are deleting leading zero, you haven't judge if the point is >= 0 The solution is just a very little more difficult, that the first, which comes to mind. I tried firstly to count these probabilities (those are C(M, m) * C(N-M, n-m) / C(N, n)), but seems, it is impossible with these constraints. Here are some test cases and my AC prog's answers 1000000000 999999929 71 999999000 999998981 19 999000999 3 5 999000991 405 3 5 397 101 101 1001 3 7 991 10001 5 23 9973 100001 3 7 99991 1000001 5 13 999983 10000001 3 7 9999991 100000001 5 7 99999989 555555555 3 11 555555541 191919191 5 23 191919163 838383838 838383779 59 123456789 5 23 123456761 987654321 987654319 2 987654319 987654319 101010101 3 19 101010079 Good luck Thanks for this testset, helped me find the bug :) The same, in a more reusable format: 18 1000000000 999999000 999000999 405 101 1001 10001 100001 1000001 10000001 100000001 555555555 191919191 838383838 123456789 987654321 987654319 101010101 71 999999929 19 999998981 3 5 999000991 3 5 397 101 3 7 991 3 31 9967 3 7 99991 3 19 999979 3 7 9999991 3 67 99999931 3 11 555555541 3 61 191919127 59 838383779 3 29 123456757 2 987654319 987654319 3 19 101010079 i use python so long arithmetics is not problem for me i use greedy algo and try to replace digit to 9 i want to see test How to solve problem without long arithmetics? The main idea of this test following in sorting relative fees instead of absolute fees. Simple example: 2 1 10 10 1 1 999990 1 100 1 The first package has huge absolute value of fees ((999999 - 10) * 1), but it adds only 9 credits to the initial fees. Edited by author 18.06.2022 20:06 I'm just learning python. Can you please tell me where could be the error? import math data = input() length = len(data) list = [] i = 0 while i < length: if data[i] != " " and data[i] != "\n": end_index = i for j in range(i + 1, length): if data[j] == " " or data[i] == "\n": break end_index += 1 list.insert(0, int(data[i:end_index + 1])) i = end_index + 1 else: i += 1 for e in list: value = round(math.sqrt(e), 4) print(f'{value:.4f}') You only need to write about 3 lines of python code to solve this. try: help(str.split) help(reversed) help(str.join) If you're unlucky and get WA#25 (just like I did), try a test: > 2 4 5 1 1 1 The answer should be NO. This obvious test helped me to fix a little bug, so I decided to share. My program passes all tests created by me, so I don't know what could be the problem with it Why can we always choose the farthest point? Suppose the opposite. Let we have 3 adjacent points in our way, which make obtuse angle. Let's call them A, B and C. angle ABC is obtuse, that means that |AC|>|AB| and |AC|>|BC|. But that's impossible because our algorithm chooses the farthest point, but B is not the farthest, C is further than B. Contradiction. Edited by author 11.06.2022 17:49 Edited by author 11.06.2022 17:49 I had X[2000], then I changed it to X[2002] and got AC Test: 99 10 ***|_|*** .*.|_|*** *.*|_|*** ***|_|*** .*.|_|*** *.*|_|*** and so on (block of 3 rows repeated 33 times). My program hangs out on this test (takes infinite time), but I got accepted. It's obvious that answer for first team is n - 1 How to get answer for second team. Of course total number of points do not exceed 3 * (n * (n - 1) / 2), because we played n * (n - 1) / 2 matches, and in every match summary points not exceed 3. Assume looser team got k points, that mean that total number of points >= k * n. But k * n can't be greater than 3 * n * (n - 1) / 2, so: k * n <= 3 * n * (n - 1) / 2, then k <= 3 * (n - 1) / 2. Answer is 3 * (n - 1) / 2. But how to prove that we can make such competition where k is the smallest value and we have (n - 1) values that are not less? Edited by author 08.06.2022 21:21 I have seen many people solve this problem using divisor of given number(k).But i cannot understand how it works.Can anyone explain me how this logic works?? sorry for bad english you need to be in control. you are in control when you keep the first player in "loop". if you take number of buttons is 6, say, then the "loop" length is 3, i.e. if you take max number of buttons as 3 - 1 = 2, then whatever amount the first player takes you can keep them in loop. if they take first time 1, you take 2 - in sum 3, 3 - remaining, you are a winner. if they take 2 - you take 1, 3 remaining again - you are a winner. so, idea is to find the smallest divisor of a number > 2 & answer will be that - 1. hope that makes sense. Edited by author 18.01.2019 19:50 WLOG, let's break `k` elements of heap into block of length `d`. The numbers below are listed from 1, ..., k in their congruent modulo of `d`. [1, 2, ...., (d - 1), d], [1, 2, ...., (d - 1), d], ......(k / d) blocks. Here [..] is a block notation. B = #blocks of length `d` = (k / d) Basis: If B = 1, it's always true, as `first player` can pick whatever from 1, ..., (d - 1), `second player` always left with atleast 1 element by less then d to be picked. So `second player` player will greedily pick all remaining element in the block as an optimal move for his/her winning. Hypothesis: Let say it's true upto (B - 1) blocks that `second player` has taken the last element. Proof: If we have B block then since it is true for (B - 1) blocks we left with 1 block of element to pick and since `first player` is the who pick first in the last 1 block by using the `basis` we know that `second player` is always the winner. Hence, if we take the divisor of number of elements in the heap (k) we always end of with `second player` being the winner. Edited by author 07.06.2022 10:23 Edited by author 07.06.2022 10:23 Knight can't step on the cell with the horned demon int make_test() { fstream inp("input2.txt", ios::out | ios::binary | ios::in | ios::trunc); if (!inp) { _Post_equals_last_error_ DWORD er = GetLastError(); cerr << er << '\n'; _getch(); exit(1); } int n = 100; inp << n << '\n'; srand(time(0)); for (int i = 0; i < n; i++) { int sign = rand() % 2; if (sign == 1 || i < 2) { int a = rand() % 300; while (find(simple.begin(), simple.end(), a) != simple.end()) { a = rand() % 300; } inp << "+ " << a << '\n'; v.push_back(a); } else if (v.size() > 1) { int a = rand() % v.size(); inp << "- " << v[a] << '\n'; v.erase(v.begin() + a); } } inp.close(); return 0; } ... TextReader reader = new StreamReader(Console.OpenStandardInput(), System.Text.Encoding.GetEncoding("iso-8859-1")); ... string line = reader.ReadLine(); ... Is there possible such test: 1 A aa 10 1 1 1 A bb ? If then, what correct solution will be: 'aa 1' or 'aa 1, bb 1'? k - is it a day when person comes to city? Or it is a day when he goes to that city - so person comes in this city on next day? Why in example 25 days, but result has only 20 days? If two cities have same largest amount of money then it shouldn't be counted? Edited by author 02.06.2022 13:52 Why always i get wrong answer in test#2?? which is the case i didnt condiser?? in the case>> aa@ab.c aa@as.a aa@abs.l my code return "7" Edited by author 23.10.2014 02:42 Edited by author 23.10.2014 02:43 ab@ab@ab 4 aa@ab.c aa@as.a aa@abs.l 14 Have no idea what's wrong I used simple plan with massive of relations and recursive function that checks all ancesters (only up moving) and all descendants (only down moving). There is some part of code in C++: int checkforblood(int index, int** mas, int* checkmas, int range, int direct) { if (checkmas[index - 1] == 1) return 0; checkmas[index-1] = 1; for (int i = 0; i < range; i++) { if (( mas[i][0] == index )&&(direct > -1)) { checkforblood(mas[i][1], mas, checkmas, range, 1); } if (( mas[i][1] == index ) && (direct < 1)) { checkforblood(mas[i][0], mas, checkmas, range, -1); } } return 0; } I can't see the problem, so if you can't too i will know, that problem in output method. Edited by author 31.05.2022 02:26 Does somebody know what test I need to try to solve this problem? |
|