Submission #39611838
Source Code Expand
Copy
#include <iostream>#include <set>using namespace std;const int MAX_H = 15;const int MAX_W = 15;int H, W;int A[MAX_H][MAX_W];set<int> visited;int dfs(int i, int j) {// Base case: reached the bottom-right squareif (i == H && j == W) {return 1;}// Recursive case: try moving right and downint ans = 0;if (j < W) { // can move rightint a = A[i][j+1];if (!visited.count(a)) { // haven't visited this integer yetvisited.insert(a);
#include <iostream> #include <set> using namespace std; const int MAX_H = 15; const int MAX_W = 15; int H, W; int A[MAX_H][MAX_W]; set<int> visited; int dfs(int i, int j) { // Base case: reached the bottom-right square if (i == H && j == W) { return 1; } // Recursive case: try moving right and down int ans = 0; if (j < W) { // can move right int a = A[i][j+1]; if (!visited.count(a)) { // haven't visited this integer yet visited.insert(a); ans += dfs(i, j+1); visited.erase(a); } } if (i < H) { // can move down int a = A[i+1][j]; if (!visited.count(a)) { // haven't visited this integer yet visited.insert(a); ans += dfs(i+1, j); visited.erase(a); } } return ans; } int main() { cin >> H >> W; for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) { cin >> A[i][j]; } } visited.insert(A[1][1]); cout << dfs(1, 1) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Make Takahashi Happy |
User | IgnatiusTio |
Language | C++ (GCC 9.2.1) |
Score | 300 |
Code Size | 1114 Byte |
Status | AC |
Exec Time | 31 ms |
Memory | 3620 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 7 ms | 3376 KB |
001.txt | AC | 2 ms | 3380 KB |
002.txt | AC | 19 ms | 3548 KB |
003.txt | AC | 15 ms | 3548 KB |
004.txt | AC | 3 ms | 3512 KB |
005.txt | AC | 1 ms | 3440 KB |
006.txt | AC | 31 ms | 3440 KB |
007.txt | AC | 2 ms | 3484 KB |
008.txt | AC | 2 ms | 3544 KB |
009.txt | AC | 2 ms | 3544 KB |
010.txt | AC | 25 ms | 3380 KB |
011.txt | AC | 21 ms | 3520 KB |
012.txt | AC | 20 ms | 3552 KB |
013.txt | AC | 22 ms | 3512 KB |
014.txt | AC | 19 ms | 3548 KB |
015.txt | AC | 27 ms | 3544 KB |
016.txt | AC | 13 ms | 3572 KB |
017.txt | AC | 8 ms | 3432 KB |
018.txt | AC | 14 ms | 3548 KB |
019.txt | AC | 13 ms | 3384 KB |
020.txt | AC | 10 ms | 3572 KB |
021.txt | AC | 9 ms | 3620 KB |
022.txt | AC | 10 ms | 3440 KB |
example0.txt | AC | 2 ms | 3544 KB |
example1.txt | AC | 16 ms | 3380 KB |