### jinlifu1999's blog

By jinlifu1999, history, 10 months ago, ,

Code (C++ version)

Code (C++ version)

Code (Python version)

Code (C++ version)

Code (Python version)

Code (C++ version)

Code (C++ version)

Code (My stupid solution: C++ version)

Code (demon1999's fast solution: C++11 version)

UPD1: Note that the editorial of problem E is modified with some correction. Sorry for that inconvenience.

UPD2: The editorial is complete now. Hope you find it useful. :P

UPD3: It's seems that all bonus questions can be found in the comments. :) Don't hesitate to give them an upvote. :P

UPD4: The editorial is updated.

•
• +121
•

 » 10 months ago, # | ← Rev. 2 →   -20 For B, instead of going for every number, we can move at intervals of 9 probably?
•  » » 10 months ago, # ^ |   -26 yes you can but you have to go for brute for near every multiple of 100.
•  » » » 10 months ago, # ^ |   -26 http://codeforces.com/contest/919/submission/34774559Its just simple checking.... seems good to go.
•  » » 10 months ago, # ^ | ← Rev. 2 →   -18 In B I precomputed all the values and hardcoded all the values in an array for an O(1) solution .. But my code was too large in size so I only stored the values for k=5000 upwards
 » 10 months ago, # |   -21 My solution for B question has complexity O( k * (log(2 * 10^7)[base 9]) * 10 ).Source code: linkIs this the optimized one that you are talking about @jinlifu1999
 » 10 months ago, # |   -15 For B, Bonus1: Iterate from 1 and for every number n whose sum of digits is less than 10, answer is concatenation of n and 10 - sum(n). This is 10 times faster than mentioned brute-force.Submission
•  » » 10 months ago, # ^ |   -16 I also thought of this approach but this is not efficient for solving Bonus2. Do you have any idea, how to solve for Bonus2?
•  » » » 10 months ago, # ^ | ← Rev. 2 →   0 Binary Search + DP. We binary search over the answer and for a fixed ans we check how many numbers smaller or equal to this has digit-sum 10 using DP. And whether that is grater, equal or smaller than given k.My Solution. We would have to use Bigint and larger constraints for the DP for it to work for k upto 10^18.
•  » » » » 10 months ago, # ^ |   +1 Actually, you don't need to use binary search. http://codeforces.com/contest/919/submission/34803226 The complexity is O(number of digits in answer * 10) for computing the table ignoring the need to use BigInt.
•  » » » » » 10 months ago, # ^ |   0 Could you please explain your idea a bit. I saw your code but didn't quiet understand what you were doing.
•  » » » » » » 10 months ago, # ^ | ← Rev. 2 →   +1 dp[i][s] = number of numbers with i digits (leading 0-s counts) and sum of digits sEvery possible number [i][s] is a path from [i][s] to [0][0]. So you start looking at some number of digits and the sum you want. Try putting a 0 in the last position. dp[i — 1][s — 0] is the number of such numbers. If that's lesser than the n that you are looking for, you know that the number you want has some number greater than 0 in this position, so you exclude the numbers that have the same prefix and 0 in this position (n -= dp[i — 1][s — 0]) and try it for 1. Keep on trying for all the next digits 0 <= j <= 9 until n <= dp[i — 1][s — j]. Now you know that the number you are looking for has digit j in this position and can do the same process for i — 1 until getting to i == 0.
•  » » » » » » » 9 months ago, # ^ |   0 Awesome idea!! You must have a deep understanding in dp. The way you formulate dp[i][j] really surprised me (dp in dp)! Learned a lot from your word and code. But I think n >= dp[i — 1][s — j] should be n <= dp[i — 1][s — j]. Is that right?
•  » » » » » » » » 9 months ago, # ^ |   0 That's right! My mistake.
 » 10 months ago, # | ← Rev. 4 →   -10 jinlifu1999http://codeforces.com/contest/919/submission/34773513http://codeforces.com/contest/919/submission/34770710Same Solution. Different Verdict . What type of Judge ?
•  » » 10 months ago, # ^ |   0 Java programs inherently use more memory than C/C++ programs. Using System.gc() might help (it recommends invoking the garbage collector, but just like inline functions in C, there is no guarantee that it will happen).
•  » » » 10 months ago, # ^ |   -11 Java Compiler Automatically collects garbage whenever not necessary. So no need for any external Garbage Collector. And If Java Programs uses more memory Why There are no different memory limits for different languages ?
•  » » » » 10 months ago, # ^ |   +10 That's the thing, the java garbage collector is invoked whenever it "thinks" there's some memory to free, but that may not be immediately apparent to it (how does it know for sure you won't be needing this bit of memory in the future?). System.gc() doesn't invoke an "external Garbage Collector", it invokes the normal java garbage collector (or at least it recommends its invocation), but it invokes it NOW (at the point of the instruction), not when the system finds it necessary.I've had some problems in the past where a well-placed System.gc() made the difference between MLE and Accepted (I've also had situations where using that instruction made things worse... the gc is just very unpredictable).As for your second question, on some online judges there ARE actually different memory limits for Java :). There might also be some problems on codeforces which have different memory limits (not sure). Just not this one :)
•  » » 10 months ago, # ^ |   0 By the way, in the Java solution you use LinkedList to store the graph, whereas in the C++ solution you use vector, which is the equivalent of ArrayList in java. Not the same thing :). Linked lists inherently occupy more memory (there's pointers to be stored in addition to the data).I've replaced LinkedList with ArrayList in your solution and it got accepted. As a general rule of thumb, never use linked lists unless you specifically need them for something (for example, deletion of elements form the middle).
•  » » 10 months ago, # ^ |   +16 Just use C++, I used java in the past and it sucked.
 » 10 months ago, # |   0 The k=1 case in problem C does hurt lol. Got hacked, though my code is fairly straightforward still.Also, is it a right way to solve D by merging strongly-connected components into one node and do the calculations? Just discussed with my friend and I haven't tried this approach.
•  » » 10 months ago, # ^ |   0 Mans not lonely
•  » » 10 months ago, # ^ |   +4 In D, if you have a SCC of size > 1 then you have a cycle and just output -1. In the other case, every SCC must have size = 1 so there is no need to "merge" them, because is the same as using the original nodes.So for your answer, I think it is valid but it is unnecesary :p
•  » » 10 months ago, # ^ |   +3 For a DAG, the number of strongly connected components is equal to n (the number of nodes)
 » 10 months ago, # |   +5 To be precise complexity of brute force in B is O(ans * log(ans)) :D
•  » » 10 months ago, # ^ |   0 Yeah, since you need to add all the digits, which requires logarithmic number of additions.
»
10 months ago, # |
+2

CANNOT UNDERSTAND WHAT IS WRONG WITH THIS CODE..ITS GIVING 0.00000 for the first test case...works fine on my compiler

# include<stdio.h>

int main()
{
double n,m,a,b;
int i;
double min=100000;
scanf("%lf%lf",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lf%lf",&a,&b);
double c=m*(a/b);
if(c<min)
{
min=c;
}
}
printf("%lf\n",min);
return 0;
}
•  » » 10 months ago, # ^ |   0 What compiler are you using for submitting? You can also try to use cout, input/output is the only I see that could be giving the error
•  » » 10 months ago, # ^ |   0 The code you posted works just fine. I submitted it now and got acc.
•  » » 10 months ago, # ^ |   0 To print double you should use %f format specifier in printf due to floating point promotion in functions with variable number of arguments (printf is such a function). So I just deleted 'l' in "%lf" in printf and got AC: 34779977
•  » » » 10 months ago, # ^ | ← Rev. 3 →   0 %lf is the correct format specifier for double%f is the format specifier for floatFloating point promotion means float gets promoted to double, which means you should always use %lf instead of %f (not the other way around). However, for that very reason, (for printf at least) %f is exactly the same as %lf. It's not that %lf doesn't work due to promotion, it's that %f ALSO works due to promotion.The above code works just fine (I submitted it and got ac, with %lf, just like it was posted). No need to modify anything.EDIT: I'm talking about C++ 11 and later (I don't know the standard all that well for previous iterations). As I'm typing this it occurs to me the question was not meant for C++, but for C and it seems like %lf for printf does indeed cause undefined behavior for C90 standard and lower (but codeforces uses newer standard, so the posted code still gets accepted even with C compiler).
•  » » » » 10 months ago, # ^ |   0 What I've written is just a simple way to remember where to use %f and where to use %lf. But the best way to remember that is to learn it.I was talking about C11 standard of language C. I chose this standard because first submission of vivekchandela2 for this task used exactly this standard. Here you can check it: 34744000.
•  » » 10 months ago, # ^ |   0 maybe you need to specify the number of decimal places. like printf(%.10f, min);
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 Try submit using a different compiler. Like GNU C ++ 11.
 » 10 months ago, # |   0 Faster brute force for B which skips some iterations if sum of digits(of current iteration) become > 10 and jumps to nearest number(greater than that of current iteration) which has sum of digits < 10.Brute force mentioned in tutorial won't work in JAVA or Python.http://codeforces.com/contest/919/submission/34775820
 » 10 months ago, # |   +6 Please add Tutorial for Problem F as well.
 » 10 months ago, # |   0 can anyone please tell why am I getting TLE(in 15th test case) IN 4TH question ?https://ideone.com/Kpl1jy
 » 10 months ago, # | ← Rev. 3 →   0 can anyone explain why I am getting tle on test case 32 in problem d(Java)? http://codeforces.com/contest/919/submission/34773289update: same c++ solution of mine is got accepted but it is giving tle in java. link to c++ code http://codeforces.com/contest/919/submission/34778298
 » 10 months ago, # |   +1 There should be a nice and fairly easy solution for problem E with generators (prime roots). We know which power of g is a, which one is g, so we are just left with a simple congruence on exponents. Finding stuff can be done in O (p) instead of writing some sqrt algorithms, because p is nice
•  » » 10 months ago, # ^ |   +7 Miyukine would you please explain in more details. i am very weak in maths.
 » 10 months ago, # |   0 Is the brute-force for B really O(answer)? I mean.. computing the sum of digita on n takes log(n) time does it not?
•  » » 10 months ago, # ^ |   0 with base 10; that is at max 7, which can be considered a constant.
•  » » » 10 months ago, # ^ |   0 Time complexity is about infinitely large inputs, so you can't just say "it's considered" to be a constant. Though in this problem, it's indeed quite trivial, but it's still an O (answer * log (answer)) solution.
•  » » » » 10 months ago, # ^ |   0 If the input is infinitely large, I don't think we should worry about complexity at all. It will just take infinite time not matter what the complexity is.My point was that since the base is 10; its even smaller factor than our regular log2n
•  » » » » » 10 months ago, # ^ |   +6 That's right. The factor is really small. However, mouse_wireless was talking about the complexity, not how much actual time it takes within the input range, and that is what it means.Time complexity is about how the time "asymptotically increases" as the input increases infinitely. Therefore, it's about the algorithm itself, not about the actual time consumed for "some" inputs.Bubble sort has worst case complexity of O(N^2). You can say that if N is like 3, the factor is very small so you can almost ignore it. But no matter what that N is, it doesn't change that the complexity of bubble sort is still O(N^2), because it's the property of the algorithm itself.I see your point but you should choose correct words.
•  » » » » » » 10 months ago, # ^ |   0 I was trying to tell mouse_pointer not to nitpick such a small factor but I guess lots of people are too sentimental about it.
•  » » 10 months ago, # ^ |   +3 My solution is O(answer) using O(answer) memory for memoization of the sum of digits. http://codeforces.com/contest/919/submission/34749833 :P
 » 10 months ago, # | ← Rev. 3 →   +10 Can somebody elaborate on Div2E I seem to be deriving j - i ≡ b·a - j(mod p)Thanks!Edit: They edited the editorial, all clear now :)
•  » » 10 months ago, # ^ |   -14
•  » » 10 months ago, # ^ | ← Rev. 3 →   0 You are correct too, next line in the editorial explains your result. You equation becomes: j = b.a^-j + i*p (mod p) Edit: no this is wrong, should be j = b.a^-j + (p+i) (mod p) (editorial is clearer now)Now read the next line in the editorial: the possible i can only be b·a - j, p + b·a - j, ..., p·t + b·a - j. Then we can calculate how many possible answers n in this situation (i.e. decide the maximum possible t using the given upper bound x).
•  » » » 10 months ago, # ^ | ← Rev. 2 →   +1 mkagenius sorry but I don't see your point ?
•  » » » » 10 months ago, # ^ |   0 No, that’s wrong you cannot add p, 2p, ...., tp from thin air. Their mod p is not 0. They have to come somewhere from the equation.
•  » » » » 10 months ago, # ^ | ← Rev. 3 →   0 It's like saying 2 = 2, 2 = 2 + 0, 2 = 2 + 2 * 0 ..., 2 = 2 + t * 0We can add any multiple of p to both sides because any multiple of p is zero modulo p
•  » » » 10 months ago, # ^ |   0 in editorial i=y mod p and what is (i-y+p)%p stand for? why i-y?
•  » » » » 10 months ago, # ^ | ← Rev. 2 →   0 They have updated the editorial, it should be clearer now.
•  » » » » » 10 months ago, # ^ |   0 finally ,it is really clear now
•  » » 10 months ago, # ^ |   +1 I didn't understand what they mean by looping section?
•  » » » 10 months ago, # ^ |   0 The given term n*a^n mode p has a period of p*(p-1) always (sometimes less, but definitely repeats after p*(p-1) terms)
 » 10 months ago, # |   0 Can someone tell me why my submission for C fails in TC 32 ?
•  » » 10 months ago, # ^ |   +1 Swap these lines:  char** c = new char*[n]; and  cin >> n >> m >> k; 
•  » » » 10 months ago, # ^ |   0 Thanks <3
 » 10 months ago, # | ← Rev. 2 →   +19 My solution here for B is 34769949First, let’s binay search the answer xThen our job is to check if there are more than k perfect numbers less than xLet f(i,j) represent for the previous i digits, the sum is j, how many numbers can we have. Which is a classical digital dp.I was retarded during the contest and thought k was smaller than 1e5, that’s why I solved B last and didn’t work out E, R.I.P.
•  » » 10 months ago, # ^ |   +5 You aren't the only one. Exactly same thing happened to me.
 » 10 months ago, # |   0 Why my code for D is giving wrong answer in TC 7. I used dfs to count the frequency in every path. In the worst case scenerio my code should give TLE, but I can not comprehend why it is giving me wrong answer. Here is my implementation.
•  » » 10 months ago, # ^ |   0 Hi, maybe is because of the line vis[i] = true; in the for in solve function
•  » » » 10 months ago, # ^ |   0 Thanks. I see the mistake now. Anyway my way of solving this will give tle because of brute force approach.
•  » » » » 10 months ago, # ^ |   0 yeah but it is not difficult to change, only add some memoization since the graph now is acyclic.
•  » » » » » 10 months ago, # ^ |   0 I am not that comfortable with DP, Can you show me how can I use memoization. [ I am aware of the concept]. Here is my TLE code. Thanks in advance.
•  » » » » » » 10 months ago, # ^ |   0 this is my implementation.So basically you try to count for every letter what is the maximum number of times can appear in any path starting at node u. And the maximum is the answer.
 » 10 months ago, # |   +5 I hacked 2 people in problem C, because they're not careful when k=1.
•  » » 10 months ago, # ^ |   +3 I hacked 10 people in problem C, because they're not careful when k=1.
•  » » » 10 months ago, # ^ |   0 I was hacked immediately after I submitted problem C, for i'm not careful when k = 1.Well...it could be worse, at least i have a chance to correct it.
 » 10 months ago, # | ← Rev. 3 →   +2 I use dfs+dp in problem D. Dfs to find cycle. When there is a cycle, I will output -1. Dp to calculate which is the maximum number.
 » 10 months ago, # |   +3 You needn't judge every number in problem B. You only need to judge x which x%9==1.
 » 10 months ago, # |   0 Can someone tell me why my solution for D fails?
 » 10 months ago, # |   0 What's wrong with this code?460C
•  » » 10 months ago, # ^ |   +7 In your code, line 27... for(int j = 0; j < m; j ++) { for(int i = 0; i < m; i ++) //here, m -> n { s += c[i][j]; 
 » 10 months ago, # |   +5 Problem E was such a nice number-theory problem for beginners :D
 » 10 months ago, # | ← Rev. 4 →   +5 In problem E, the 'looping' mentioned in the editorial mod p(p - 1) can be proved.From Euler's Theorem, , for any integer n. Since φ(p) = p - 1, we only need to consider powers of a ranging from 0 to p - 2. This gives us two congruences: This system of congruences then has a unique solution mod p(p-1)), by the Chinese Remainder Theorem, which gives us the 'looping'.Edit: Fixed formatting and notation: Fermat's Little Theorem -> Euler's Theorem.Edit 2: The proof also gives a way to solve the problem using the Chinese Remainder Theorem, which is slightly different from the method mentioned in the editorial in its approach.The idea follows directly from above: for each $i$ from 0 to p - 2 the above system of congruences can be solved uniquely mod p(p - 1), and the contribution of each of these to the final answer can be counted easily.See 34764463.
•  » » 9 months ago, # ^ |   0 In the editorial why did we take n = i*(p — 1) + j ?
 » 10 months ago, # | ← Rev. 2 →   0 Can anyone please help with Problem D... this solution is giving wrong on test 7.The test case is huge to manually check it.Thank youhttp://codeforces.com/contest/919/submission/34794840
•  » » 10 months ago, # ^ |   +1 try this date case5 5 abaaa 1 2 1 5 2 3 3 4 5 3The true answer is 4You did not think about the nodes you visited before(the nodes that visi[i] == true)
•  » » 10 months ago, # ^ |   +4 Try this: 3 2 aaa 1 2 3 1 : )
 » 10 months ago, # |   0 Auto comment: topic has been updated by jinlifu1999 (previous revision, new revision, compare).
•  » » 9 months ago, # ^ |   0 could you tell the way on how to solve problem B by (dp+binary.s) or any other for BONUS 1 and 2(sorry for my bad English :P)
 » 10 months ago, # |   0 Auto comment: topic has been updated by jinlifu1999 (previous revision, new revision, compare).
 » 10 months ago, # |   0 Can Someone please Explain E from expressing n as i*(p-1)+j.Thank you.
 » 10 months ago, # |   0 Auto comment: topic has been updated by jinlifu1999 (previous revision, new revision, compare).
 » 10 months ago, # |   0 Can you please explain how did you get C(m+k-1,k) in F?
•  » » 10 months ago, # ^ |   +3 That is nothing but number of solutions to x0 + x1 +x2+x3+ x4 =8 in this question. Similarly extend to general case
 » 10 months ago, # |   0 Problem CWhy is my code so slow?http://codeforces.com/contest/919/submission/34798301
 » 10 months ago, # |   0 hey! can you please explain why i got a TLE error on this code? it seems pretty optimized to me! thanks :) #include #include #include using namespace std; typedef vector vi; typedef set si; typedef vector vsi; vsi edge; vector nodes; vector visit; int maxnum = -1; bool cycle = 0; void dfs(int cur, vi dp) { visit[cur] = 1; if(maxnum < ++dp[nodes[cur]- 'a']) maxnum = dp[nodes[cur]- 'a']; for(auto i: edge[cur]) { if(cycle == 1) return; if(visit[i] == 1) { cycle = 1; return; } dfs(i, dp); } visit[cur] = 2; } int main() { ios::sync_with_stdio(false); int n,m; cin >> n >> m; visit.resize(n); edge.resize(n); vi inedge(n); for(int i = 0; i < n; i++) { char c; cin >> c; nodes.push_back(c); } for(int i =0; i < m; i++) { int x,y; cin >> x >> y; if(x == y) cycle = 1; else { edge[x-1].insert(y-1); inedge[y-1] = 1; } } vi dp(26); for (int i = 0; i< n; i++) { if(visit[i] == 0 && inedge[i] == 0) dfs(i, dp); if(cycle == 1) break; } if(cycle == 1) cout << -1; else cout << maxnum; return 0; } 
•  » » 9 months ago, # ^ |   0 Passing vector dp by copy add & after vi.
 » 10 months ago, # | ← Rev. 3 →   0 In Problem D i have used DFS and maintained the occurences of each character during the traversal in a map. Unable to figure out where i am going wrong. This is my code. Can anyone explain how DP can be applied here?
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 quite similar is done by me... code not able to understand where i'm wrong
 » 10 months ago, # |   0 What is looping section in problem E editorial??
•  » » 10 months ago, # ^ |   0 The given term n*a^n mode p has a period of p*(p-1) always (sometimes less, but definitely repeats after p*(p-1) terms)
•  » » » 10 months ago, # ^ | ← Rev. 2 →   0 Actually, it will always be p(p - 1). Check my comment above for the details.If the period was less than that, it would mess up the counting.Edit: I was wrong, ignore this.
•  » » » » 10 months ago, # ^ |   +3 No, sometimes it repeats with period p*(p-1)/2 as well. Just check with 7 as P and 3 as A. And it won’t mess up your counting as it definitely repeats after p*(p-1) as well (coz divisible).
•  » » » » » 10 months ago, # ^ |   0 Huh. You're right, period p(p - 1) / 2 does occur sometimes too. My bad, then.Your example is a bit wrong though. p = 7 and a = 3 still gives a period of p(p - 1). Instead, p = 11 and a = 3 gave me a period of p(p - 1) / 2.
•  » » » » » » 10 months ago, # ^ |   0 Yeah, it was probably 7 and 2. Sorry I have a bad memory.
•  » » » » » » » 10 months ago, # ^ |   0 7 and 2 does indeed give a period of p(p - 1) / 2.And yeah, counting doesn't get messed up because we're doing the counting mod p(p - 1) no matter what, so repeats within that will be counted separately.
 » 10 months ago, # |   +9 For F,this is what you said: "First we should notice that the useful number of states isn't something like (8^5)^2" Maybe it isn't something like (5^8)^2,right?
 » 10 months ago, # |   0 can someone help me out ? I submitted problem D with my data structures statically sized using SIZE.I got MLE when my SIZE was 1000005 in the 6th test case. but when i changed it to 300005 I got AC. my question is , why didn't i get MLE in the first test case itself as the data structures are static? MLE :34803955 AC :34804264
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 So what's wrong? You were trying to allocate more than 256 MB memory (3 * 10^7 long long array is 230 MB).
•  » » » 10 months ago, # ^ | ← Rev. 2 →   0 why didn't I get MLE in first test case ? btw i allocated 1e6
•  » » » » 10 months ago, # ^ | ← Rev. 2 →   0 Well, not all of your data structures are static. You have set ms; and you insert n elements in it, so in the first cases there is enough memory for your program. Why 1e6? You have ll dp[SIZE][30]; So you allocated 30 * SIZE = 3 * 1e7.
 » 10 months ago, # |   0 Can anybody give a proof why Problem D can't be solved using only DFS?. Keep counting the frequency of each letter in the traversal and record the maximum. -1 if cycle is found. I haven't solved it yet, but was wondering. Thanks
•  » » 10 months ago, # ^ |   0 no , it can't be solved using DFS only. Take for example a graph with edges :1->2 , 2->3, 2->5, 3->4 , 4->6. As in DFS you only visit a vertex ONCE , the vertex 6 won't have the frequency table of 5 in it. the way i solved it was for every node , find the frequency table of its parent(s) and record the maximum. my code is kind of messy but the function you want to see is the dfs one. code : 34804264
 » 10 months ago, # | ← Rev. 2 →   0 A more detailed Explanation for problem E:- 1. n*a^n-b=k*p, k-integer 2. n-b*a^(-n)=k*P*a^(-n) 3. n%p-( b*a^(-n))%p= (k*P*a^(-n))%p=0 4. n%p=( b*a^(-n))%p=y .....eq(1) 5. As n=i*(p-1)+j where j=[1,p-1] 6. n%p=(i*p)%p+(j-i)%p=(j-i)%p .....eq(2) 7. from eq(1) and eq(2) 8. y= (j-i)%p9. i%p=(j-y)%p 10. i=(j-y)%p , (j-y)%p+p,....... (j-y)%p+p*t 11. n=((imin)*(p-1)+j),.......... ((imax)*(p-1)+j)<=x for each j (no of n) =(no of i)+1=t+1=(x-((imin)*(p-1)+j))+1
 » 10 months ago, # |   0 In problem F, how to deal with cycles?
•  » » 10 months ago, # ^ |   +15 We don't need to do anything to that :)Those which we don't meet in BFS (toposort) will be "DEAL".BTW, You can give all states a "DEAL" tag for initialization.
•  » » » 10 months ago, # ^ |   0 can u go in more detail!plz
•  » » » » 10 months ago, # ^ |   0 perhaps represent what u mean visually
 » 10 months ago, # | ← Rev. 2 →   0 In problem F,when current status is in circle,but I have other succeed status which are all lose states.Maybe I can go into one of the lose states and win instead of make it deal.With topological sort we can have the correct answer for this status,but what about the previous status?The previous status maybe not visited.How to deal with this problem?
•  » » 10 months ago, # ^ |   0 Maybe only BFS is ok?
 » 10 months ago, # | ← Rev. 2 →   0 For Problem B. My Solution. Instead of iterating each and every value of n, I am finding the next Perfect Number in each iteration.
 » 10 months ago, # |   0 It came as a surprise to me when I found out k=1 was NOT in the pretests for problem C. I thought about trying to look for solutions which didn't treat this case but I thought surely it must have been in the pretests (usually pretests contain small cases like n = 0, 1, 2) so I decided to pass (I usually never go for hacks anyway, I prefer trying to solve more problems).
 » 10 months ago, # |   0 http://codeforces.com/contest/919/submission/34797654http://codeforces.com/contest/919/submission/34818291The code provided as a tutorial for problem C using Python (submission 34797654) does not run in the time listed. Using an assumed test case 9 of 2000 for m,n, and k; I get an average run time of more than 2 seconds on the test code provided in the tutorial on my personal computer. The time listed on that submission on CodeForce is 202 ms. For my code shown in submission 34818291 on those same systems I can get the code to run average 1.4 seconds on my personal computer. Looking at the code mine has the same complexity with redundancy's eliminated while still a similar algorithm.It looks to be that a large portion of Python 2 code during competition was correct but was being held to a standard the tutorial code doesn't pass. If this is the case a number of individuals were penalized incorrectly.Will you run the tutorial submission again to see what it is doing differently that other similar code that are not accepted?p.s. I would like to point out that a large portion of that code does fail the test case of k being one but that wasn't what they failed on and shouldn't exclude them from this issue.
 » 10 months ago, # |   0 Why the graph we built in F don't have any circle?
•  » » 10 months ago, # ^ |   0 The graph may have cycles,but with topological sort we won't visit those cycles.
•  » » » 10 months ago, # ^ |   0 The states which were not visited will not be marked,so "Deal" only happens when ans[s1][s2]=0. But I think topological sort has a small problem,as I said here.
 » 10 months ago, # | ← Rev. 2 →   0 For problem F bonus, the answer is the number of non-negative integer solution of x0 + x1 + x2 + x3 + ... + xm - 1 = k.It seems to be , and the number of status in the problem F is instead of 245025, right?
•  » » 10 months ago, # ^ |   0 It is ,because the number of solutions of x0 + x1 + ... + xn = k is .You can see it as combination with repetition.Wikipedia has an article about this,see here.
•  » » » 10 months ago, # ^ |   0 Oh, I mixed up m and k. It should be . Thx
 » 10 months ago, # |   0 Auto comment: topic has been updated by jinlifu1999 (previous revision, new revision, compare).
 » 10 months ago, # |   0 can someone tell what's wrong with my submission- http://codeforces.com/contest/919/submission/34839113 for problem C.
 » 9 months ago, # |   0 Can someone share their approach for the problem "919E Congruence Equation?". Editorial is bit difficult for me to understand. Thanks in advance
 » 9 months ago, # |   0 In the 2nd question, the code I've written works perfectly on my system, but when I uploaded it, it showed me a wrong answer. After the contest, when I executed the test case which went wrong on my own system, it showed the correct answer. Could anyone please help me in identifying the mistake?1st submission: http://codeforces.com/contest/919/submission/35751191^ Passed only the first test case2nd submission: http://codeforces.com/contest/919/submission/35751331 ^ passed two test cases, even though I changed just the starting number, from 19 to 1both the codes are working perfectly on my system
•  » » 5 months ago, # ^ |   0 sum() function does not return anything when s is less than 10, so the behavior is undefined in that case.