### chokudai's blog

By chokudai, history, 10 months ago,

We will hold AtCoder Beginner Contest 161.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

• +70

 » 10 months ago, # |   0 Excited for my first atcoder contest...
 » 10 months ago, # |   0 I wish it will be a perfect contest！
•  » » 10 months ago, # ^ |   0 Today's Internet is not smooth
•  » » » 9 months ago, # ^ |   0 What happened ?
 » 10 months ago, # |   0 In Problem F For N = 6 When K = 3 : 6 -> 2 -> 1 Why K = 3 is not considered in first sample?
•  » » 10 months ago, # ^ |   -7 If you subtract 3 from 2, it does not become 1, it turns -1, which is not what is expected!
•  » » » 10 months ago, # ^ |   -10 Read the question again!
•  » » 10 months ago, # ^ |   -8 When 3 divides 6 it changes N to N/k which is 2 and N-K,i.e., 2-3 is equal to -1 and not 1. :)
•  » » 10 months ago, # ^ |   +3 for k=3n = 61> 6%3==0: n = 6/3=22> 2%3!=0: n = 2-3=-1it's wrong
•  » » » 10 months ago, # ^ | ← Rev. 2 →   0 Ok, Thanks I wrongly interpreted the question, I thought that we can choose different K at each step while reducing N.
•  » » 10 months ago, # ^ |   0 Hmm, everyone is pointing out wrongly... If you choose $K = 3$, performing one operation results in $2$, which is less than K, so you don't have to consider operations one more time :)
 » 10 months ago, # |   0 Do you have a smooth network today？
 » 10 months ago, # |   +2 Why does this solution fail E? Code#include #define int long long int using namespace std; // Author: Ashish int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n,k,c; string s; cin>>n>>k>>c>>s; int maxWork[n]; for(int i=n-1;i>=0;i--) { maxWork[i]=(s[i]=='o'); if(i+1k) return 0; int index=0; for(int j=k;j>0;j--) { set indices; for(;maxWork[index]==j&&index
•  » » 10 months ago, # ^ | ← Rev. 2 →   -9 I solved E doing dpl[n + 1] and dpr[n + 1] — the max days we can work in 0...i for dpl and i...n dpr. So i will be in the answer if dp[i] + dp[n — i — 1] < k and dp[i] + dp[n — i — 1] + 1 == k ands[i] == '0'.Sorry for my poor English.Code: #include #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, c; string s; cin >> n >> k >> c >> s; int dpl[n + 1], dpr[n + 1]; dpl[0] = 0; dpr[0] = 0; int last = -10000000; for (int i = 1; i <= n; ++i) { if (s[i - 1] == 'x') dpl[i] = dpl[i - 1]; else if (last + c < i) { last = i; dpl[i] = dpl[i - 1] + 1; } else dpl[i] = dpl[i - 1]; } last = -10000000; for (int i = 1; i <= n; ++i) { if (s[n - i] == 'x') dpr[i] = dpr[i - 1]; else if (last + c < i) { last = i; dpr[i] = dpr[i - 1] + 1; } else dpr[i] = dpr[i - 1]; } //for (int i = 0; i <= n; ++i) cout << dpr[i] << " "; for (int i = 0; i < n; ++i) { int left = i; int right = n - i - 1; if (s[i] == 'o' && dpl[left] + dpr[right] < k && dpl[left] + dpr[right] + 1 >= k) cout << i + 1 << endl; } return 0; } 
•  » » 10 months ago, # ^ | ← Rev. 2 →   +8 You need an else block for when indices.size()!=1: In this case, the best strategy (i.e. causes the least forced days) is to work on the earliest day $d^*$ inside indices{}, because if a future day is forced when using $d^*$ then it is also forced for any other $d$ inside indices{}, but not necessarily the other way around. After you select $d^*$, you should increment the index appropriately.For instance suppose you have 4 o's in a row, where the first and second have maxwork=2, and the third and fourth have maxwork=1. Then assume you work on the day with the first o. This might disqualify the 3rd o, making the 4th o forced. So you need a condition similar to your index=c+1+index1, except assuming you work on the earliest day $d^*$.I think something like "oooxo" with k=2, c=2 should exhibit this problem- you'll have maxwork = 2, 2, 1, 1, etc.Mine to compare (btw linear time with a stack instead of a set is possible) https://atcoder.jp/contests/abc161/submissions/11538625
•  » » » 10 months ago, # ^ |   +3 Thank you very much :D Moved the index=c+1+index1; part outside if statement and it worked :D
•  » » 3 months ago, # ^ | ← Rev. 2 →   0 Maybe the hardest thing to encounter Can anyone check why this fails in one test case? https://atcoder.jp/contests/abc161/submissions/17260017
 » 10 months ago, # |   0 I think the difficulty gap from C to D is way more than expected
•  » » 10 months ago, # ^ |   0 D is bruteforce recursion, and I feel F is also much easier this time.
•  » » » 10 months ago, # ^ |   0 You can also use DPSolution
•  » » 10 months ago, # ^ |   +3 D is not hard, just dfs.
•  » » » 10 months ago, # ^ |   +1 How you used dfs in it?
•  » » » » 10 months ago, # ^ |   +1 Code#include using namespace std; typedef long long ll; vector v; void dfs(ll x, ll num, ll st, ll cc){ if(v.size() > 100050) return; if(num == 0) num += x; else { num *= 10; num += x; } if(cc > st) return; if(cc == st){ v.push_back(num); return; } if(x-1 >= 0) dfs(x-1,num,st,cc+1); if(x+1 <= 9) dfs(x+1,num,st,cc+1); dfs(x,num,st,cc+1); return; } int main(){ ll k; cin>>k; for(int i = 1; i <= 10; i++){ for(int j = 1; j <= 9; j++){ dfs(j,0,i,1); } } sort(v.begin(),v.end()); cout<
•  » » » » » 7 months ago, # ^ |   0 bro can you elaborate the above solution.
 » 10 months ago, # |   +24 Video tutorials + ScreencastScreencastVideo Editorials
 » 10 months ago, # |   +20 I think F is easier than D;
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 With D a brute force works, just maintain the lunlun numbers as an array, and increment i times. That is fairly simple compared to F.Submission
•  » » » 9 months ago, # ^ |   0 Can you explain your logic please !
•  » » » » 9 months ago, # ^ |   0 We store the digits of the number in an array as if written down on paper.Incrementation works just like that, we increment the lowest significant digit. If it runs out of scope (higest possible number), then we increment the one at one position higher, and use the lowest possible number for the digits at the lower positions.
 » 10 months ago, # |   0 Can somebody explain me logic behind problem F? I only can guess that n = (ak + 1) * b or n = ak + 1.
•  » » 10 months ago, # ^ |   +5 Solution to $F$:If $N=2$, the answer is $1$.Otherwise, let's define the function $f(x, y)$ like this: bool f(long long x, long long y) { while(x%y==0) { x/=y; } return x%y==1; } Now for all $i$ $(i>1)$ which is the factor of $N$, add $f(N, i)$. Let's define this sum as $S$, and the number of factors of (N-1) as $T$. The answer is $S + T$.
•  » » 10 months ago, # ^ | ← Rev. 2 →   +4 $n$ can be of the form $k^p$ or $k^p(km+1)$. So we can loop over $\sqrt{n}$ values to check such $k$. Here
•  » » » 10 months ago, # ^ |   0 Can you please explain it with more details?
•  » » » » 10 months ago, # ^ |   0 Umm I mean suppose you have reached $1$ then either you reached it by dividing some other number by $k$ or adding $k$.Now just follow the question's operations. Note that as soon as our number is not divisible by $k$ then we may only subtract $k$. So in the first case in above paragraph, it must be that number is $k^p$. In second case, we may add any number of $k$, and after that multiply by $k$ any number of times, so that following questions sequence of operations always reduces it to $1$.
 » 10 months ago, # | ← Rev. 2 →   0 Can anyone reason out why adding codes for compiler optimization gives RTE ? I wasted a lot of time and attempts over it. RTE   AC chokudai ?
•  » » 10 months ago, # ^ |   +1
 » 10 months ago, # |   0 https://ide.codingblocks.com/s/205523Why is this giving WA in B ?
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 it should be ceil(sum/(4.0*(double)m)). you are meant to round it up to fit the requirement
•  » » » 10 months ago, # ^ |   0 Thank you brother....i'm getting wa in test case 5 and 6...this thing helped me.
•  » » 10 months ago, # ^ |   0 you are dividing sum by 4*m and both of them are int, so there division gave you a rounded down int. suppose sum/(4*m) is 96.5, your code will convert it to 96 and then include all the 96s in the array which shouldn't be include as 96<96.5 . use double while dividing and then use ceil function.
•  » » 10 months ago, # ^ |   0 Line 23: if(v[i]>=sum/(4*m)), this does integer division as both sum and m are integers. The correct way would have been to store it in a double and then compare.
•  » » 10 months ago, # ^ |   0 Cast integers to doubles where you are doing division and comparison
•  » » » 10 months ago, # ^ |   0 Better use multiplication on the left side instead of divison on the right.
•  » » 10 months ago, # ^ |   +5 Change if(v[i]>=sum/(4*m)) to if(4*m*v[i]>=sum) .
•  » » 9 months ago, # ^ |   0 Use this if(((v[i]*4)*m)>=sum)
 » 10 months ago, # | ← Rev. 5 →   0 Could someone tell me where my code for F is wrong. Only 6 out of 25 test cases were wrong. Codepublic class F { private static long n; private static int[] a; public static void main(String[] args) { n = in.nextLong(); long ans = 0; for(long i=2; i*1L*i<=n; i++) { long temp = n; while(temp%i==0) { temp/=i; } if (temp%i==1) { ans++; } } long p = n-1; long f = 1; for(long j=2; j*1L*j<=p; j++) { int count = 0; while(p%j==0) { p/=j; count++; } if (n%j!=0 && count!=0) { f*=(count+1); } } if (n==2) { println(1); } println(ans+f+1); out.flush(); out.close(); } }
•  » » 10 months ago, # ^ |   0 if i is a factor then n/i is also a factor.U missed to check for n/i in the first for loop.
•  » » 10 months ago, # ^ |   0 You are printing twice when n=2
•  » » » 10 months ago, # ^ |   0 I accidently removed return in the if condition while debugging.
 » 10 months ago, # | ← Rev. 2 →   0 D OEIS but for the first 1k only :v .. waiting for English editorial and thanks for the round EDIT: video editorial
 » 10 months ago, # |   +8 In D I used binary search + digit dp. It took me a lot of time to implement that :/// solution link
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 Can you explain please what dp[12][N][2][2] in your code means?
•  » » » 10 months ago, # ^ |   -8 You may check the digit Dp article if you don't know about it.Digit DP
•  » » » 10 months ago, # ^ |   +5 yeah sure,first dim means — the last digit that is usedsecond dim means — the length of number iteratedthird means — the lower limit is fixed or not (this one is not required as lower limit is always one)fourth one — if upper limit is fixed or not
•  » » 10 months ago, # ^ |   0 Wow, Thank you!
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 Same here. D was a bit tough for me while F was much easier. It took me 25 minutes to solve D with BS+digitdp and just 7 minutes in F.
 » 10 months ago, # |   0 What am I missing for D? 100000 case doesn't work. import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int k = Integer.parseInt(br.readLine()); HashSet set = new HashSet<>(); LinkedList q = new LinkedList<>(); for (long i = 1; i <= 9; i++) { q.add(i); set.add(i); } if (k <= 9) { pw.println(k); pw.close(); return; } while (!q.isEmpty()) { long head = q.poll(); for (long i = head % 10 - 1; i <= head % 10 + 1; i++) { if (i < 0) continue; long val = head * 10 + i; if (set.contains(val)) continue; set.add(val); q.add(val); if (set.size() == k) { pw.println(val); pw.close(); return; } } } pw.close(); } } 
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 Never mind, I figured it out. When the last digit is 9, the queue puts in a 0, bc (9 + 1) % 10 = 0
 » 10 months ago, # |   0 Can someone describe how to solve D? Was it dp digits?
•  » » 10 months ago, # ^ | ← Rev. 7 →   0 My approach for D was a bit different. I had a set $s$ which would store all possible answers for all $K$. Now I had an integer $z$, such that the next numbers to be added to $s$ were $z*10+d-1$, $z*10+d$, $z*10+d+1$, where $d=z(\mod 10)$. Note that $z$ $\epsilon$ $s$ $\forall$ $z$. Hence I incremented $z$ by $1$ and set $z =$ *$s$.lower_bound($z$). I continued this until size of $s<=K$. Then I just printed the $K$ th element of the set.
•  » » » 10 months ago, # ^ |   0 Okay thank you.
•  » » 10 months ago, # ^ | ← Rev. 2 →   +3 I solved it using bfs. Here is my solution
•  » » » 10 months ago, # ^ |   0 Thank you!
•  » » 10 months ago, # ^ | ← Rev. 3 →   +4 I used simple BFS. Codeint k; cin>>k; if(k<=12){ cout<,greater> pq; for(int i=1;i<=9;i++) pq.push(i); int cnt=0; ll ans; while(true){ ll num=pq.top(); pq.pop(); cnt++; if(cnt==k){ ans=num; break; } int ld=num%10; ll num1=num*10+ld; pq.push(num1); if(ld!=0){ num1=num*10+ld-1; pq.push(num1); } if(ld!=9){ num1=num*10+ld+1; pq.push(num1); } } cout<
•  » » » 10 months ago, # ^ |   0 Thank you!
•  » » » 10 months ago, # ^ |   0 Thank you bro
•  » » » 10 months ago, # ^ |   0 Really nice man
•  » » » 10 months ago, # ^ | ← Rev. 2 →   0 This is the simplest self-explanatory code solution, I have read for this problem till now. Thank you
•  » » 10 months ago, # ^ |   +1 I did it using simple bfs.link to submission
•  » » » 10 months ago, # ^ |   0 Thank you!
•  » » 10 months ago, # ^ |   0 You can solve with bruteforce, just store Lunlun numbers in an array.Then check the last digit of i'th entry, let it be x. Then for next position, you can have digit -> x-1, x and x + 1.For example: Initial array : [1, 2, 3, 4, 5, 6, 7, 8, 9]Consider you are at 1 -> 10 , 11, 12. Then increase the pointer after you try all consecutive of current entry.Now do same for 2-> 21, 22, 23.and keep adding them in the array. You can implement it recursively as well as iteratively.Iterative
•  » » » 10 months ago, # ^ |   0 Oh that seems easy. Thank you!
•  » » 10 months ago, # ^ |   0 BFS can solve the problem. int n,cnt; void solve(){ cin>>n; queue q; rep(i,1,10)q.push(to_string(i)); while(1){ int m = q.size(); for(int i=0;i
•  » » » 10 months ago, # ^ |   0 Thank you!
 » 10 months ago, # |   0 What is wrong with the following code for problem B?  int n,m; cin>>n>>m; int tot = 0; vector arr(n,0); for(int i=0;i>arr[i]; tot+=arr[i]; } sort(arr.rbegin(),arr.rend()); int req=tot/(4*m); int cnt = 0; for(int i=0;i=req) { cnt++; } else break; } if(cnt>=m) cout<<"Yes"; else cout<<"No"; 
•  » » 10 months ago, # ^ |   0 Try making req into a double: double req=(double)(tot)/(4*m);
•  » » » 10 months ago, # ^ |   0 Yeah worked bro. Thanks.
 » 10 months ago, # |   0 I think this contest is more difficult than before.
 » 10 months ago, # | ← Rev. 2 →   0 #include using namespace std; int main(){ long long n,k; cin>>n>>k; long long N=n; long long mn=1000000000000000000; while(n>=0){ mn=min(n,mn); if(n
•  » » 10 months ago, # ^ |   0 For small k and big n the loop will run n/k times, wich then is to slow. You can speed this up by using mod operations.
•  » » » 10 months ago, # ^ |   0 i tried but it was showing error.
•  » » » 10 months ago, # ^ |   0 oh yes. thanks. i tried to make both conditions using mod but the k>n condition was giving error. But why? can you please explain ?
•  » » » » 10 months ago, # ^ |   0 I think there are a lot of possible implementations. The basic aproach is the same for all: For big $n$ and small $k$ the loop is shortened by removing a multiple of $k$ in one step.My Submission
•  » » » » » 10 months ago, # ^ |   0 Hey man appreciate it. thanks for helping me.
 » 10 months ago, # |   0 So,how to solve the problem D?
•  » » 10 months ago, # ^ | ← Rev. 3 →   +4 If you were to generate all numbers, it'd be something like this: vector num; void brute(int i, int last, long long cur){ if(i == 0) return; num.push_back(cur); if(last > 0) brute(i-1, last-1, cur * 10 + last - 1); if(last < 9) brute(i-1, last+1, cur * 10 + last + 1); brute(i-1, last, cur * 10 + last); } Where $i$ is the maximum number of digits, $last$ is the last digit you used and $cur$ is your current number.Then, you can use nth_element or sort to get $k-1$ smallest.But why does this work? Well since there are only 3 transitions, complexity would be $O(3^D)$ where D is the maximum number of digits. Turns out answer will have not more than 12 digits so you can just brute force it =p.
•  » » » 10 months ago, # ^ |   0 Thank you. I understand it
•  » » 10 months ago, # ^ |   +3 You can approach that problem by using backtracking. Let's say you have a lunlun number x, you can find another lunlun number by taking the last digit of x which is d = (x%10) and appending d, d+1, d-1 to x. Then you keep doing the same on the new lun lun number. Also you have to keep in mind that initially you have start with all the single digit numbers. You can imagine the tree as 0 at the top and the root node, the from that emerges 9 branches to 1, 2, 3, 4, 5, 6, 7, 8, 9. Then from each one of them will emerge at most 3 branch. Like from 2 we will have 21, 22, 23. And so on.
•  » » » 10 months ago, # ^ |   0 Thanks，bro~
 » 10 months ago, # |   +1 So how to solve E?
•  » » 10 months ago, # ^ | ← Rev. 4 →   +8 Let's define dpl[i] as the max number of days that we can work in first i days, and define dpr[j] as the max number of days that we can work in last j day. The size of both arrays is n + 1. We can precalculate dpl and dpr greedy, base: dpl[0] = 0, dpr[0] = 0, last = -inf. Then iterate from left to right, keeping last as last day when he worked. Same for dpr.If day i is in the answer, then s[i] == 'o'(Im counting days from 0 to n — 1) and dpl[i] + dpr[n — i — 1] < k and dpl[i] + dpr[n — i — 1] + 1 == k(may be its useless condition). Time complexy: O(n) Code:https://atcoder.jp/contests/abc161/submissions/11534466
•  » » » 10 months ago, # ^ |   0 Thank you very much, nice explanation.
 » 10 months ago, # |   +4 Please atcoder! can you make english editorial.
•  » » 10 months ago, # ^ |   +3 Or if someone just translates the existing one to English.
 » 10 months ago, # |   +1 can anyone explain the d part and what is written in the editorial of d in japanese
•  » » 10 months ago, # ^ | ← Rev. 3 →   +4 This problem can be solved efficiently using Queue. Prepare one Queue and Enqueue 1, 2, ..., 9 in order. Then do the following K times: Dequeue the Queue. Let x be the extracted element. Let d = x mod 10. if d = 0. Enqueue 10x, 10x+1. if d = 9. Enqueue 10x + 8, 10x + 9; else Enqueue 10x + d-1, 10x + d, 10x + d + 1. Kth extracted element will be the answer.
•  » » » 10 months ago, # ^ |   0 Above is what you get if you translate the Japanese editorial for D.
•  » » » 10 months ago, # ^ |   0 Damn that's such a clean solution
•  » » » 10 months ago, # ^ |   0 thanks man!!
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 The same idea: Codeint n,cnt; void solve(){ cin>>n; queue q; rep(i,1,10)q.push(i); while(1){ int m = q.size(); for(int i=0;i
 » 10 months ago, # |   0 It's harder to understand the editorial than to understand the problem statement. (Since the editorial is in Japanese ! )
 » 10 months ago, # |   +7 can anyone plz explain the logic behind E??
•  » » 10 months ago, # ^ |   0 https://codeforces.com/blog/entry/75551?#comment-597715 Great explanation ...
•  » » 10 months ago, # ^ | ← Rev. 2 →   +3 Find the earliest and latest day of the $i$-th working day. If for some $i$ they are the same, this is a day bound to work.You can greedily iterate the days to find the earliest days. Also, reversely iterating the days gives the latest days.
•  » » » 10 months ago, # ^ |   0 Why "they are same" indicates this is a day bound to work? Can you explain it more detailedly？
•  » » » » 10 months ago, # ^ |   0 Ohhhhhhh！ I suddenly understand it，Thx.
•  » » » 9 months ago, # ^ |   0 Thank you very much !
 » 10 months ago, # | ← Rev. 2 →   +7 My submission for problem 'D' is giving Runtime error on sample test cases on Atcoder but this code is working fine on Codeforces custom invocation.I tried to cut-short the code to find my mistake but still, I can't find my mistake, Here is the link of a very short and clean code which should give WA but is giving RE instead. Can someone help me find the mistake in either of the code?Edit: It got accepted when I removed lines 8 to 12 (pragma tags) but I am still unable to understand why including pragma tags is giving RE here
 » 10 months ago, # | ← Rev. 2 →   +1 Supplementary editorial and sample codes for last 4 problems AtCoder ABC 161
•  » » 10 months ago, # ^ |   0 Thank you
 » 10 months ago, # | ← Rev. 2 →   0 why this code is giving TLE for question F #include using namespace std; typedef long long ll; ll func(ll n,ll x) { while(n%x==0) n/=x; if(n%x==1) return 1; else return 0; } int main() { ll t; t=1; while(t--) { ll n; cin>>n; ll s=0; for(int i=2;i*i<=(n-1);i++) { if((n-1)%i==0) { s++; if((n-1)/i != i) s++; } } ll c=0; for(int i=2;i*i<=n;i++) { if(n%i==0){ c+=func(n,i); if(n/i != i) c+=func(n,n/i); } } cout<
•  » » 10 months ago, # ^ |   +1 use long long for i instead of int
•  » » » 10 months ago, # ^ |   0 thanks but can u tell me why it was giving tle earlier
•  » » » » 10 months ago, # ^ |   +3 i*i becomes negative when overflowing so the for loop will become an infinite loop
 » 10 months ago, # |   0 I find a data that someone can not pass for Problem E 5 2 1 oxooo the result is empty,but someone will out 1
»
10 months ago, # |
0

Here is the code

# include<stdio.h>//----1

int main(void){//------2 long int n,k,t;//----3 scanf("%ld%ld", &n, &k);//---4 t=n%k;//-----5 if(2*t<k){//-----6 printf("%ld", t); } else{ printf("%ld", k-t); } return 0; } i do not understand the line 5 and 6.why i use this condition ????please anyone explain it??? thanks in advance

 » 10 months ago, # | ← Rev. 2 →   0 Whats wrong in this solution for problem 'Replacing integer' . I have even gone through editorial solution.Its same as mine.Whats wrong here..Please someone look at thishttps://atcoder.jp/contests/abc161/submissions/11572033
•  » » 10 months ago, # ^ |   0 if(a[i]>=(sum/(4*m))) Instead of dividing on the right you better multiplicate on the left side, to avoid rounding issues.
•  » » » » 10 months ago, # ^ |   0 check output for n = 14, k = 15. Correct output is 1. Your program prints 14.
•  » » » » » 10 months ago, # ^ |   0 Thanku so much brother..Really appreciated..Thanks..Done
•  » » » 10 months ago, # ^ | ← Rev. 3 →   0 Will u please see my solution of E.My solution is same as editorial. but i dont understand what the hell is wrong here?? pls look at this.thanks in advancehttps://atcoder.jp/contests/abc161/submissions/11577640
•  » » » » 10 months ago, # ^ |   +1 I think the editorial means the size of array is K , here is My code ,the idea is the same with editorial.it's easy to understand ,hope it will help. Spoilerint n,k,c; string s; void solve(){ cin>>n>>k>>c>>s; s = '#' + s; VI earliest(k+1,0),latest(k+1,0); int i=1,j=1; while(i0&&j>=1){ if(s[i]=='o'){ latest[j--] = i; i-=c+1; }else{ i--; } } rep(i,1,k+1)if(earliest[i]==latest[i])cout<
•  » » » » » 10 months ago, # ^ | ← Rev. 2 →   +3 thanks sir, got my mistake
•  » » » » » » 10 months ago, # ^ |   0 I did something similar as well. I sorted the reverse array and then compared,but still got WA at the same test case as you were getting earlier. Can you please tell me where am I going wrong : https://atcoder.jp/contests/abc161/submissions/11594352
 » 10 months ago, # |   0 https://atcoder.jp/contests/abc161/submissions/11592729what is the problem in this submission for problem C?
»
10 months ago, # |
0

my code for problem no D(lunlun number):

# include<math.h>

long long int a[1000001],rem[100000001]; int main() { int n,i,j,k=1; scanf("%d",&n); for(i=0; i<9; i++) a[i]=k++; long long int x=9,cnt,flag,num; for(i=9; i<n; i++) { num = ++x,cnt = 0,flag = 1; while(x!=0) { rem[cnt++]=x%10; x/=10; } for(j=cnt-1; j>0; j--) { if(abs(rem[j]-rem[j-1])>1) { flag=0; break; } } if(!flag) { i--; continue; } else if(flag == 1) a[i]=num; } printf("%lld\n",a[n-1]); return 0; }

can anyone please tell me where I have made the mistake? I am getting CE for this code.

 » 10 months ago, # |   0 try to do the D with brute force but when it arrives I give the number 37 input the outputs start to be wrong. Could someone help me find the fault? Solution
 » 10 months ago, # | ← Rev. 2 →   0 Why do I get WA? Here's my code for problem E.I'm looking for a savior.
•  » » 9 months ago, # ^ |   0 Your code gives wrong answer on oxooo with N=5,K=2 and C=1. In first iteration you are marking index 0 and 2 as true. In second iteration you are marking index 4 and 2 as true. And printing three as 2 come in both the iterations. However the i'th day should be same in both the iterations. Only then we can count it in our answer.
•  » » » 9 months ago, # ^ |   0 Thanks!
 » 10 months ago, # |   0 Hi! Not getting the logic of Solution D in the editorial. It's hard to come up with that kind of solution. Can anyone share other ways to do it? Thanks.
 » 9 months ago, # |   0 Can someone please help me...my two testcases are failing in problem B(The popular vote)i even read the editorial solution...i can't figure out where my mistake is happening?my code
 » 8 months ago, # |   0 I do not understand in problem E, why do we have to take the days greedily from left and right. Problem