Codeforces Round 828 (Div. 3) 1744C - Traffic Light Solution

 


Problem Link :  https://codeforces.com/contest/1744/problem/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n;
  11. char c;
  12. cin >> n >> c;
  13. string s;
  14. cin >> s;
  15. s += s;
  16. int lg = -1;
  17. for (int i = 2 * n - 1; i >= n; i--) {
  18. if (s[i] == 'g') lg = i;
  19. }
  20. int ans = 0;
  21. for (int i = n - 1; i >= 0; i--) {
  22. if (s[i] == 'g') lg = i;
  23. if (s[i] == c) ans = max(ans, lg - i);
  24. }
  25. cout << ans << "\n";
  26. }
  27. return 0;
  28. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.