Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- char a[50010];
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n;
- scanf("%d", &n);
- int s = 1;
- int f = 0;
- int j = 0;
- bool nothing = false;
- scanf("%c", &a[0]);
- for (int i = 0; i < n - 1; i++) {
- char g;
- scanf("%c", &g);
- if (j > 0 && a[j - 1] == g) {
- if (!nothing) {
- f = 2;
- nothing = true;
- } else {
- f += 2;
- }
- j--;
- } else if(!nothing && n >= 2 && a[j - 2] == g) {
- f = 3;
- nothing = true;
- j -= 2;
- } else {
- a[j] = g;
- j++;
- nothing = false;
- if (f > s) {
- s = f;
- }
- }
- }
- n -= s;
- if (n % 2 == 0) {
- printf("1");
- } else {
- printf("2");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment