Cod sursa(job #2767502)

Utilizator asdfdajksdjfhfghjhfghjkjgv asdfdajksdjfh Data 6 august 2021 14:55:36
Problema Divk Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int dp[10001][10001];

int main(int argc, char const *argv[])
{
    // const string file_location = "/home/alex/PROGRAMMING-C++/Practice/divk.in";
    ifstream read("divk.in");
    ofstream print("divk.out");

    int N, K, A, B; 
    read >> N >> K >> A >> B;
   
    int element;
    vector<int> array;
    for(int i = 0; i < N; i++) {
        read >> element;
        array.push_back(element);
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if(i == j) {
                dp[i][j] = array[j];
            } else {
                dp[i][j] = 0;
            }
        }
    }
    
    int nr = 0;
    for(int i = 0; i < N; i++) {
        int length_of_sequence = 1;
        for(int j = i + 1; j < N; j++) {
            dp[i][j] = dp[i][j - 1] + array[j];
            length_of_sequence++;
            if(dp[i][j] % K == 0) {
                if(length_of_sequence >= A and length_of_sequence <= B) {
                    nr++;
                } else {
                    length_of_sequence = 1;
                }
            } 
        }
    }

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // cout << nr << endl;
    print << nr << endl;
    return 0;
}