Submission #19304411


Source Code Expand

Copy
//int good_vec(vi a){
//    vi cnt(26);
//    for(int x : a)
//        cnt[x] ^= 1;
//    return sum(cnt) == sz(a)%2;
//}
//bool solve(vvi grid){
//    int n = sz(grid);
//    int half = n/2;
//    rep(i,n)
//        sort(all(grid[i]));
//    rep(bm,1<<n){
//        if(__builtin_popcount(bm) != half) continue;
//        vi tmp;
//        rep(i,n)
//            if(bm&(1<<i))
//                tmp.pb(i);
//        rep(i,n)
//            if(!(bm&(1<<i)))
//                tmp.pb(i);
//        vi order(n-half);
//        iota(all(order),half);
//        do{
//            bool ok = true;
//            rep(i,half)
//                if(grid[tmp[i]] != grid[tmp[order[i]]])
//                    ok = false;
//            if(n%2 && !good_vec(grid[tmp[order.back()]]))
//                ok = false;
//            if(ok)
//                return true;
//
//        }while(next_permutation(all(order)));
//    }
//    return false;
//}
//string __(){
//    int h,w;
//    cin >> h >> w;
//    vvi grid(h,vi(w));
//    rep(i,h)
//        rep(j,w){
//            char c;
//            cin >> c;
//            grid[i][j] = c-'a';
//        }
//    if(!solve(grid))
//        return "NO";
//    {
//        vvi tmp(w,vi(h));
//        rep(i,h)
//            rep(j,w){
//                tmp[j][i] = grid[i][j];
//            }
//        grid = tmp;
//    }
//    if(!solve(grid))
//        return "NO";
//    return "YES";
//}
//
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 T sum(vector<T>& arr){
    T ans = 0;
    for(auto x : arr)
        ans += x;
    return ans;
}
int good_vec(vi a){
    vi cnt(26);
    for(int x : a)
        cnt[x] ^= 1;
    return sum(cnt) == sz(a)%2;
}
bool solve(vvi grid){
    int n = sz(grid);
    int half = n/2;
    rep(i,n)
        sort(all(grid[i]));
    rep(bm,1<<n){
        if(__builtin_popcount(bm) != half) continue;
        vi tmp;
        rep(i,n)
            if(bm&(1<<i))
                tmp.pb(i);
        rep(i,n)
            if(!(bm&(1<<i)))
                tmp.pb(i);
        vi order(n-half);
        iota(all(order),half);
        do{
            bool ok = true;
            rep(i,half)
                if(grid[tmp[i]] != grid[tmp[order[i]]])
                    ok = false;
            if(n%2 && !good_vec(grid[tmp[order.back()]]))
                ok = false;
            if(ok)
                return true;

        }while(next_permutation(all(order)));
    }
    return false;
}
string __(){
    int h,w;
    cin >> h >> w;
    vvi grid(h,vi(w));
    rep(i,h)
        rep(j,w){
            char c;
            cin >> c;
            grid[i][j] = c-'a';
        }
    if(!solve(grid))
        return "NO";
    {
        vvi tmp(w,vi(h));
        rep(i,h)
            rep(j,w){
                tmp[j][i] = grid[i][j];
            }
        grid = tmp;
    }
    if(!solve(grid))
        return "NO";
    return "YES";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << __() << '\n';
}

Submission Info

Submission Time
Task E - Symmetric Grid
User Andres_Unt
Language C++ (GCC 9.2.1)
Score 0
Code Size 3761 Byte
Status WA
Exec Time 54 ms
Memory 3624 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 62
WA × 1
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 100.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 4.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 5.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 8 ms 3616 KB
10.txt AC 7 ms 3496 KB
100.txt WA 3 ms 3568 KB
11.txt AC 7 ms 3572 KB
12.txt AC 5 ms 3604 KB
13.txt AC 14 ms 3580 KB
14.txt AC 5 ms 3500 KB
15.txt AC 14 ms 3604 KB
16.txt AC 37 ms 3580 KB
17.txt AC 42 ms 3564 KB
18.txt AC 18 ms 3604 KB
19.txt AC 46 ms 3500 KB
2.txt AC 3 ms 3512 KB
20.txt AC 16 ms 3620 KB
21.txt AC 51 ms 3620 KB
22.txt AC 37 ms 3512 KB
23.txt AC 52 ms 3532 KB
24.txt AC 18 ms 3620 KB
25.txt AC 3 ms 3504 KB
26.txt AC 46 ms 3604 KB
27.txt AC 43 ms 3500 KB
28.txt AC 38 ms 3580 KB
29.txt AC 14 ms 3572 KB
3.txt AC 2 ms 3512 KB
30.txt AC 8 ms 3620 KB
31.txt AC 51 ms 3616 KB
32.txt AC 6 ms 3508 KB
33.txt AC 47 ms 3616 KB
34.txt AC 32 ms 3508 KB
35.txt AC 49 ms 3616 KB
36.txt AC 12 ms 3608 KB
37.txt AC 5 ms 3512 KB
38.txt AC 54 ms 3512 KB
39.txt AC 4 ms 3508 KB
4.txt AC 2 ms 3612 KB
40.txt AC 39 ms 3616 KB
41.txt AC 47 ms 3616 KB
42.txt AC 38 ms 3512 KB
43.txt AC 28 ms 3508 KB
44.txt AC 6 ms 3576 KB
45.txt AC 13 ms 3576 KB
46.txt AC 15 ms 3564 KB
47.txt AC 14 ms 3616 KB
48.txt AC 34 ms 3612 KB
49.txt AC 35 ms 3604 KB
5.txt AC 9 ms 3616 KB
50.txt AC 50 ms 3508 KB
51.txt AC 12 ms 3512 KB
52.txt AC 27 ms 3516 KB
53.txt AC 33 ms 3532 KB
54.txt AC 3 ms 3512 KB
55.txt AC 2 ms 3616 KB
56.txt AC 41 ms 3616 KB
6.txt AC 3 ms 3496 KB
7.txt AC 2 ms 3512 KB
8.txt AC 6 ms 3516 KB
9.txt AC 2 ms 3576 KB
sample1.txt AC 2 ms 3576 KB
sample2.txt AC 2 ms 3620 KB
sample3.txt AC 15 ms 3624 KB