Advertisement
YEZAELP

PROG-1113: อ้าโอ้ (RO)

Aug 16th, 2020
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using lli = long long;
  5.  
  6. char ar[1000010];
  7.  
  8. int main(){
  9.  
  10.     int n,k;
  11.     scanf("%d%d",&n,&k);
  12.  
  13.     map <lli,int> qs;
  14.  
  15.     lli s = 0;
  16.     int mx = 0;
  17.     for(int i=1;i<=n;i++){
  18.         char a;
  19.         scanf(" %c",&a);
  20.         if(a == 'O') s--;
  21.         else s += k;
  22.         if(qs[s] == 0 and s != 0) qs[s] = i;
  23.         else mx = max(mx, i - qs[s]);
  24.     }
  25.  
  26.     printf("%d",mx);
  27.  
  28.     return 0;
  29. }
  30. /*
  31. 4 3
  32. ROOO
  33. */
  34.  
Advertisement
RAW Paste Data Copied
Advertisement