Language: C++

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

template <typename T, typename A>
inline ostream& operator<<(ostream& os, const vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) { os << p << ","; }
    return (os << "]" << endl);
}

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) { cin >> S[i]; }
    auto f = [=](const string& s1, const string& s2) {
        for (int i = 0; i < H; i++) {
            if (s1[i] != s2[H - 1 - i]) { return false; }
        }
        return true;
    };
    vector<vector<int>> rs;
    auto rec = fix([&](auto&& self, vector<int> r, const int num) -> void {
        if (num == (H + 1) / 2) {
            rs.push_back(r);
        } else {
            int head = 0;
            for (; r[head] != -1 and head < H; head++) {}
            r[head] = num;
            if (H % 2 == 1 and num == (H - 1) / 2) {
                self(self, r, num + 1);
            } else {
                for (int tail = head + 1; tail < H; tail++) {
                    if (r[tail] == -1) {
                        r[tail] = num;
                        self(self, r, num + 1);
                        r[tail] = -1;
                    }
                }
            }
        }
    });
    rec(vector<int>(H, -1), 0);
    for (const auto row : rs) {
        vector<int> r(H, -1);
        for (int i = 0; i < H; i++) {
            if (r[row[i]] == -1) {
                r[row[i]] = i;
            } else {
                r[H - 1 - row[i]] = i;
            }
        }
        vector<string> cols(W);
        for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
                cols[i].push_back(S[r[j]][i]);
            }
        }
        vector<bool> unused(W, true);
        for (int i = 0; i < W; i++) {
            for (int j = i + 1; j < W; j++) {
                if (unused[j] and f(cols[i], cols[j])) {
                    unused[i] = unused[j] = false;
                    break;
                }
            }
        }
        const int ans = accumulate(unused.begin(), unused.end(), 0);
        if (ans <= 1) {
            for (int i = 0; i < W; i++) {
                if (unused[i] and not f(cols[i], cols[i])) {
                    s = "NO";
                }
            }
            if (s == "YES") {
                cout << s << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:21: error: 's' was not declared in this scope
   89 |                     s = "NO";
      |                     ^
a.cc:92:17: error: 's' was not declared in this scope
   92 |             if (s == "YES") {
      |                 ^