Task: | Ruudukko |
Sender: | Sup |
Submission time: | 2022-11-10 14:18:28 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 28 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.02 s | 2, 3 | details |
#5 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#6 | ACCEPTED | 0.03 s | 2, 3 | details |
#7 | RUNTIME ERROR | 0.07 s | 3 | details |
#8 | RUNTIME ERROR | 0.13 s | 3 | details |
#9 | RUNTIME ERROR | 0.14 s | 3 | details |
Code
// CPP program to count number// of decreasing path in a matrix//#include <bits/stdc++.h>// using namespace std;//#include <iostream>#include <bits/stdc++.h>#include <cmath>using namespace std;#define MAX 400// Function that returns the number of// decreasing paths from a cell(i, j)int CountDecreasingPathsCell(int(&mat)[MAX][MAX], int(&dp)[MAX][MAX],int n, int x, int y){// checking if already calculatedif (dp[x][y] != -1)return dp[x][y];// all possible paths//int delta[4][2] = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };int delta[4*MAX][2];int C = 0;for (int i = -n; i<=n; i++){if(i != 0){C++;delta[C][0] = i;delta[C][1] = 0;}}for (int i = -n; i<=n; i++){if(i != 0){C++;delta[C][0] = 0;delta[C][1] = i;}}int newx, newy;// counts the total number of pathsint ans = 1;int modulo_num = pow(10, 9) + 7;// In all four allowed direction.for (int i = 0; i < 4*n; i++) {// new co-ordinatesnewx = x + delta[i][0];newy = y + delta[i][1];// Checking if not going out of matrix and next// cell value is less than current cell value.if (newx >= 0 && newx < n && newy >= 0&& newy < n && mat[newx][newy] < mat[x][y]) {ans = (ans % modulo_num) + (CountDecreasingPathsCell(mat, dp, n, newx, newy) % modulo_num);ans = ans % modulo_num;}}// function that returns the answerreturn dp[x][y] = ans;}// Function that counts the total// decreasing path in the matrixint countDecreasingPathsMatrix(int n,int(&mat)[MAX][MAX]){int dp[MAX][MAX];// Initialising dp[][] to -1.for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)dp[i][j] = -1;int sum = 0;int modulo_num = pow(10, 9) + 7;// Calculating number of decreasing path from each cell.for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)sum = (sum % modulo_num) + (CountDecreasingPathsCell(mat, dp, n, i, j) % modulo_num);//sum += CountDecreasingPathsCell(mat, dp, n, i, j) % modulo_num;return sum;}// Driver Codeint main(){//int i = 1;int number_of_rows;cin >> number_of_rows;//int input_row[number_of_rows] = {};int input_row1;//string replace_char = ",";//int mat[1000][1000];//int j;int my_array[MAX][MAX];//cout << number_of_rows << endl;for (int iii = 0; iii < number_of_rows; iii++){for (int ii = 0; ii < number_of_rows; ii++){cin >> input_row1;//input_row[ii] = input_row1;//cout << input_row1 << "its the input row" << endl;my_array[iii][ii] = input_row1;//char *modified_input = strtok(input_row, " ");//cout << modified_input << "its modified_input" << endl;//int number = stoi(modified_input);//cout << number << "its the number" << endl;//my_array[ii] = number;//cout << ii << "its the ii number" << endl;//cout << iii << "its the iii number----" << endl;}//my_array[iii] = input_row;}//int arrSize = sizeof(my_array)/sizeof(my_array[0]);//cout << arrSize << "its the length of arrSize" << endl;//cout << input_row[0] << "its the input_row---" << endl;//cout << input_row[1] << "its the input_row---" << endl;//cout << input_row[2] << "its the input_row---" << endl;//cout << my_array[0][0] << "its the my_array " << endl;//cout << my_array[1][1] << "its the my_array " << endl;//std::copy_n(std::istream_iterator<int>(std::cin), number_of_rows, my_array);//int mat[100][100] = { { 2, 1, 3 }, { 1, 1, 1 }, {9, 2, 7} }; // function call that returns the//cout << mat[50][0] << "its the mat print" << endl;//cout << modulo_num << "its the modulo_num" << endl;//int modulo_num = pow(10, 9)+7;int number_of_paths = countDecreasingPathsMatrix(number_of_rows, my_array);cout << number_of_paths << endl; // count of decreasing paths in a matrixreturn 0;}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 1 1 1 1 1 1 1 1 1 |
correct output |
---|
9 |
user output |
---|
9 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 1 2 3 6 5 4 7 8 9 |
correct output |
---|
135 |
user output |
---|
135 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
3 7 8 1 4 5 4 3 9 6 |
correct output |
---|
57 |
user output |
---|
57 |
Test 4
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
10000 |
user output |
---|
10000 |
Test 5
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
187458477 |
user output |
---|
1187458484 |
Test 6
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100 2995 8734 1018 2513 7971 5063 ... |
correct output |
---|
964692694 |
user output |
---|
964692694 |
Test 7
Group: 3
Verdict: RUNTIME ERROR
input |
---|
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
1000000 |
user output |
---|
(empty) |
Test 8
Group: 3
Verdict: RUNTIME ERROR
input |
---|
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
229147081 |
user output |
---|
(empty) |
Test 9
Group: 3
Verdict: RUNTIME ERROR
input |
---|
1000 520283 805991 492643 75254 527... |
correct output |
---|
951147313 |
user output |
---|
(empty) |