Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Visual C++ Accepted | mNT | 2056. Scholarship | 17 Nov 2020 15:23 | 2 | #include <iostream> using namespace std; int main(){ int a,b = 0,c = 0,d = 0; int ocenki[20]; cin » a; for (int i = 1; i <= a; i++) cin » ocenki[i]; for (int i = 1; i <= a; i++){ if (ocenki[i] == 5){ b++; } else if (ocenki[i] == 4){ c++; } else if (ocenki[i] == 3){ d++; } } if (d > 0){ cout « "None" « endl; } else if (b == a){ cout « "Named" « endl; } else if (c > b){ cout « "Common" « endl; } else if (c = b){ cout « "High" « endl; } return 0; } | | Не работает | △@|\|11L | 2056. Scholarship | 17 Nov 2020 14:57 | 1 | #include <iostream> using namespace std; int main() { int m[10]{}, n; cin >> n; int sum = 0; for (int i = 0; i < n; i++) { cin >> m[i]; sum += m[i]; } double q; q = static_cast<double>(sum) / n; if (q == 4) { cout << "Common"; } if (q > 4.5 && q < 5) { cout << "High"; } if (q == 5) { cout << "Named"; } if (q == 3) { cout << "None"; } } | | Python solution failing on test 1 | hackerman420 | 1001. Reverse Root | 17 Nov 2020 00:03 | 2 | Hi, I'm not sure why I'm failing on test 1. Any ideas? import sys def main(): ans = [] for line in sys.stdin: nums = line.split() ans.extend([int(num) ** 0.5 for num in nums if num]) for root in ans[::-1]: print("%.4f" % root) Hey, you wrote your code in function. Just paste your code out of function | | How to decrease mod operations? | 👾_challenger128_[PermSU] | 1523. K-inversions | 16 Nov 2020 18:15 | 1 | Anybody know how to decrease mod operations to get more faster solution? I've implemented segment tree, where any node used mod operation to be calculated. I got 0.75s on G++, 0.41s on Clang and 0.25s Visual C++. Maybe I should check if value is overflowed (than mod), but will it be faster? | | WA #2 | Marginean Ciprian | 2105. Alice and Bob are on Bikes | 15 Nov 2020 21:07 | 2 | WA #2 Marginean Ciprian 14 Nov 2018 22:19 Can you please give me a test for my code? For WA#2 you have to check if Alice/Bob are waiting exact amount di. I tried case when di=0, and noticed my code waits 1 time, instead of waiting for 0. | | No need to overengineer with bitmasks, just use the brute force. Think how you can improve brute force a little one bit ;) | mksdbk | 1005. Stone Pile | 14 Nov 2020 00:17 | 1 | | | C# Compilation error (time limit exceeded) | Zergatul | | 13 Nov 2020 18:09 | 2 | How big in compilation time limit? I am getting this error for problem #2107. It is compiling in 1 second on my PC. I don't understand, there is nothing very complicated in my code, just one method with IEnumerable<T> as return value and yield return inside. Ok, I managed to workaround this. I compiled my yield return code. Decompiled it. And copied generated state machine code into my submission. | | Bu....... | Nargiza Asqarova | 1639. Chocolate 2 | 13 Nov 2020 16:42 | 5 | xatosi qayerda bilasizmi? var m,n:1..50; begin read(m,n); if odd(m*n)then write('[second]:=]') else write('[:=[first]'); end.
var a,n,m:word; begin a:=m*n-1; if a mod 2=0 then writeln('[second]=:]') else writeln('[:=[first]');readln; readln;end. #include <stdio.h> void main() { int n,m; scanf("%d %d",&m,&n); printf("%s",(m*n%2)?"[second]=:]":"[:=[first]" ); } men paskallni yaxshi tushunmiyman C++ da kod quyidagicha yozilgan: #include<iostream> using namespace std; int main() { int n,m,s1=0,s2=0,i=0; cin>>n>>m; while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; }
//------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; }
} if(s1>=s2)cout<<"[:=[first]"; else cout<<"[second]=:]"; return 0; } //javada ,in java import java.util.Scanner; public class ONETHOUSANDTWO { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int s1 = 0, s2 = 0, i = 0; if ((m * n - 1) % 2 == 0) { System.out.println(); } while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; } //------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; } } if (s1>=s2) System.out.println("[:=[first]"); else System.out.println("[second]=:]"); } } men paskallni yaxshi tushunmiyman C++ da kod quyidagicha yozilgan: #include<iostream> using namespace std; int main() { int n,m,s1=0,s2=0,i=0; cin>>n>>m; while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; }
//------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; }
} if(s1>=s2)cout<<"[:=[first]"; else cout<<"[second]=:]"; return 0; } | | 1820 Ural Steaks Explained - Simply - Accepted Solution - Read it before you start | Manoj Pathak | 1820. Ural Steaks | 13 Nov 2020 14:50 | 3 | Lets say there are 5 Steaks and capacity of pan is 4. Step 1: Cook first 4 one side for 1 minute. Step 2: Replace 1 one sided cooked steak with completely uncooked (remaining) one and cook for next 1 minute. Step 3: Now the chef has 3 completely cooked and 2 Half cooked. Cook the remaining 2 half cooked for another one minute. so 1 minute at each step, hence 3 minutes total minimal time. However, story doesn't end here :-). Lets take another example Now, Lets say there are 7 Steaks and capacity of pan is 4. Step 1: Cook first 4 one side for 1 minute. Step 2: Replace 3 one sided cooked steak with completely uncooked (remaining) three and cook for next 1 minute. Step 3: Now the chef has 1 completely cooked and 6 Half cooked. Cook 4 steaks from half cooked six for another one minute. Step 4: Last cook final 2 half cooked one for another one minute So total minimum time take is 4 minute. 1 minute at each step. Please keep in mind the scenarios where 0 steaks or steaks less then cooking capacity of pan. Edited by author 08.06.2017 20:19 Edited by author 08.06.2017 20:20 the scenario with n == 0 or k == 0 won't happen as in the statements it says 1 <= n, k <= 1000 | | WA 7 Help Please | Sharakshinov | 1640. Circle of Winter | 12 Nov 2020 22:27 | 1 | | | WA1 | kirdmiv | 1155. Troubleduons | 11 Nov 2020 23:53 | 1 | WA1 kirdmiv 11 Nov 2020 23:53 First sample != test 1 :( | | Почему на Паскале не проходит???????????????? | IT | 1502. Domino Dots | 11 Nov 2020 12:29 | 2 | var n:integer; s:real; begin read(n); s:=n*((n+1 )/2)*(n+2); write(s); end. округли 'round' У тебя 12.0 не пройдет,а надо 12 | | Solving using Python 3.8 x64 | wnik | 1510. Order | 11 Nov 2020 00:17 | 2 | Hi people. It looks like there is no one solution which used Python 3.8 x64. I use a linear algorithm (one pass, actually) but I still get TLE21. Are there any options for python or should I just use another language? Thanks. No worries, Boyer-Moore works well. My first approach was a bitwise (digit) based. It's a one pass as well, but a bit slower. | | Solution to that evil problem. | Mahilewets | 1224. Spiral | 10 Nov 2020 14:40 | 2 | answer = min(2*(n-1), 2*m-1); //don't forget about 32-bit signed integer overflow | | CLARIFICATION ABOUT 204 as Solution for n = 4 !!!!! | Sahil | 1586. Threeprime Numbers | 9 Nov 2020 11:43 | 1 | Here any three consecutive numbers means every three consecutive numbers. For Eg. if the four digit number is abcd then (abc) itself has to be a three digit prime and also (bcd) should also be a three digit prime. Taking the example for n = 5 let the 5 digit number be abcde then (abc) itself has to be a three digit prime, (bcd) should also be a three digit prime and at last (cde) should also be a three digit prime. If any of the problem setter reads this then please clarify clearly about this. As I was stuck on this for almost 2 days, by pondering how come the answer for n = 4 is 204 while even bruteforce was giving me 2513. Edited by author 09.11.2020 11:45 Edited by author 09.11.2020 11:45 | | WA 48. So strange... | Konstantin Verkhoturkin {det} [Licey №110 (math - inf)] | 1075. Thread in a Space | 8 Nov 2020 18:51 | 4 | I know that the task was rejudged. I added the condition for new test, where A, B and C collinear: cos(ACB) - 1.0 < eps, where eps = 1e-8, then answer = AB, but I've still get WA 48. Give me a hint, please. Thanks in advance. Now already accepted, I have found stupid bug in my code. Ignore first message. And what bug did you found? Just like you I've added a condition for test: 2 4 0 3 6 0 0 0 0 3 The answer is not NaN now, but I still have WA48. Try cases when all points belongs to one axis only: Case 1: 6 0 0 2 0 0 4 0 0 1 Case 2: 0 6 0 0 2 0 0 4 0 1 Case 3: 0 0 6 0 0 2 0 0 4 1 For all cases correct answer will be 4.51 Good luck! | | Hint | 👾_challenger128_[PermSU] | 1090. In the Army Now | 8 Nov 2020 18:46 | 1 | Hint 👾_challenger128_[PermSU] 8 Nov 2020 18:46 You should find the permutation with the maximum number of inversions. You can use segment tree to calculate inversions for each element, just store sorted leafes in each node. | | SSP solver | Orient | 1394. Ships. Version 2 | 8 Nov 2020 02:58 | 41 | Didn't know will it be useful for someone and is it on the right path to solve the problem, but I wish to publish this code for SSP solver. To invent good heuristics for MSSP is utmost harder. using I = short; template<typename T = I, typename S = I> struct DDP // dynamic dynamic programming solver for subset sum problem O(n^3 * 2^sqrt(n)) (n is number of input bits) { T terms[2][10001]; S sums[2][10001]; template<typename Term, typename Sum> std::pair<Term, Sum> solve(const Term termsBeg, const Term termsEnd, const Sum sumsBeg, const Sum sumsEnd) { static_assert(std::is_same<typename std::iterator_traits<Term>::value_type, T>::value, "!"); static_assert(std::is_same<typename std::iterator_traits<Sum>::value_type, S>::value, "!"); auto sumMax = std::max_element(sumsBeg, sumsEnd); auto termsSrc = terms[0]; auto termsDst = terms[1]; auto sumsSrc = sums[0]; auto sumsDst = sums[1]; *termsSrc = {}; *sumsSrc = {}; auto sumsSrcEnd = std::next(sumsSrc); for (auto t = termsBeg; t != termsEnd; ++t) { auto termsSrcBeg = termsSrc; auto termsDstBeg = termsDst; auto sumsSrcBeg = sumsSrc; auto sumsShiftedBeg = sumsSrc; auto sumsDstBeg = sumsDst; // merge unique assert(std::size_t(std::distance(sumsSrcBeg, sumsSrcEnd)) <= std::extent<std::remove_reference_t<decltype(sums[0])>>::value); while (sumsSrcBeg != sumsSrcEnd) { if (sumsShiftedBeg == sumsSrcEnd) { break; } I shiftedSum = *sumsShiftedBeg + *t; if (shiftedSum < *sumsSrcBeg) { *sumsDstBeg++ = shiftedSum; ++sumsShiftedBeg; *termsDstBeg++ = *t; } else { if (shiftedSum == *sumsSrcBeg) { ++sumsShiftedBeg; assert(*sumsShiftedBeg + *t != *sumsSrcBeg); } *sumsDstBeg++ = *sumsSrcBeg++; *termsDstBeg++ = *termsSrcBeg++; } assert(std::size_t(std::distance(sumsDst, sumsDstBeg)) <= std::extent<std::remove_reference_t<decltype(sums[0])>>::value); } if (sumsShiftedBeg == sumsSrcEnd) { sumsSrcEnd = std::copy(sumsSrcBeg, sumsSrcEnd, sumsDstBeg); termsDstBeg = std::copy_n(termsSrcBeg, std::distance(sumsDstBeg, sumsSrcEnd), termsDstBeg); } else { assert(sumsSrcBeg == sumsSrcEnd); sumsSrcEnd = std::transform(sumsShiftedBeg, sumsSrcEnd, sumsDstBeg, [t] (S s) { return s + *t; }); termsDstBeg = std::fill_n(termsDstBeg, std::distance(sumsDstBeg, sumsSrcEnd), *t); } std::swap(termsSrc, termsDst); std::swap(sumsSrc, sumsDst); for (auto sum = sumsBeg; sum != sumsEnd; ++sum) { sumsSrcBeg = std::lower_bound(sumsSrc, sumsSrcEnd, *sum); if ((sumsSrcBeg != sumsSrcEnd) && (*sumsSrcBeg == *sum)) { sumsSrcEnd = sumsSrcBeg; assert((*std::next(termsSrc, std::distance(sumsSrc, sumsSrcEnd)) == *t)); auto termsDstEnd = termsDst; do { auto term = *std::next(termsSrc, std::distance(sumsSrc, sumsSrcEnd)); *termsDstEnd++ = term; sumsSrcEnd = std::lower_bound(sumsSrc, sumsSrcEnd, *sumsSrcEnd - term); } while (sumsSrcEnd != sumsSrc); assert((std::accumulate(termsDst, termsDstEnd, S{}) == *sum)); termsDstBeg = termsDst; auto termsSrcEnd = t; assert(*termsSrcEnd == *termsDstBeg); auto termsTail = termsSrcEnd; while (++termsDstBeg != termsDstEnd) { while (*--termsSrcEnd != *termsDstBeg) { *termsTail-- = *termsSrcEnd; } } while (termsBeg != termsSrcEnd) { *termsTail-- = *--termsSrcEnd; } assert(std::distance(termsBeg, termsTail) + 1 == std::distance(termsDst, termsDstEnd)); auto term = termsTail; termsDstBeg = termsDst; assert(termsDstBeg != termsDstEnd); do { *termsTail-- = *termsDstBeg++; } while (termsDstBeg != termsDstEnd); assert(termsTail == std::prev(termsBeg)); return {term, sum}; // not past the end element for found range but exactly last element } } sumsSrcEnd = std::lower_bound(sumsSrc, sumsSrcEnd, *sumMax); // crop } return {termsEnd, sumsEnd}; } }; auto x = solve(std::begin(ships), std::end(ships), std::cbegin(rows), std::cend(rows)) if succeeded, it gives rearranged ships range such, that range [std::begin(ships), x.first] is a solution and sum of all ships is *x.second. [std::begin(ships), std::end(ships)) still consists of exactly the same ships. If not succeeded then it return a pair of std::end(ships) and std::cend(rows) Edited by author 11.06.2020 12:53 What algorithm do you use to pass 68 tests ? Edited by author 15.06.2020 21:48 I use bactracking and dynamic programming, it runs 30 seconds for the test 67th, the hardest one for my solution. Edited by author 17.06.2020 15:02 Edited by author 17.06.2020 15:37 it's too hard to figure out what's going on here! Not specific kind of algorithm but just a good seed. I have no backtracking. No dp or dfs over that primitive above. Free search by combining of ships from one of found rows with pool of ships that cannot form some of the rows. Here used stability of the algorithm above to rearrange ships for better mixing of them. 67 is also hardest test for mine. 8 solutions per minute on E5-2667 v2 when running 16 threads (I use -fopenmp to parallelize). 70 gives about 220 solutions for that configuration. Edited by author 17.06.2020 03:36 What algorithm do you use to pass 82 tests? is it the same one you described above? is it the same one you described above? The same, but with small improvements, which detect a situation when heuristics goes to infinite loop then reshuffles a part of partial solution. Strictly speaking above algorithm is only a part of the whole algorithm. Anyways that algorithm is just a heuristics. Although it is the only "beautiful" heuristics I can imagine, it is still a heuristics. (!!!) Just now I found, that full brute force for tests like 67, 70 and 80, which enumerates all the possible solutions (literally ALL (+ simple b&b of course)), finishes in 3 seconds max. Even if I don't exit when first solution is found. It is incredible after all that research in heuristics field. I think I'll publish the algorithm. Not too soon. After solving the problem. Thx. It seems it is mistake of OJ, because I cannot reproduce. jury must add a test in which several inputs are verified with single verdict: passed or failed to protect them from collecting information :) Edited by author 25.10.2020 06:23 I bet you have a number of 70+ tests)) only one, and realized that it would be faster to solve it by changing the heuristic parameter (every 3-5 works) than to spend 100+ submissions to determine it. You heuristics is fast. Mine is not. Can you give us a hint? > solve it by changing the heuristic parameter (every 3-5 works) Your heuristics is highly effective, if I understand correctly. Is it true, that you can select a parameter ("seed") for the heuristics by just 3-5 tries? For each hard test case. Then you write `for (int seed : {seed_test70, seed_test67, seed_test80, seed_test69, seed_test77, seed_test79}) heuristics(seed);` and even for test79 (e.g., here "last" one) all iterations run in less then 1 second? I.e. less then a small number of milliseconds per every seed value, you collect? Edited by author 26.10.2020 23:46 nothing like this, my solution is common for all test and direct randomization is minimal. Actually I have kind of deterministic one (stuck on test#67 and can't pass #82 too, but not critical) and ideas for improving it, but don't have motivation and time to do this. I'm not going to share an idea or give hints. Do you use one algorithm or you mix them ? Edited by author 29.10.2020 11:56 I use two algorithms. Heuristics and branch and bounded brute force. They called in the next order: 1 try of heuristics (I think 90% of tests are covered by this first one) (it take about 1-2ms), then highly clipped b&b brute force (I think it get about a couple of hundreds of milliseconds in worst case - on test 77 or 79 it fails and made complete (unsuccessful) enumeration through all clipped DoD), then infinite number of tries of the same heuristics (it get about first tens or mb one hundred of milliseconds average, but for some good seed (in fact I enumerate first 20 of them - two was good enough) it get mb less than ten milliseconds or so). A vast majority of test are covered by heuristics. It works well on those tests, that have big actual number of unique solutions. For these brute force produces too big number of solutions, that results in MLE. Heuristics is simple and have regular structure. Actually it can find solutions for any test, but for some of them (test67) the probability per try is too low to reliable fit in 1 seconds of time limit. On the contrary brute force is highly effective on those tests, which have one or two unique solutions (or maybe thousands -- don't even know, because I have only test67 and test70, which have such a property). Branch and bounding works highly effective on these. The only "cheating" to get solution for me was to find right seed for test79 (I don't know its structure and I want to collect it maybe). Don't even know how rare it -- I find it from the first try. Another cheating -- is to optimize. I made holes in DoD of brute force. So enumeration was reduced a lot for minor number of tests. Optimization is not valuable at all from algorithmic point of view. It is a bullshit full of magic numbers. My backtracking algorithm runs in 4.0 sec on Java and 8.0 sec on C++ for test 78, 0.178 sec on Java and 0.165 sec on C++ for test 67. I can conclude, that your backtracking algorithm is (exactly) as optimal as mine. I bet you use something like `std::vector<std::bitset<99>>` to store solutions per every row and something like `std::unordered_map<std::bitset<9>, std::unordered_set<std::bitset<99>>>` for branch and bounding, isn't it? Yes, you are right, but I use my bit set implementation. I have found another constraint but I don't know for now how to implement optimal! What is the constraint? Is it a secret for now? It's no secret, but it won't be fair to post it here OK, I think I'll come up with one too. Knowing that there is something besides `std::unordered_map<std::bitset<9>, std::unordered_set<std::bitset<99>>>` is enough. Edited by author 29.10.2020 18:39 > I use my bit set implementation Do you use _bit_scan_forward/_bit_scan_reverse when recover solution? Can it be an improvement over std::bitset? Yes, It can, but I don't think it will improve more than 0.1 second! Edited by author 31.10.2020 12:56 It is not critic recovering and saving solution! Anyways it is interesting to implement next-bit-set-iterator. Do you use parallel programing ? No. Because it have no sense. User time of all the threads are summed up. Edited by author 20.11.2020 22:00 Good to know. Do you want to trade our solutions when you solve?) Edited by author 26.10.2020 23:45 test 80 has 11881161 solutions! Your algorithm generate all of them in just 3 seconds!? > test 80 has 11881161 solutions! Your algorithm generate all of them in just 3 seconds!? I was wrong. The algorithm (backtracking) generates all the (15741649, "all the" contains a large amount of convention, because of branch and bounding) solutions for test80 in ~72 seconds. First solution found in 3.223853s for standard random seed and 0.563442s for search in lexicographical order. But my heuristics finds solution for test80 in 0.000041s and it goes before the backtracking, so test80 is not the problem at all. test67 (first solution): 0.290 (lexicographical order) test67 (complete enumeration, 1 solution): 0.373 (lexicographical order) test70 (first solution): 0.179 (lexicographical order) test70 (complete enumeration, 2 solutions): 0.187 (lexicographical order) Number of solutions for each separate line for test80 (lines sorted): 109 115 209 3981 4442 10091 38691 0 // this one is not even calculated, because not needed Hardware: Intel Intel(R) Xeon(R) CPU E5-2667 v2 @ 3.30GHz (3.90GHz Trubo Boost per single core, vs 2.40GHz (same arch) on OJ system). Specially bought for this problem). BTW test5 is a tough nut to crack for the algorithm. Edited by author 26.10.2020 22:38 Mind elaborating? Cannot see the linkage between this code and an O(n^3 * 2^sqrt(n)) algorithm. My email sunzheng.david[at]gmail.com. This is implementaton of third algorithm from "An Empirical Study of Algorithms for the Subset Sum Problem" O'Neil. It is not the code of solution of the whole problem (which is "multiple subset sum problem"), but a trivial part of it ("subset sum problem"). Hello, Orient, could you tell us more about your idea by email facttacf@gmail.com? | | why always wa#10 | abreto | 2110. Remove or Maximize | 7 Nov 2020 05:24 | 3 | dp[n][k] = max{dp[n-1][k] or a[n], dp[n-1][k-1]} any hints?? thank you. Edited by author 18.01.2017 13:16 3 2 7 6 1 Answer: 7 3 2 6 1 7 Answer: 7 because DP like this doesn't work lets consider next case 3 1 90 75 20 when we calculate last step we have: dp[3][1] = max(dp[2][1] or 20, dp[2][0]) now dp[2][1] = 90, dp[2][0] = 90 or 75 = 91 we are choosing max between (90 or 20) and 91, which is equal to 94 but this is incorrect answer correct answer is 75 or 20 = 95 | | Simple algorithm | Littel_John | 1083. Factorials!!! | 6 Nov 2020 18:45 | 1 | A simple way to solve is to begin with a value x which going to depend whether n % k == 0. and increase it by k until it becomes n. and of course on each step multiply it to your sum which is initially 1. |
|
|