Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. char a[50010];
  4.  
  5. int main() {
  6.     //freopen("input.txt", "r", stdin);
  7.     //freopen("output.txt", "w", stdout);
  8.     int n;
  9.     scanf("%d", &n);
  10.     int s = 1;
  11.     int f = 0;
  12.     int j = 0;
  13.     bool nothing = false;
  14.     scanf("%c", &a[0]);
  15.     for (int i = 0; i < n - 1; i++) {
  16.         char g;
  17.         scanf("%c", &g);
  18.         if (j > 0 && a[j - 1] == g) {
  19.             if (!nothing) {
  20.                 f = 2;
  21.                 nothing = true;
  22.             } else {
  23.                 f += 2;
  24.             }
  25.             j--;
  26.         } else if(!nothing && n >= 2 && a[j - 2] == g) {
  27.             f = 3;
  28.             nothing = true;
  29.             j -= 2;
  30.         } else {
  31.             a[j] = g;
  32.             j++;
  33.             nothing = false;
  34.             if (f > s) {
  35.                 s = f;
  36.             }
  37.         }
  38.     }
  39.     n -= s;
  40.     if (n % 2 == 0) {
  41.         printf("1");
  42.     } else {
  43.         printf("2");
  44.     }
  45.     return 0;
  46. }
Add Comment
Please, Sign In to add comment