Skip to content

A. Seats (AtCoder Beginner Contest 375)

Published:

Problem Link: A. Seats (AtCoder Beginner Contest 375)

Approach

We just have to check the condition that seats ii and i+2i+2 are occupied, and seat i+1i+1 is unoccupied between 11 to n2n-2 in string s.

Code Implementation

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans=0;
    for (int i=0; i<=n-2; i++){
        ans+=s.substr(i,3)=="#.#";
    }
    cout << ans;
    return 0;   
}

Next Post
B - Traveling Takahashi Problem (AtCoder Beginner Contest 375)