| Show all threads Hide all threads Show all messages Hide all messages |
| Optimize your solution if you got TLE. | wiwi | 2102. Michael and Cryptography | 25 Nov 2020 20:01 | 1 |
I thought that using the sieve of Eratosthenes would slow down the program, but it turned out the opposite. |
| To everybody who had solved this problem | Renat Mullakhanov | 1188. Library | 25 Nov 2020 01:56 | 5 |
What is the output for this test? 996 997 754 543 100 42 25 119 17 70 96 293 581 96 391 57 102 888 313 458 55 238 385 15 195 3 576 216 47 117 41 75 849 407 769 87 25 884 319 620 66 94 886 27 552 86 561 377 149 206 90 413 209 74 198 78 32 914 11 840 7 76 814 288 447 72 42 892 370 579 82 42 813 165 677 26 123 561 104 424 38 14 521 154 368 2 120 63 4 38 88 43 887 76 772 71 113 750 88 384 24 78 255 87 138 17 59 862 263 760 44 272 386 117 255 33 368 453 223 330 77 148 846 214 480 76 191 671 219 487 46 305 685 332 436 15 197 356 15 254 37 203 406 74 362 84 14 916 157 603 68 102 287 57 167 98 340 560 81 331 40 7 986 251 728 91 116 791 251 412 92 53 486 13 330 61 8 268 107 217 65 467 304 49 304 22 25 924 250 471 63 430 73 12 38 25 456 462 110 318 80 435 389 102 288 34 673 84 13 59 18 714 7 0 5 32 208 602 7 571 97 189 307 50 232 28 10 836 280 491 56 601 119 42 78 95 36 312 28 229 8 63 821 273 479 35 117 279 126 168 89 195 787 162 421 45 658 59 26 39 74 857 106 18 58 94 269 677 48 445 10 79 636 134 572 31 65 842 214 673 62 294 395 51 308 100 239 197 51 133 20 758 209 10 194 39 26 900 437 721 51 56 712 197 536 6 256 553 93 334 9 210 662 57 598 58 558 371 185 309 47 294 535 222 439 81 265 728 100 713 13 107 464 212 349 27 8 987 137 644 67 43 480 78 355 79 197 644 185 596 99 567 64 10 36 21 62 781 254 502 23 968 5 0 4 69 69 849 92 599 36 66 585 92 382 49 8 747 110 618 73 329 79 9 69 16 366 217 14 161 70 468 527 245 283 93 149 547 252 498 48 35 883 9 797 52 138 611 108 401 60 286 430 104 222 53 119 188 90 152 1 199 505 24 502 5 149 603 73 477 43 325 577 224 399 75 179 709 254 483 29 42 597 212 537 54 585 140 45 105 19 9 680 97 664 11 58 886 281 847 12 223 96 42 93 4 578 228 10 211 14 27 563 94 368 83 67 895 178 778 30 51 882 225 579 50 304 637 315 332 59 99 850 127 762 64 346 19 1 19 85 270 502 185 306 I haven't got AC but this is my answer for this test : 16 3005 16 3005 is right! :-) I've AC :-) Good test :) With all that weird positioning I forgot about L>=XT for basement shell :P Why are there two boards in line 7 |
| if you have WA12 or WA20 try this tests | D4nick | 1354. Palindrome. Again Palindrome | 25 Nov 2020 01:37 | 1 |
abbb answer: abbba abbbb answer: abbbba Edited by author 25.11.2020 01:48 Edited by author 25.11.2020 01:50 |
| TLE#9 C# how make it faster? =( | Shamov Roman | 1671. Anansi's Cobweb | 24 Nov 2020 12:50 | 2 |
Can someone help how to make C# code faster? Here is my code: using System; using System.Collections.Generic; class Program { static int countCut(List<int>[] nods, List<int> uncheckedNodes) { int next = 0; int count = 0; do { count++; watchCut(nods, uncheckedNodes, next); if (uncheckedNodes.Count > 0) next = uncheckedNodes[0]; else next = -1; } while (next != -1); return count; } static void watchCut(List<int>[] nods, List<int> uncheckedNodes, int node) { uncheckedNodes.Remove(node); for (int i = 0; i < nods[node].Count; i++) { if (uncheckedNodes.Contains(nods[node][i])) watchCut(nods, uncheckedNodes, nods[node][i]); } } static void Main(string[] args) { string[] inp_NM = Console.ReadLine().Split(' '); int N, M; N = Convert.ToInt32(inp_NM[0]); M = Convert.ToInt32(inp_NM[1]); int[,] threads = new int[M, 2]; List<int>[] nods = new List<int>[N]; for (int i = 0; i < N; i++) nods[i] = new List<int>(); for (int i = 0; i < M; i++) { string[] inp_thread = Console.ReadLine().Split(' '); threads[i, 0] = Convert.ToInt32(inp_thread[0]) - 1; threads[i, 1] = Convert.ToInt32(inp_thread[1]) - 1; nods[threads[i, 0]].Add(threads[i, 1]); nods[threads[i, 1]].Add(threads[i, 0]); } int Q; Q = Convert.ToInt32(Console.ReadLine()); int[] cuts = new int[Q]; string[] inp_tear = Console.ReadLine().Split(' '); for (int i = 0; i < Q; i++) { cuts[i] = Convert.ToInt32(inp_tear[i]) - 1; } for (int i = 0; i < Q; i++) { nods[threads[cuts[i], 0]].Remove(threads[cuts[i], 1]); nods[threads[cuts[i], 1]].Remove(threads[cuts[i], 0]); List<int> uncheckedNodes = new List<int>(); for (int l = 0; l < N; l++) uncheckedNodes.Add(l); Console.Write(countCut(nods, uncheckedNodes)+" "); } } } Edited by author 24.11.2020 08:00 In this problem you should use disjoint-set(система непересекающихся множеств). |
| If you have MLE. | wiwi | 1635. Mnemonics and Palindromes | 22 Nov 2020 16:44 | 1 |
I had MLE on test 33. I just changed int to short and 1,0 to bool Sorry if this is too obvious Edited by author 22.11.2020 16:48 |
| Look up Fermat's last theorem | Yongye | 1349. Farm | 22 Nov 2020 14:12 | 1 |
|
| Why do I get WA 1??? | Bebop | 1585. Penguins | 22 Nov 2020 09:33 | 1 |
#include <iostream> #include <string> #include <vector> #include <set> const std::string &solution(const std::vector<std::string> &penguins); int main() { int n; std::cin >> n; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::vector<std::string> penguins; penguins.reserve(n); for (int i = 0; i < n; ++i) { std::string penguin; std::getline(std::cin, penguin); penguins.emplace_back(std::move(penguin)); } std::cout << solution(penguins) << std::endl; return 0; } const std::string &solution(const std::vector<std::string> &penguins) { std::set<std::string> penguinSet(penguins.begin(), penguins.end()); auto setIterator = penguinSet.begin(); std::set<std::string>::iterator mostNumerous; int maxCount = 0; while (setIterator != penguinSet.end()) { int count = 0; for (const auto &penguin : penguins) { if (*setIterator == penguin) { count++; } } if (count > maxCount) { maxCount = count; mostNumerous = setIterator; } setIterator++; } return *mostNumerous; } I tested locally and it works... |
| Problem 1115 "Ships" now has 2 versions. | Vladimir Yakovlev (USU) | 1394. Ships. Version 2 | 22 Nov 2020 03:40 | 13 |
Problem 1394 "Ships. Version 2" is the same problem as 1115 but has full testset. Problem 1115 has only first 10 tests. All latest submissions on 1115 were moved to new problem. You can resubmit you solutions to 1115 also if you want. Problem 1115 was rejudged with 10 tests. But some submissions got WA. So change the text 1115, because two problems now have the same limits for N, M and interval length. Or just delete the problem 1115. If you can write a solution that works within 5-10 seconds for any test I make, I wolud increase TL. Wouldn't you like to share with us? up Safe Bird 3 Dec 2005 12:45 I use two algorithms inside one program: First I try to arrange ships using heuristics with randomization. If it fails for many times (say, 1000 times) I use bruteforce with optimizations (just like many people) I found a big numbers of different bruteforces and heuristics for this problem. I have tests for all that methods. You need just one good combination! My program works well on all tests, I've already checked more than 30 billions random tests. A little hint: my bruteforce gets TLE 22, heuristics gets TLE 17. Good luck! Oh, my Safe Bird 26 Jan 2006 08:35 the idea is great! I have thought for too many strange ideas like netflow.....but not this one! i gonna try to solve it right now. Where is your good solution at now? The present-day test is too tough for your algorithm? If this the edge, it may be worth keeping the time limit so that one top solution has always been AC. It will be reasonable to increase the TL to 3s. It is required to inspect all the current solutions thoroughly to decide whether all of them have some "tweaking" for specific tests or not. If any of them is universal (i.e. actually not depends on any seed or magic number), then time limit can be even capped on that. If not, then it is reasonable to increase TL somehow. I can bet that some of accepted solutions will not pass for some permutation of actual tests and that is not ok when them will require to be adjusted in order to pass! Edited by author 21.11.2020 11:53 I sort input before use. What do you mean? Edited by author 16.12.2020 00:35 |
| C# hint | Zergatul | 2148. Insane Shot | 19 Nov 2020 04:59 | 1 |
Don't use double or you will suck hard. My formulas are definitely correct (because I got AC), but with double and framework functions like Math.Sqrt I was getting very big inaccuracies (about FEW degrees for angles between tangent and shots). Then I switched to BigInteger and got AC immediately. Edited by author 19.11.2020 04:59 |
| What can be the reason of WA 11? I'll be glad if you give some tests. | D4nick | 1118. Nontrivial Numbers | 19 Nov 2020 04:35 | 3 |
#include <iostream> using namespace std; int main() { long long i, j, iDel; long long biggestV = 9999999, biggestDel = 9999999; cin >> i >> j; if (i == 1) { cout << 1; return 0; } else if (i == j) { cout << i; return 0; } else if (i + 1 == j) { cout << (j % 2 != 0 ? j : i); return 0; } for (long long iV = j % 2 != 0 ? j : j-1; iV >= i; iV -= 2) { for (iDel = j / 3 + 1; iDel >= 1; iDel--) { if (iV%iDel == 0) { if (iDel < biggestDel) { biggestDel = iDel; biggestV = iV; } break; } } if (iDel == 1) { cout << iV; return 0; } } cout << biggestV; } In the main cycle you doesn't compare trivialities, you search the smallest biggest divisor in the weird range instead. Could you please show the mathematical proof of your main cycle? Edited by author 31.03.2020 14:11 Edited by author 31.03.2020 14:12 Hi.Did you solve this problem? |
| Why wa 11?? | wiwi | 1118. Nontrivial Numbers | 19 Nov 2020 04:28 | 1 |
---- ll l,r; cin >> l >> r; if(l==1){ cout << 1; return 0; } if(l == r){ cout << l; return 0; } ll n = 1e6+2; vector<bool> prime(n+1,1); prime[0]=prime[1] = 0; for( ll i =2; i*i <= n; i++) { if(prime[i]) { for(ll j = i*i; j <= n; j+=i) prime[j]=0; } } for(ll i = r; i >= l; i--){ if(prime[i]) { cout << i; return 0; } } double mx =1e11; ll ans = 0; for(ll i = r; i >= l; i--){ if(i % 2 == 0) continue; double suma = 1; for(ll k = 2; k*k <= i; k++){ if( i % k == 0 ){ suma += k; if(i/k != k){ suma += (i/k); } } } double q=(suma)/(i); if( q < mx){ mx = q; ans = i; } } cout << ans; return 0; ---- I used the sieve of Eratosthenes to find prime numbers. If I have not found prime numbers on the interval [l; r], then I iterate over all numbers with [l; r]. I go through the divisors (sqrt (i)). I calculate the minimum. What's wrong? WA 11. Google translator, sorry. |
| AC | D4nick | 2029. Towers of Hanoi Strike Back | 17 Nov 2020 17:02 | 1 |
AC D4nick 17 Nov 2020 17:02 if you wanna get 20 lines solutions, write me on dalydudan@gmail.com |
| 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; } |