|
|
Common Boarda, b = map(int, input().split()) print(10-a, 10-b) Их не обязательно 10! то есть всего банок a + b - 1 Total_Cans = a+b-1 then, print(Total_Cans-a, Total_Cans-b) Finally I've solved this problem using very hard optimised Main & Lorentz's algo, and 0.405s only. But I noticed many people solved this problem very fast and using much less memory. What algo do you use? I doubt it's possible to speed-up Main & Lorentz or Crochemore algos so much. Is it some alternative (like suffix tree) solution, or just some strong idea can be applied to this particular problem? Is it possible to solve it in O(n)? I use something similar with manacher algorithm with some optimization.. I use this approach: first for every position find the answer which cover outside the string(using kmp algo) as estimate value, and sort the estimate value in desending order, then use bruteforce(hash+enum) to calc the answer inside the string.when estimate value <=ans break; this program make me 0.2s AC... Thank you, but your solution is either not very fast :) I believe there's a strict approach exists with a strict algo for this problem. My algorithm is similar to Shen Yang.But I also use exkmp to calc another two situaion. Then the estimate value will become smaller.I got AC in 0.046s. Look up Critical Factorization Theorem So clearly realising (if monkey will follow others then monkey never will create that word because of re-using letters)? 4 1 0 3 0 3 2 1 2 3 1 0 Answers: 2.00000000 4 1 0 3 0 3 2 1 2 3 1 1 45 Answers: 2.00000000 2.00000000 4 1 0 3 0 3 2 1 2 3 1 2 45 -90 Answers: 2.00000000 2.00000000 0.50000000 4 1 0 3 0 3 2 1 2 3 1 2 -45 -45 Answers: 2.00000000 0.50000000 0.00000000 3 -2.000 1.000 1.000 -2.000 4.000 1.000 1.000 1.000 1 359 Answers: 9.00000000 0.00000000 rt Voroni diagrams perhaps (O(N*log(N)) I have AC 0.046s, O(K^3) with very simple approach Edited by author 14.04.2024 21:19 Can Anyone be kind enough to explain this ques to me? I'll be grateful to you.. When I tried the brute force algorithm, I TLE at #15 How to solve this problem? Please send the solution to 13588731339@163.com 1) When bruteforcing, random shuffle both m rows and n ships 2) When solving one subset sum problem inside bruteforcing, use bitset (array of bitsets) instead of bool array (2d-array). Instead of max() in subset sum problem, use operator OR and operator "right bit shift". Just search "subset sum problem bitset" and you'll find out. This will speed up your dynamic programming in 32 or 64 times (if you are using both 64-bit compiler and 64-bit processor) It will not totally solve problem, but you will get TLE#67 which is better and giving more hope :) Edited by author 12.04.2024 01:08 Edited by author 12.04.2024 01:09 Edited by author 12.04.2024 01:11 I tried this approach with Java: Test 5. TL With C++: Test 9. TL And seems like this is not enough, however time complexity is O(αk^2 + α|S|*k) where α is hash map hidden constant. So... did anyone managed to solve it this way? dp[i][j] - amount of i-digit numbers ending with j. therefore we form 2d table dp[n][2] then dp[i][0] = dp[i - 1][0] + dp[i - 1][1] dp[i][1] = dp[i - 1][1] It's not hard to see that dp[i][0] + dp[i][1] (i.e. number of all valid sequences) forms a fibonacci sequence. dp[i][0] + dp[i][1] = 2*dp[i - 1][0] + dp[i - 1][1] you can treat as f_n = 2*f_(n - 2) + f_(n - 3) But still, I don't know how to solve this problem :) Edited by author 23.01.2022 01:36 Edited by author 23.01.2022 01:37 dp[i][1] = dp[i - 1][1] is wrong, should be: dp[i][1] = dp[i - 1][0] Не вздумайте решать задачу, оно того не стоит. ( window | A | aisle |B C| aisle | D | window )-- Premium (1-2) ( window | A B| aisle |C D| aisle |E F | window )-- Business (3-20) ( window | A B C| aisle |D E F G| aisle |H G K | window )-- Economy (21-64) Edited by author 30.05.2022 16:38 It took me a while to get this one correct, and it's because I found part of the descritpion to be ambiguous/unclear - so I'm posting this clarification which hopefully will help anyone else who has the same misunderstanding. "if a student has got satisfactory marks, the scholarship is not given, " I read this to mean "got ONLY satisfactory marks" but my solutions were rejected. Once I modified my solution to treat it as "got ANY satisfactory marks", the solution was accepted. First time I've got WA #4 because of this test case: Input: 6 1 1 2 1 1 1 Correct answer: 2 1 1 2 3 1 Instead of using getline(cin, str), use two different string such as string s1, s2. Then compare s1! When n > 6 the cases are wrong. Try to do it without placing a circle in the center. How is it POSSIBLE to find 42 test case? It seems like everything should work fine.. OK, found my mistake. 777&222 would be very helpful test cases) already done. for someone who doesn't know how to do it: a,b = input().split() print(int(a)+int(b)) a = int(1) b = int(5) Edited by author 28.03.2024 16:23 What the output of? 2 0 0 1 1 1 1 2 2 |
|
|