| Show all threads Hide all threads Show all messages Hide all messages |
| WA1 With G++ | Keworker `~ | 2072. Kirill the Gardener 3 | 30 Jun 2024 16:55 | 1 |
Same program getting WA1 with G++ and AC with MVC++. Idk why. I use linear DP, i print answer with cstdio. |
| Why this taks can not be solved with Trie? :@@ | Giorgi Pataraia [Tbilisi SU] | 1414. Astronomical Database | 28 Jun 2024 18:19 | 5 |
It's just brute-force task :) There 36 lines in my AC code versus yours 165 lines :) Edited by author 08.03.2013 19:59 thanks, now AC with set :/ It can actually be solved with trie. My solution uses 0.4s (cin) and 20MB. Just store a map in every node. Solved with C++ with tree of static arrays of links, without any STL structures |
| O(1) c++ solution and BEST EXPLANATION | Mohamed | 1607. Taxi | 25 Jun 2024 16:29 | 3 |
i kinda changed the variables a = the first sum suggested by petr b = the ---------------------- taxi driver c = amount added by petr everytime d = ---------------- taxi driver we can say that at step n of bargaining: petr -> a + n*c taxi -> b - n*d where looking for a time when petr's suggestion is less than the drivers which means a + nc <= c - n*d but there sometime when petr suggest more than what the driver suggest the previous time. that's why i am comparing between the last petr's suggestion and the previous one of the driver a+c*n > b-d*(n-1). in this case petr says ok to the taxi driver and do not suggest more than that. void solve() { int a, c, b, d; cin >> a >> c >> b >> d; if (a >= b) { cout << a; return; } int n = (b-a)/(c+d); if ((b-1)%(c+d)!=0) n++; if (a+c*n > b-d*(n-1)) { cout << b - d*(n-1) << ln; } else { cout << a + n*c << ln; } } Edited by author 10.09.2022 21:11 could you help explain why: if ((b-1)%(c+d)!=0) n++; this is more simply code: int a, b, c, d; cin >> a >> b >> c >> d; if (a >= c) { cout << a; return; } int l = (c - a) / (b + d); a += b * l; c -= d * l; if (a + b <= c) cout << a + b; else cout << c; |
| Version 2 | andreyDagger`~ | 1911. Titan Ruins: Overtaking Fire | 22 Jun 2024 02:35 | 1 |
We need version 2 of this problem, where cart can be used in more than one tunnel |
| WA3 | Mortus | 1307. Archiver | 20 Jun 2024 17:20 | 1 |
WA3 Mortus 20 Jun 2024 17:20 string s = ""; int c; while ((c = getchar()) != EOF) s.push_back((char)c); Correct read input C++ |
| Почему надо запускаться от всех узлов? | >>> | 1463. Happiness to People! | 20 Jun 2024 09:38 | 2 |
я выбрал корнем вершину 1 и запускал в int main() дфс от этой вершины. Прошло 24 теста и упало на 25, но затем я запустился от всех вершин с условием if(!used[i]) dfs(i) и прошло. я не понял почему.. в условии не сказано, что это дерево, это может быть лес, то есть если запустить только один дфс, некоторые компоненты не обработаются |
| WA 4 | Mortus | 2157. Skydiving | 19 Jun 2024 19:38 | 1 |
WA 4 Mortus 19 Jun 2024 19:38 1 2 6 1 1 1000 answer: 1001.4472135955 |
| test 8 c# help please | Alexander_Real_Under | 1493. One Step from Happiness | 18 Jun 2024 20:27 | 1 |
my code using System; using System.Diagnostics; using System.Drawing; using System.Globalization; namespace Program; public static class Program {
public static void Main() { int number = Convert.ToInt32(Console.ReadLine()); string number_plus = Convert.ToString(number + 1); string number_minus = Convert.ToString(number - 1); char[] massiv_plus = number_plus.ToCharArray(); char[] massiv_minus = number_minus.ToCharArray(); string str_minus; string str_plus; while (massiv_minus.Length < 6) { str_minus = String.Join("", massiv_minus.Reverse()); str_minus += '0'; massiv_minus = str_minus.ToCharArray(); massiv_minus.Reverse(); } while (massiv_plus.Length < 6) { str_plus = String.Join("", massiv_plus.Reverse()); str_plus += '0'; massiv_plus = str_plus.ToCharArray(); massiv_plus.Reverse(); } int a1_plus = Convert.ToInt32(massiv_plus[0]); int a2_plus = Convert.ToInt32(massiv_plus[1]); int a3_plus = Convert.ToInt32(massiv_plus[2]); int b1_plus = Convert.ToInt32(massiv_plus[3]); int b2_plus = Convert.ToInt32(massiv_plus[4]); int b3_plus = Convert.ToInt32(massiv_plus[5]); int a1_minus = Convert.ToInt32(massiv_minus[0]); int a2_minus = Convert.ToInt32(massiv_minus[1]); int a3_minus = Convert.ToInt32(massiv_minus[2]); int b1_minus = Convert.ToInt32(massiv_minus[3]); int b2_minus = Convert.ToInt32(massiv_minus[4]); int b3_minus = Convert.ToInt32(massiv_minus[5]); if ((Math.Abs(a1_plus + a2_plus + a3_plus) == Math.Abs(b1_plus + b2_plus + b3_plus)) || Math.Abs(a1_minus + a2_minus + a3_minus) == Math.Abs(b1_minus + b2_minus + b3_minus)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } |
| Hint | InstouT94 | 2126. Partition into Teams | 17 Jun 2024 14:22 | 1 |
Hint InstouT94 17 Jun 2024 14:22 Lucas theorem, O(p * log(n)). |
| To admins 2 | andreyDagger`~ | 1163. Chapaev | 15 Jun 2024 04:18 | 1 |
|
| To admins | andreyDagger`~ | 1163. Chapaev | 15 Jun 2024 03:47 | 1 |
Admins, please add this to statement: "The coordinates are given with no more than 6 digits after a decimal point |
| Overrated | FaNato4kA_TiMoFeYa | 1061. Buffer Manager | 12 Jun 2024 00:47 | 1 |
Overrated FaNato4kA_TiMoFeYa 12 Jun 2024 00:47 |
| why my recursive solution is giving WA??? | Suparna | 1079. Maximum | 11 Jun 2024 21:50 | 2 |
int main() { long int n,res; while(1){ scanf("%ld",&n); if(n!=0){ if(n%2==0){ res=function(n-1); printf("%ld\n",res); } else{ res=function(n); printf("%ld\n",res); } } else{ return 0; } } //gives right ans in codeblocks but here gives WA....Why?? return 0; } long int function(long int n){ if(n==1){ return 1; } if(n%2==0){ return 1; } else if(n%2==1){ return function(n/2)+function(n/2+1); } } you have to print the maximux number of n range.but in recursive formula it alawys give the n th value . n th value and maximum value of n range is not same |
| How to apply DP??? | Saikot | 1005. Stone Pile | 11 Jun 2024 13:19 | 2 |
Can somebody tell me how to implement dp for this probelm? dp cant be applied to every problem Can somebody tell me how to implement dp for this probelm? |
| WA19 | andreyDagger`~ | 1845. Integer-valued Complex Determinant | 11 Jun 2024 01:58 | 1 |
WA19 andreyDagger`~ 11 Jun 2024 01:58 2 0 0 1 0 1 0 0 0 5 0 Possible answer: -1 0 |
| intuition | classenemy | 1009. K-based Numbers | 10 Jun 2024 21:04 | 1 |
When N=0, no number is there, or 0 is there. a[0]=1 When N=1, there are k such numbers, or 1..k-1. a[1]=k-1 When N=2, there are k^2-k such numbers. a[2]=>k^2-k =>(k-1)k =>(k-1)(k-1+1) =>(k-1)(k-1)+(k-1)*1 =>(k-1)a[1] + (k-1)*a[0] which can be used for all subsequent digits |
| Precalculate is not needed | Pearl | 1044. Lucky Tickets. Easy! | 3 Jun 2024 00:51 | 2 |
#include <iostream> using namespace std; int sumDigit(int n) { int sum = 0; while (n) { sum += n % 10; n /= 10; } return sum; } int main() { int n; cin >> n; if (n % 2 == 1) { cout << 0; } else { // We need to choose at most 4 digits, so the largest digit sum is 9*4 int count[9*4 + 1] = {0}; int halfN = n / 2; int maxNum = 9; for (int i = 1; i < halfN; ++i) { maxNum *= 10; maxNum += 9; } // Count the ways to create a particular sum for (int i = 0; i <= maxNum; ++i) ++count[sumDigit(i)]; // Now, for each number i whose digit sum are s, there are // count[s] numbers (including i itself) have the sum s. // So we have count[s] ways to choose the second half. int result = 0; for (int i = 0; i <= maxNum; ++i) result += count[sumDigit(i)]; cout << result; } return 0; } thanks a lot.It was really helpful |
| Read input until the end in C/C++ | Hristo Nikolaev (B&W) | 1226. esreveR redrO | 1 Jun 2024 22:02 | 2 |
Reading the entire input char by char can be done quickly this way: while ((input = (char)getchar())) { if (input == EOF) { break; } The canonical way is: while ((input = std::getc()) != EOF) { ... } |
| The Power of C# | Hikmat Ahmedov | 1723. Sandro's Book | 1 Jun 2024 21:15 | 7 |
/* ALGORITHM: In any substring that is encountered the most, at least one letter of that substring should be encountered the same time as the substring. So, we just need to find the most encountered symbol in the string. */ using System; using System.Linq; class Program { static void Main() { Console.WriteLine((from u in Console.ReadLine().ToArray() group u by u into gg orderby gg.Count() descending select gg.Key).ToList()[0]); } } Power of Python :) from collections import Counter print(Counter(input().strip()).most_common(1)[0][0]) Power of C/C++ int main() { //shitcode_fiveloops } // AC :) #include <The Power of me!> int main() { ThePowerOfMe.makeItAC(); } ...AC!:) Edited by author 25.04.2014 16:46 I think that one line could be enough. Console.WriteLine(input.GroupBy(c => c).OrderByDescending(g => g.Count()).First().Key); // the power of C++ :) #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { string s; cin >> s;
vector<int> v(30, 0); for (int i=0; i<s.size(); ++i) { ++v[s[i]-'a']; } auto c = distance(v.begin(), max_element(v.begin(), v.end())); cout << (char)('a'+c); return 0; } Slightly shorter C++ version of Raphael: #include <algorithm> #include <cstdio> int main() { size_t v[26]{}; char c; while ((c = std::getc(stdin)) != EOF) ++v[c - 'a']; std::putc(static_cast<char>('a' + std::distance(v, std::max_element(v, v + 26))), stdin); return 0; } Edited by author 01.06.2024 21:37 |
| Some hints | Sayem | 1014. Product of Digits | 1 Jun 2024 18:47 | 3 |
The authors should've mentioned these in the question. Like if q is 0 then you should print 10 but if it is any number between 1 to 9 then you should print that number only, i.e. 2 for 2, 4 for 4 not 14 for 4. Thanks, that saved me a lot of time. I was printing 0 for 0. Which makes sense in my opinion. thanks to you .It was really helpful |