Submission #59366776


Source Code Expand

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second

const int N = 13;
int n, m, k;
string mat[N];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

bool check(int i, int j, vector<vector<bool> > &visited){
    if(i < 0 || j < 0 || i >= n || j >= m || visited[i][j] || mat[i][j] == '#'){
        return 0;
    }
    return 1;
}

int dfs(int i, int j, vector<vector<bool> > &visited, int curr){
    if(curr == k){
        return 1;
    }
    int ans = 0;
    for(int a = 0; a < 4; a++){
        int newi = i + dx[a], newj = j + dy[a];
        if(check(newi, newj, visited)){
            visited[newi][newj] = 1;
            ans += dfs(newi, newj, visited, curr + 1);
            visited[newi][newj] = 0;
        }
    }
    return ans;
}


int32_t main(){
    FAST
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++){
        cin >> mat[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            vector<vector<bool> > visited(n, vector<bool>(m, 0));
            if(mat[i][j] == '.'){
                visited[i][j] = 1;
                ans += dfs(i, j, visited, 0);
            }
        }
    }
    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task D - Count Simple Paths
User Basilhijaz
Language C++ 23 (gcc 12.2)
Score 425
Code Size 1639 Byte
Status AC
Exec Time 57 ms
Memory 3620 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 35
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 02_handmade_01.txt, 02_handmade_02.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3560 KiB
00_sample_02.txt AC 1 ms 3496 KiB
00_sample_03.txt AC 7 ms 3504 KiB
01_random_01.txt AC 1 ms 3420 KiB
01_random_02.txt AC 48 ms 3420 KiB
01_random_03.txt AC 1 ms 3476 KiB
01_random_04.txt AC 1 ms 3420 KiB
01_random_05.txt AC 1 ms 3424 KiB
01_random_06.txt AC 11 ms 3488 KiB
01_random_07.txt AC 1 ms 3504 KiB
01_random_08.txt AC 1 ms 3552 KiB
01_random_09.txt AC 1 ms 3552 KiB
01_random_10.txt AC 2 ms 3412 KiB
01_random_11.txt AC 1 ms 3500 KiB
01_random_12.txt AC 2 ms 3436 KiB
01_random_13.txt AC 1 ms 3552 KiB
01_random_14.txt AC 2 ms 3476 KiB
01_random_15.txt AC 1 ms 3492 KiB
01_random_16.txt AC 4 ms 3620 KiB
01_random_17.txt AC 1 ms 3452 KiB
01_random_18.txt AC 1 ms 3408 KiB
01_random_19.txt AC 1 ms 3476 KiB
01_random_20.txt AC 1 ms 3436 KiB
01_random_21.txt AC 1 ms 3480 KiB
01_random_22.txt AC 1 ms 3420 KiB
01_random_23.txt AC 1 ms 3472 KiB
01_random_24.txt AC 1 ms 3500 KiB
01_random_25.txt AC 1 ms 3496 KiB
01_random_26.txt AC 1 ms 3360 KiB
01_random_27.txt AC 1 ms 3500 KiB
01_random_28.txt AC 1 ms 3568 KiB
01_random_29.txt AC 1 ms 3416 KiB
01_random_30.txt AC 1 ms 3432 KiB
02_handmade_01.txt AC 1 ms 3484 KiB
02_handmade_02.txt AC 57 ms 3472 KiB