Wave Generation

Правка en1, от tsvk, 2024-04-07 11:02:41

Recently I had been trying to solve a question :

I have come up with the following approach :

#include "bits/stdc++.h"
using namespace std;
const int MOD = 1000000007;
vector<int> getValidRep(const vector<int>& arr, int i, int m) {
    vector<int> vec;
    if (i == 0) {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i + 1]) 
                vec.push_back(i);
        }
    } 
    else if (i == arr.size() - 1) {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i - 1]) 
                vec.push_back(i);
        }
    } 
    else {
        for (int i = 1; i <= m; i++) {
            if (i != arr[i - 1] && i != arr[i + 1])
                vec.push_back(i);
        }
    }
    return vec;
}

int f(const vector<int>& arr, int n, int m) {
    int totWays = 1;
    for (int i = 0; i < n; i++) {
        if (arr[i] == -1) {
            vector<int> vec = getValidRep(arr, i, m);
            totWays = (static_cast<long long>(totWays) * vec.size()) % MOD;
        }
    }
    return totWays;
}

int main() {
    int n = 5;
    vector<int> v(n);
    for(auto &it : v) cin>>it;
    int m = 5;
    cout << f(v, n, m) << endl; // Output: 4
    return 0;
}

The thing is that , I cannot submit to test for the test cases as it was part of an OA and I can't find it on any online judge and I am not able to think of anythinf better. All kinds of inputs will be appreciated... Thanks

Теги combinatorics, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский tsvk 2024-04-07 11:03:30 12 Tiny change: ' << endl; // Output: 4\n retu' -> ' << endl; \n retu'
en1 Английский tsvk 2024-04-07 11:02:41 1566 Initial revision (published)