深さ優先探索

ABC015-C-高橋くんのバグ探し

再帰を使った解答

#include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
    return (n >> i) % i;
}

template<class T>
T getbit(T i) {
    return 1LL << i;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;


ll N,K;
vvll T(N, vll(K));
bool dfs(ll n, ll t) {
    bool flg = true;
    rep(i, 0, K*N) {
        if (n ==-1) {
            flg &= t != 0;
        }
        else {
            flg &= dfs(n - 1, t ^ (T[n][i]));

        }
    }
    return flg;
}
int main() {
    cin >> N >> K;
    rep(i, 0, N) {
        rep(j, 0, K) {
            cin>>T[i][j];
        }
    }


    bool flg = true;
    rep(i, 0, N) {
        rep(j, 0, K) {
            
        }
    }

    if (dfs(N - 1, 0)) {
        cout<<"Nothing";
    }
    else {
        cout << "Found";
    }
}

for文による解答

#include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
    return (n >> i) % i;
}

template<class T>
T getbit(T i) {
    return 1LL << i;
}
template<class T>
T POW(T n, T m) {
    T res=1;
    rep(i, 0, m) {
        res *= n;
    }
    return res;
}

using namespace std;


ll N, K;
vvll T;

int main() {
    cin >> N >> K;
    vvll T(N, vll(K));
    rep(i, 0, N) {
        rep(j, 0, K) {
            cin>>T[i][j];
        }
    }

    
    bool flg = true;
    rep(i, 0, POW(K,N)) {
        ll t = 0;
        rep(n, 0, N) {
            t^=(T[n][(i/POW(K,n))%K]);
        }
        flg =flg && t; // &= とは省略できない。(bit演算と解釈されてしまうため。flg&=bool(t)と書くことは可能)。
    }
    
    

    if (flg) {
        cout<<"Nothing";
    }
    else {
        cout << "Found";
    }
}