awoo's blog

By awoo, history, 18 months ago, translation,

1473A - Replacing Elements

Tutorial
Solution (Neon)

1473B - String LCM

Idea: BledDest

Tutorial
Solution (Neon)

1473C - No More Inversions

Tutorial

1473D - Program

Idea: BledDest

Tutorial
Solution (awoo)

1473E - Minimum Path

Idea: Neon

Tutorial
Solution (Neon)

1473F - Strange Set

Idea: BledDest

Tutorial
Solution (BledDest)

1473G - Tiles

Tutorial
Solution (Neon)

• +133

 » 18 months ago, # |   +67 The terminology of using "path" for problem E was a bit misleading, since path is normally defined as a walk in which all vertices are distinct, which may not be necessary in this case. Would have given greater clarity if "path" was defined within the problem.Otherwise, great problem with an even better solution.
•  » » 18 months ago, # ^ |   +14 Completely agreed. I spent 30 minutes wondering how to eliminate repetitive edges during the contest (that would be a much harder problem, I believe). Since the term "path" is redefined, it deserves a more detailed distinction.
•  » » » 17 months ago, # ^ |   0 Can you please tell about time complexity for $E$. My doubt is regarding when graph will be like simple line then for $i^{th}$ vertex we will have $i_{C_2}$ many possible value of triplets for $i^{th}$ node so wouldn't it will go $O(n^2)$?
•  » » » » 17 months ago, # ^ | ← Rev. 2 →   0 Let's count the number of vertices in the new graph. Since each vertex is defined by 3 independent values, the number of vertices will equal to the product of numbers of possible values. So, the first value is the number of vertex, so there are $n$ possible values. Every flag has 2 values, so there are only $4\cdot n$ vertices in the new graph. Without thinking much you can find an upper bound $16 \cdot m$ for number of edges. So, time complexity of Dijkstra algorithm on the new graph is still $O(m \log n)$
•  » » » » » 17 months ago, # ^ |   0 Ohh my bad. Thanks. We are not maintaining the edge removed/added instead we are using flag. Thank you!
•  » » 18 months ago, # ^ |   +27 Interesting... In portuguese a "walk" is a "path" and a "path where no vertices are repeated" is a "simple path".
•  » » 17 months ago, # ^ |   +5 There exist cases that passing one edge more than once would decrease the total weight?
•  » » » 17 months ago, # ^ |   +3 4 3 1 2 10 2 3 1 2 4 10 Solution is 3 2 13
•  » » » » 17 months ago, # ^ |   0 Oh! So the solution never pass the 4*n vertices more than once but may pass original vertices more than once. Thanks.
•  » » 15 months ago, # ^ | ← Rev. 2 →   0 .
 » 18 months ago, # | ← Rev. 2 →   +8 fixed
 » 18 months ago, # |   -15 If anyone is stuck at D :https://www.youtube.com/watch?v=mMFkvyeRFQY&t=1s
 » 18 months ago, # | ← Rev. 2 →   +32 I know this will sounds biased, but is n = 1000 necessary for G? I've read the official solution, and assuming that the constant factor of NTT is 1, then that solution would require somewhere around 9e7 operations in worst case (which is something around multiplying 2 polynomials of size 5e6). Of course, the official solution runs in a mere 654ms on the hardest test, but it kills pretty much any recursive NTT solution. (I swapped the solution's NTT with an recursive NTT, and it TLEd on custom invocation on the hardest test, and Codeforces gives 15000ms on custom invocation.) While using recursive NTT itself is folly, I've yet to seen a NTT problem on Educational rounds that forces the participant to use iterative NTT. Which leads to the original question: is this problem intended to introduce iterative NTT to more experienced participants, or was it just an overtly pushed limit to fight brute force?
•  » » 18 months ago, # ^ |   +6 I wouldn't call it overly pushed.
•  » » » 18 months ago, # ^ |   +9 Wait, so brute force actually pass lower limits? o_O
 » 18 months ago, # | ← Rev. 4 →   0 During the contest , what was your lane of thought while solving C ? How you approached it before reaching to the solution?I saw that even SecondThread (in his screencast) and nskybytskyi (in comments) misread the problem C twice and same happened with me . Finally i wrote brute force and observed the pattern and passed somehow.Though after seeing the solution it doesn't seems to be difficult , we just needed to observed that in palindrome number of inversions would remain same.
•  » » 18 months ago, # ^ |   +11 I just figured out the number of inversions for the original array, messed around a bit and noticed the pattern, and tried my luck lol.
•  » » 18 months ago, # ^ |   +49 I read the problem then guessed the solution based on "this is C so it should be easy". In fact it was the hardest problem to think about for me.
•  » » » 17 months ago, # ^ |   0 hi! in problem C, no more inversion for the test case n= 6, k= 4, the expected output is -> 1 4 3 2 . but the answer 4 1 2 3 may also be correct. since the number of inversions are '3' ans also 4 1 2 3 is lexiographically greater than 1 4 3 2.
•  » » » » 17 months ago, # ^ |   0 1 2 3 4 3 21 4 3 2 3 44 1 2 3 2 1
•  » » 17 months ago, # ^ |   0 rananjay23 Can you please provide any blog where this observation : "In Palindrome, number of inversions would remain same" is proven formally or at least an inituition is given. Thanks in advance :)
•  » » 17 months ago, # ^ | ← Rev. 2 →   0 Hi, I want to ask you a thing, since you have watched screencast so, his code for C problem he created a "toReverse" variable whose value is n-k+1 whereas I declared it as 2k-n. Although I set different answers for k=2 and n=2, but not able to understand the logic behind that and so please explain this. It would be very helpful. I also included the same code here as well. int torev = n-k+ 1; int si = k - torev, ei = k -1; for (int i = 0; i < torev / 2; i++) { int l = si + i, r = ei - i; int temp = a[l]; a[l] = a[r]; a[r] = temp; }Thanks in Advance
•  » » » 17 months ago, # ^ | ← Rev. 2 →   0 Sorry , I watched his stream long back . I don't remember now . If you have any doubt in editorial , i can help you in that.
•  » » » » 17 months ago, # ^ |   0 oh ok thanks
 » 18 months ago, # |   +3 Video Tutorial for problem A,B and D link of problem D : https://www.youtube.com/watch?v=botAQ-AZNOQlink of problem B : https://www.youtube.com/watch?v=H3qBEDYwwX4link of problem A : https://www.youtube.com/watch?v=YjC6CcxYxo8&t=263sHope you guys will enjoy and understand the intution behind the solutions !!!
 » 18 months ago, # | ← Rev. 3 →   +24 Here is an attempt to make an unofficial video editorial of Educational Round 102 by COPS IIT BHU (English) (Problem A-E).Blog link : https://codeforces.com/blog/entry/86815
•  » » 17 months ago, # ^ |   0 Thank you. Useful.
 » 18 months ago, # |   +3 Can we solve the D problem using segment trees also ? If yes can someone explain their approach along with code link ?
•  » » 18 months ago, # ^ |   0
•  » » 18 months ago, # ^ |   +6 To solve using segtree, you just need to know how to join two segments. Each segment will store the smallest x, the largest x and the current x. Node and junction code are these: struct Node{ int l, r, curr; Node(){ l = r = curr = 0; } Node(char c){ if(c == '+') l = 0, r = 1, curr = 1; else l = -1, r = 0, curr = -1; } Node(int a, int b, int c){ l = a, r = b, curr = c; } }; inline Node join(Node a, Node b){ return Node(min(a.l, b.l + a.curr), max(a.r, b.r + a.curr), a.curr + b.curr); } 
•  » » » 17 months ago, # ^ |   0 Thanks for sharing your approach. I had watched this explanation in stevenkplus's stream but wasn't able to implement.
•  » » 18 months ago, # ^ |   0 code... #include "bits/stdc++.h" using namespace std; #define inti long long #define ll long long const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t mod = 1e9 + 7; const int32_t MM = 998244353; bool prime[100000]; //primes under 10^5 //////////////////////////////////seive for prime///////////////////////////// /* void primes() { int n=100000; for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } // Print all prime numbers // for (int p=2; p<=n; p++) // if (prime[p]) // cout << p << " "; } */ ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////NCR//////////////////////////////////////// /*const int N=5000; #define NCR #define PRIME M inti pw(inti a,inti p=M-2,inti MOD=M){ inti result = 1; while (p > 0) { if (p & 1) result = a * result % MOD; a = a * a % MOD; p >>= 1; } return result; } inti fact[N],invfact[N]; void init(){ inti p=PRIME; fact[0]=1; inti i; for(i=1;i=0;i--){ invfact[i]=invfact[i+1]*(i+1)%p; } } inti ncr(inti n,inti r){ if(r > n || n < 0 || r < 0)return 0; return fact[n]*invfact[r]%PRIME*invfact[n-r]%PRIME; }*/ /////////////////////////////////////////////////////////////////////////////// ////\\//////\\/////////\\///////////\\\////////\\/////////////\\\///// /* ll power(ll a, ll b) //time complexity is o(log(b)); { if (a == 0) return 0; ll ans = 1; a = a % mod; while (b > 0) { if ((b & 1) == 1) ans = (ans * a) % mod; b = b >> 1; a = (a * a) % mod; } return ans; }*/ //\\////\\//////\\//////\//////\\///////\\//////////\\/////\\/// /*bool isPrime(int n) { if (n == 1) { return false; } for (int i = 2; i*i <= n; i++) { if (n % i == 0) return false; } return true; }*/ //////////////\\\\\\\\////////\\\\\\\\\\//////////\\\\//// /////////////////////////////////////////////////////////////////////// /* //sort string by there length ==> sort(v.begin(), v.end(), [&] (const string &s, const string &t) { return s.size() < t.size(); }); */ /////////////////////////////////////////////////////////////////////// pair min_max(pair a, pair b) { return make_pair(max(a.first, b.first), min(a.second, b.second)); } void buildseg(int idx, int l, int r, vector> &seg, vector &v) { if (l == r) { seg[idx] = make_pair(v[l], v[l]); return; } int mid = (l + r) / 2; buildseg(2 * idx + 1, l, mid, seg, v); buildseg(2 * idx + 2, mid + 1, r, seg, v); seg[idx] = min_max(seg[2 * idx + 1], seg[2 * idx + 2]); return; } pair get_min_max(int idx, int ql, int qr, int l, int r, vector> &seg) { if ((ql <= l) and (qr >= r)) { return seg[idx]; } if (ql > r || qr < l) { return make_pair(INT32_MIN, INT32_MAX); } int mid = ((l + r) / 2); auto x = get_min_max(2 * idx + 1, ql, qr, l, mid, seg); auto y = get_min_max(2 * idx + 2, ql, qr, mid + 1, r, seg); return min_max(x, y); } void solve(vector &v, int n, int m) { //pair vector> seg((4 * n) + 1); buildseg(0, 0, n, seg, v); while (m--) { int ql, qr; cin >> ql >> qr; int mini = 0, maxi = 0; if (ql > 1) { auto x = get_min_max(0, 0, ql - 1, 0, n, seg); //max,min maxi = max(maxi, x.first); mini = min(mini, x.second); } if (qr < n) { auto y = get_min_max(0, qr + 1, n, 0, n, seg); //max,min int balance_factor = v[qr] - v[ql - 1]; y.first = y.first - balance_factor; y.second = y.second - balance_factor; maxi = max(maxi, y.first); mini = min(mini, y.second); } cout << (maxi - mini + 1) << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // memset(prime, true, sizeof(prime)); //primes(); // primes under 1lakh /* #ifdef NCR init(); #endif */ int t; cin >> t; while (t--) { int n; int m; cin >> n >> m; string str; cin >> str; vector v(n + 1); v[0] = 0; for (int i = 1; i <= n; i++) { v[i] = (str[i - 1] == '+') ? 1 : -1; v[i] = v[i] + v[i - 1]; } solve(v, n, m); } } 
•  » » 18 months ago, # ^ |   0 Yes, I did with segment tree , I used range sum segment tree to find sum for [l,r] , rest of the approach is same as editorial you can check here : https://codeforces.com/contest/1473/submission/104444800
•  » » 18 months ago, # ^ |   0 Yep, 104324446 was what I did in-contest
 » 18 months ago, # |   0 can anyone explain the solution for problem E .
•  » » 18 months ago, # ^ |   +2 sorry for my poor EnglishFirstly,add "extra information" when you running dijkstra.Original dijkstra only cares about which point is visted,but now we add two new information on every point.Like copy every point 4 times.When dijkstra is over,we get the shortest path from 1 to others,and the conversions in editorial works based on the answer we get is the "shortest",and "shortest" means we must delete the maximum edge's cost,and multiple the minimum edge's cost twice.This exactly fits the problem.
 » 18 months ago, # |   0 in what world G is a div 2 problem? (or under 2100)
•  » » 18 months ago, # ^ |   +4 Educational Contests are typically a bit harder than the regular Div. 2 Rounds (c) neal
•  » » 17 months ago, # ^ |   +31 In the world where a div2 has problem G.
•  » » 17 months ago, # ^ |   0 Usually, F&G in Educational Contests focus on more complex algorithms(flow,fft...),but use it as a template.
 » 18 months ago, # |   0 Are there any problems similar to E ?
•  » » 18 months ago, # ^ |   0 https://acm.timus.ru/problem.aspx?space=1&num=1527 You can use a similar algorithm here.
•  » » 18 months ago, # ^ |   -24 Use A2oj ladder. It has all the questions sorted according to difficulty levels
 » 18 months ago, # | ← Rev. 2 →   0 Problem C, maybe I'm misreading forever and I can't figure out where it is, can someone help me?For example n = 5, k = 3, sequence a will be "12321", and inversions of "12321" equals to 3.The answer p is "321" then sequence b will be "32123", and inversions of "32123" equals to 4 ??It exceeds the total number of inversions in a??
•  » » 18 months ago, # ^ | ← Rev. 2 →   +1 12321 has 4 inversions. (2, 1)(First appearance of 2), (3, 2), (3, 1), (2, 1) // second 2
•  » » » 18 months ago, # ^ |   +6 Oh!!! I understand that I couldn't find second (2, 1) for many hours...Very thanks!
•  » » » 17 months ago, # ^ |   0 hi! in problem C, no more inversion for the test case n= 6, k= 4, the expected output is -> 1 4 3 2 . but the answer 4 1 2 3 may also be correct. since the number of inversions are '3' ans also 4 1 2 3 is lexiographically greater than 1 4 3 2.
 » 18 months ago, # |   +23 finally...... rating:1599 :(
 » 17 months ago, # |   0 What kind of solutions does the ML in F intend to block?
•  » » 17 months ago, # ^ |   0 O(N^2) edges I guess.
•  » » » 17 months ago, # ^ |   0 Thanks. I was thinking that the ML was to block something other than flow because that edge-decreasing observation seemed rather obvious.
 » 17 months ago, # | ← Rev. 2 →   0 .
 » 17 months ago, # |   0 Can someone please explain D , went thorugh the editorial multiple times but still ain't clear ? Thanks !
•  » » 17 months ago, # ^ |   0 the video tutorial mentioned in the comments might help you
•  » » 17 months ago, # ^ | ← Rev. 2 →   +1 You can plot a graph from the given string. As the graph is continuous , the answer will be $max + abs(min) + 1$. Now notice what happens when you remove a segment. Graph on the right side of the segment gets shifted up or down by $abs(\text{sum of segment l,r})$ , i.e. if you know the max and min on right side of the segment, you can calculate the new max and min. Solve this in O(1) using prefix, suffix arrays.
•  » » 17 months ago, # ^ |   0 i have tried to explain it here
 » 17 months ago, # |   0 ~~~~~ auto mul = [](string s, int k) -> string { string res = ""; while (k--) res += s; return res; };~~~~~ can someone explain this? new to c++
•  » » 17 months ago, # ^ |   0 It's just a lambda expression which returns a string and the arrow operator makes it easy for auto to deduce the return type of the lambda is string.
•  » » » 17 months ago, # ^ |   0 Why were empty square brackets placed?
•  » » » » 17 months ago, # ^ |   0
•  » » » » » 17 months ago, # ^ |   0 Thanks. Excuse me for being too lazy to check myself.
•  » » » » » » 17 months ago, # ^ |   0 No problem comrade.
 » 17 months ago, # | ← Rev. 3 →   +10 May I ask why $ans_{i, j} = \sum\limits_{k=1}^{m} \binom{a_i+b_i}{b_i-k+j} ans_{i-1,k}$ is established in problem G?
•  » » 17 months ago, # ^ |   +13 Consider an infinity grid.Let $ans_{i-1,k}$ be at $(x_1, y_1) = (k-1+OFFSET_{i-1}, 1-k+OFFSET_{i-1})$.Let $ans_{i,j}$ be at $(x_2, y_2) = (j-1+b_i+OFFSET_{i-1}, 1-j+a_i+OFFSET_{i-1})$.Where $OFFSET_{i-1}$ is some accumulated offset from $1$ to $i-1$.The number of ways walking from $(x_1, y_1)$ to $(x_2, y_2)$ using only right and down is $\binom{x2-x1+y2-y1}{x2-x1} = \binom{a_i+b_i}{b_i-k+j}$.Sum from $k=1$ to $k=m$ we get the formula.
•  » » » 17 months ago, # ^ |   0 thanks!
•  » » » 17 months ago, # ^ |   +5 sorry...I can't understand the meaning of the coordinate. Could you help me? Thanks a lot
•  » » » » 17 months ago, # ^ |   0 A diagonal line here(say x+y=CONSTANT) corresponds to a column in the original problem.
 » 17 months ago, # |   +8 For G:1e3 * 1e5 * 17 with constant factor C = 1.7e9 * C.For NTT, obviously that C > 1.And it's quite easy to reach the worst case.How dare you set a 1e3 there.
•  » » 17 months ago, # ^ |   +24 It's not even close to 1e5, it was something that slowly increases from 1 to 5001 in the worst case. Still, I think this is a pretty tight limit for G though.
•  » » » 17 months ago, # ^ | ← Rev. 2 →   +8 I see. My mistook. Thanks for pointing it out.it's $\sum_{i=1}^{1000}{(10i-3)log_2{(10i-3)}}$.Too tight +1.
•  » » » » 17 months ago, # ^ |   +8 Finally squeezed within ~300ms. See submission 104694945.
•  » » » » » 17 months ago, # ^ |   0 QwQ So fast!
 » 17 months ago, # |   +8 Hi @BledDest,For the problem F and the input: 2 1 2 100 -200 I guess the network should look likeWhere is min-cut here? And where is the flow?
•  » » 17 months ago, # ^ |   +5 The min cut is 0 (take the set {s, 1}) and the answer is 100-0.
 » 17 months ago, # |   0 I just don't understand why in problem C, when n = 4, k = 3, p is (1, 3, 2). Shouldn't 'p' be (2, 3, 1) ??
•  » » 17 months ago, # ^ | ← Rev. 2 →   0 there will be 2 invertion (2,1) (3,1)
•  » » » 17 months ago, # ^ | ← Rev. 2 →   0 oh, That's what invertion means. Now I get it thanks.
 » 17 months ago, # |   0 Hey can someone provide me a case where my submission for E fails? Almost all tests other than samples are too big to simulate by hand and I'm not able to think of a case :(
•  » » 17 months ago, # ^ |   +13 I tried this sample case on your submission 4 4 1 2 3 1 3 7 2 4 3 3 4 1 Actual Output: 3 5 6Expected Output: 3 3 2
•  » » » 17 months ago, # ^ |   0 oo im so dumb, thanks a lot!
•  » » 17 months ago, # ^ |   0 my submission is also failing on this test case only . were you able to figure it out and come with a test case which went wrong my submission https://codeforces.com/contest/1473/submission/104981314
 » 17 months ago, # | ← Rev. 5 →   -27 I tried solving D using segment tree but i was not able to solve the problem in contest but later i solved it._ Basic idea was to consider making node that will have sum,minval,maxval and two merge left and right child in specific manner. HERE IS MY SOLUTION #include using namespace std; #define ll long long int #define loop(i,k,n) for(ll i=k;in;--i) #define loopeq(i,k,n) for(ll i=k;i<=n;++i) #define loopeqr(i,k,n) for(ll i=k;i>=n;--i) struct node { ll sum,maxval,minval; }; node NEUTRAL={0ll,0ll,0ll}; node merge(node a,node b) { return { a.sum+b.sum, max(a.maxval,a.sum+b.maxval), min(a.minval,a.sum+b.minval), }; } node single(ll x) { return {x,max(x,0ll),min(x,0ll)}; } struct segtree { int size; vector val; void init(int n) { size=1; while(size&a,int x,int lx,int rx) { if(rx-lx==1) { if(lx&a) { build(a,0,0,size); } node calc(int l,int r,int x,int lx,int rx) { if(r<=lx||rx<=l) return NEUTRAL; if(l<=lx&&r>=rx) return val[x]; int m=(lx+rx)/2; node sumleft=calc(l,r,2*x+1,lx,m); node sumright=calc(l,r,2*x+2,m,rx); return merge(sumleft,sumright); } node calc(int l,int r) { return calc(l,r,0,0,size); } }; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin>>t; while(t--) { ll n,m; cin>>n>>m; segtree st; st.init(n); vector arr(n); char ch; loop(i,0,n) { cin>>ch; if(ch=='+') arr[i]=1; else arr[i]=-1; } st.build(arr); ll l,r; while(m--) { cin>>l>>r; node left=NEUTRAL; node right=NEUTRAL; if(l!=1) left=st.calc(0,l-1); if(r!=n) right=st.calc(r,n); node final=merge(left,right); cout<
 » 17 months ago, # |   0 Can anyone give me a visualization of new graph in problem E? Maybe using the first sample test please. I could not imagine how that graph may look like. Thanks in advance.
•  » » 17 months ago, # ^ | ← Rev. 2 →   +4 There is no new graph . Here dp[u][0][0],dp[u][0][1],dp[u][1][0],dp[u][1][1] are not effected by each other and thus can be seen as independent nodes with all edges attached to them similar to u.Few definitions (similar to editorial) :dp[u][0][0] :Minimum Path length from vertex 1 to u such that each edge in path is counted once .dp[u][0][1] :Minimum Path length from vertex 1 to u such that one edge in path is counted one more time.dp[u][1][0] :Minimum Path length from vertex 1 to u such that one edge in path is subtracted.dp[u][1][1] :Minimum Path length from vertex 1 to u such that one edge in path is counted one more time and one edge in path is subtracted (Note that both type of edges can be same and in that case it will be equivalent to dp[u][0][0]).Answer for node u will be dp[u][1][1] because it fits definition in the problem and the edge subtracted will be always maximum and edge added one more time will be of minimum length (see proof in editorial).Let's consider graph with n=3,m=2 .Edge 1----2 with weight 3 , 2----3 with weight 6 . Initially dp[u][x][y] = Infinity for all nodes and all values of x and y .clearly dp[1][0][0] = 0 . Now transitions :dp[2][0][0] = 3 + dp[1][0][0] = 3 . dp[2][0][1] = 3 + 3 + dp[1][0][0] = 6 . dp[2][1][0] = dp[1][0][0] = 0 . dp[2][1][1] = 3 + 3 — 3 + dp[0][0] = 3 . As expected answer for node 2 is 3.dp[3][0][0] = 6 + dp[2][0][0] = 9 . dp[3][0][1] = min(dp[2][0][0]+6+6,dp[2][0][1]+6) = min(15,12) = 12 . dp[3][1][0] = min(dp[2][1][0]+6,dp[2][0][0]) = 3 . dp[3][1][1] = min(dp[2][1][1]+6,dp[2][0][1]) = min(9,6) = 6 . As expected answer for node 3 is 6.It can coded exactly as Dijkstra where we start from dp[1][0][0]. See the code in editorial it's very short and easy to understand.
•  » » » 17 months ago, # ^ |   +3 Thanks for your detailed example. Such a creative use of Dijkstra.
•  » » » » 17 months ago, # ^ |   0 True. It can be best described by demoralizer his comment in his stream Dijkstra is like a mixture of DP and Greedy. DP type technique with Greedy order of evaluation. That's why a lot of DP things can be used in Dijkstra, as long as the greediness is maintained.
•  » » » » » 17 months ago, # ^ |   0 I wonder if there are other problems similar to this one. I just want to see different kinds of dp combined with Dijkstra.
•  » » » » » » 17 months ago, # ^ |   +9 https://cses.fi/problemset/task/1196Try this problem from cses.
•  » » » » » » 17 months ago, # ^ |   +3 Also similar stuffs are discussed in the cses book Pg No.-153.
 » 17 months ago, # | ← Rev. 2 →   0 In C, is the number of inversions in the original sequence, a, always $(n-k)^2$?
 » 17 months ago, # |   0 Nice proof for problem C. For problem D, let's note $a_i = 1_{s_i='+'} - 1_{s_i='-'}$. For the suffix max, the quantity that we want to compute is: $s_i = \max(0, a_i, a_i + a_{i+1}, a_i + a_{i+1} + a_{i+2}, ..., a_i + a_{i+1} + ... + a_n) \\ = \max(0, a_i + \max(0, a_{i+1}, a_{i+1} + a_{i+2}, ..., a_{i+1} + ... + a_n)) \\ = \max(0, a_i + s_{i+1})$
 » 17 months ago, # |   0 is there any video editorial for F ??
 » 17 months ago, # |   0 can someone explain where i am wrong in Probem Ei am getting WA on test 5although i did similar as mentioned in editorial.SUBMISSION
•  » » 17 months ago, # ^ |   0 my submission is also failing on this test case only . were you able to figure it out and come with a test case which went wrong my submission https://codeforces.com/contest/1473/submission/104981314
 » 17 months ago, # |   0
 » 17 months ago, # | ← Rev. 2 →   0 Does the fact: "a palindromic sequence of distinct numbers has a fixed number of inversions regardless of the elements" should be known by contestants before the contest? Is it a widely known fact?
»
17 months ago, # |
-16

can someone check why my code doesnt work for B.

include <bits/stdc++.h>

using namespace std;

lcm(int a, int b) { int s=a; while(s%b!=0) s=s+a; return s; } int issubstring(char c1[],char c2[],int l1, int l2) { int l=lcm(l1,l2); for(int i=0;i<l;i++) { if(c1[i%l1]!=c2[i%l2]) return 0; } return l; }

stringlcm() { char c1[20], c2[20]; scanf("%s",c1); scanf("%s",c2);

int l1=strlen(c1);
int l2=strlen(c2);

if(int l=issubstring(c1,c2,l1,l2))
{
for(int i=0;i<l;i++)
cout<<c1[i%l1];
cout<<"\n";
}
else
cout<<"-1\n";


} main() { int n; cin>>n; while(n--) stringlcm(); }

 » 17 months ago, # |   0 Video Tutorial for problem A,B and D link of problem D : https://www.youtube.com/watch?v=botAQ-AZNOQlink of problem B : https://www.youtube.com/watch?v=H3qBEDYwwX4link of problem A : https://www.youtube.com/watch?v=YjC6CcxYxo8&t=263sHope you guys will enjoy and understand the intution behind the solutions !!!
 » 17 months ago, # |   0 Problem F is Closure problem.
 » 17 months ago, # |   0 hi! in problem C, no more inversion for the test case n= 6, k= 4, the expected output is -> 1 4 3 2 . but the answer 4 1 2 3 may also be correct. since the number of inversions are '3' ans also 4 1 2 3 is lexiographically greater than 1 4 3 2.
 » 17 months ago, # | ← Rev. 2 →   0 adedalic for the editorial of problem f how do you prove this part "It can be proven that any maximum flow algorithm that relies on augmenting paths will finish after O(v) iterations in this network"
 » 15 months ago, # |   0 Can someone explain this to me? (taken from editorial problem E) We can notice that on the shortest path, the maximum weight edge was subtracted and the minimum weight edge was added. Let's assume that this is not the case, and an edge of non-maximum weight was subtracted from the path, then we can reduce the length of the path by choosing an edge of maximum weight. But this is not possible, because we considered the shortest path. Similarly, it is proved that the added edge was of minimal weight.How exactly do we reduce path length by choosing the edge of maximum weight ???
 » 5 months ago, # |   0 What is this, could you explain better?