제출 #1237221

#제출 시각아이디문제언어결과실행 시간메모리
1237221opeleklanosKutije (COCI21_kutije)C++20
35 / 70
1095 ms8336 KiB
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> moves;
vector<vector<int>> dp;
int n, m, q;

int makeDp(int toy, int box){
    if(toy == box) return dp[toy][box] = 1;
    if(dp[toy][box] == 2) return 0;
    if(dp[toy][box] != -1) return dp[toy][box];

    dp[toy][box] = 2;
    for(int i = 1; i<=m; i++){
        if(makeDp(toy, moves[i][box]) == 1){
            dp[toy][box] = 1;
            break;
        }
    }
    if(dp[toy][box] == 2 ) dp[toy][box] = 0;
    return dp[toy][box];
}

int main(void){
    //freopen("input.txt", "r", stdin);
    cin>>n>>m>>q;
    moves.assign(m+1, vector<int>(n+1, 0));
    dp.assign(n+1, vector<int>(n+1, -1));

    for(int i = 1; i<=m; i++){
        for(int j = 1; j<=n; j++) cin>>moves[i][j];
    }

    for(int i = 0; i<q; i++){
        int t, b;
        cin>>t>>b;
        if(makeDp(t, b)) cout<<"DA\n";
        else cout<<"NE\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...