|
|
Общий форумIs it possible to use somehow that p is prime? My AC solution doesn't use this fact, but I'm wondering is there a simpler way to solve this task. Complexity is (M + N) * log N, where N is a size of the array and M is a number of queries I needed primality of 'p' when I calculated S(K) from sums of powers for Ai. I needed to divide by 2, 6 or 24 in the end. Primality plays important role when you find inverse of these divisors modulo 'p'. Also the fact that S>1000 was also convenient fact because some multiplications would turn to zero for quite small p. This problem is named "Elementary Symmetric Functions". There is formula (by Newton) that gives relation between elementary symmetric polynomials and "power sums" (that are symmetric too). Formula used division that can be done in general case only by prime modulo. But it can be solved without knowing any special about these polynomials. In this case solution doesn't need the primality of P. And then we have a data structure problem only, not number theoretical :) I used interval tree and memoization of sums on subsegments. And still the 4 seconds limitation is too large. upd: Fenwick tree is better ;) Edited by author 10.09.2011 23:40 I understand how to solve the problem with combinatoric formula and 4 segment trees, can you please explain the second way? А мне жалко стану, которая до сих пор живёт так( Да боже. Вы, тупые нытики, даже на сайте с программированием ноете. Как же вы задолбали уже. Никто так не живёт Hi I think that we should help each other. If someone resolves a problem he/she must help the others with materials or links where the algorithm/formula is explained. This is the reason we are users of such sites - because we want to improve our programming skills. So I decided to help all of you who find this problem difficult. Here you can find help: http://en.wikipedia.org/wiki/Circular_segment http://www.mathopenref.com/segmentarea.html The rest is up to you! HTH Edited by author 22.10.2013 12:23 thanks dude, i didn't even understood what the question was asking :) Thanks, bro, you are real man! i checked it manually and answer was correct. Why does if fail? Code: #include <iostream> int main(){ std::string lock1, lock2; std::string result = "yes"; int code = 1; int lock_val1, lock_val2, cur_value; bool lock_state = false; std::cin>>lock1; std::cin>>lock2; lock_val1 = std::stoi(lock1); lock_val2 = std::stoi(lock2); while (code < 10000) { if (lock_state == true){ cur_value = lock_val1; } else{ cur_value = lock_val2; } if (code > lock_val1 && code > lock_val2){ result = "no"; break; } if (code == cur_value){ break; } lock_state = !lock_state; ++code; }
std::cout << result << std::endl; return 0; } Edited by author 30.11.2021 13:19 Edited by author 30.11.2021 13:19 Edited by author 30.11.2021 13:24 Edited by author 30.11.2021 13:37 It passed, there was a typo. When i used dfs, i was getting "Division by zero" on 10 test. Then' i switched to bfs and got AC. Can you explain me: WHY? I have wa in 7 test Check this test 4 3 1 2 100 3 0 100 1 3 -100 Impossible after 3 statements Edited by author 04.04.2009 22:09 But I think the answer should be "Impossible after 1 statements"...I used BFS and I also got WA on test 7 afte statement 1 it will be: 0 100 0 problem?!?!? Edited by author 17.05.2014 22:59 before AC my prog failed on these tests: 1) 7 3 2 1 1000000000 3 1 15 4 5 -20 answer: Possible 0 0 1000000000 15 0 20 0 2) 7 4 2 1 1000000000 3 1 15 4 5 -20 4 2 1 answer: Impossible after 4 statements 3) 8 4 1 2 200 2 3 999999800 3 1 -1000000000 4 0 5 answer: Possible 0 1000000000 999999800 0 5 0 0 0 Test 2 is not correct due to statement restrictions. Length of the first string can be bigger than length of the second string. I spent 15 submissions to realise this 1) First test is not sample 2) There are not n strings in input So, if you have a number, that divides 2^n, than you can add some numbers in the begining (not more than 10) to get number, that divides 2^(n+1). That means, you can bruteforce all possible numbers, that you can add in the begining. Works in O(n*2^10) Could you be more specific? Because I try: 1. Point (row, col) closest to point (1,1) first (distance formula). 2. Row closest to row 1 first. 3. Other variations And I still get WA7. I've tried to submit the same code with different compilers and have received "compilation error" from MS Visual C++ compilers ans "accepted" from G++ and Clang++. On my laptop with MS VS 2019 this code also runs. The question is are compilers on the server ok? the store had the product, but sold it = the store did not have the product if (!Products.count(name) || !Products[name]) Purchases.erase(Purchases.begin() + i); Test: 1 10 of gg 3 1 of ff 10 of gg 9 of gg Correct Answer: 3 Edited by author 25.11.2021 23:40 You can always fill 2 * m area My program got WA1 with answer 1 2 3 4 1 2 3 4 on example test Why? tle 42 -ios_base::sync_with_stdio(0); but ios_base::sync_with_stdio(false); cin.tie(NULL); - ACCEPTED with 0.015) Is there a solution without randge tree structure? I use Fenwick Tree get AC,0.452 seconds There possible segment tree with uint16_t for indexes greater than 2^15, and uin32_t for less 2^15. (two arrays: uint16_t tree[N+N]; and uint32_t rem[32768] ) But I got WA38 (( I Got AC with segment tree!! uraaaaa. You can use segment tree where vertex is segment with length=4. 1 2 3 4 5 6 7 8 9 10 => [1,2,3,4] [5,6,7,8] [9,10,11,12] Memory is N*sizeof(int)+N*sizeof(bool) Complexity is N*log(N/4)*4+N*log(N/4) decomposition also works here, i've chosen amount of block about 300 I can't do that. C/C++. I am using two cycles. One to set up Fenwick tree and one to calculate the answer. Probably you are avoiding the use of the set up cycle somewhat. I tested my solution on war games 2 and have got 93 ms. UPD: got 46 ms on version 1 Edited by author 09.07.2017 22:20 Finally, I understood how to get rid of initialization cycle. Still TLE the same test 37. Maybe bitwise operations are faster with UNSIGNED integers... So, I tried to not calculate cnt=n-i+1 every iteration, made while (1) cycle, not call decrement on Fenwick tree after last soldier. TLE#37. My mistake was I was using queries for O(log(N) *log(N)) time in Fenwick tree But for that task, there are suitable queries in just O(log(N)) dp[i] - минимальное количество отрезков, если последний отрезок заканчивался в позиции i. ответ dp[m]. |
|
|