can anyone identify the problem in the code

Revision en2, by ajitkumar014, 2023-07-15 18:32:42

it the solution of https://mirror.codeforces.com/problemset/problem/1549/B

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using uli = unsigned long int;
using ll = long long;
#define pb push_back
int n;
int mod = 1e9 + 7;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

void solve()
{
    cin >> n;
    int v[2][n];
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> v[i][j];
        }
    }
    int ans = 0;
    vector<bool> check(n, false);
    for (int i = 0; i < n; i++)
    {
        if (v[1][i] == 1)
        {
            if (v[0][i] == 0 && check[i] == false)
            {
                ans++;
                check[i] = true;
            }
            if (i - 1 >= 0)
            {
                if (v[0][i - 1] == 1 && check[i - 1] == false)
                {
                    ans++;
                    check[i - 1] = true;
                }
            }
            if (i + 1 < n)
            {
                if (v[0][i + 1] == 1 && check[i + 1] == false)
                {
                    ans++;
                    check[i + 1] = true;
                }
            }
        }
    }
    cout << ans << endl;
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English ajitkumar014 2023-07-15 18:32:42 57
en1 English ajitkumar014 2023-07-15 18:31:41 1534 Initial revision (published)