Submission #19304810


Source Code Expand

Copy
//int good_vec(vi a){
//    map<int,int> cnt;
//    for(int x : a)
//        cnt[x] ^= 1;
//    int s = 0;
//    for(auto _ : cnt)
//        s += _.Y;
//    return s <= 1;
//}
//bool solve(vvi grid){
//    int n = sz(grid);
//    int half = n/2;
//    rep(i,n)
//        sort(all(grid[i]));
//    sort(all(grid));
//    rep(bm,1<<n){
//        if(__builtin_popcount(bm) != half) continue;
//        vvi tmp,order;
//        rep(i,n)
//            if(bm&(1<<i))
//                tmp.pb(grid[i]);
//            else
//                order.pb(grid[i]);
//        do{
//            bool ok = true;
//            rep(i,half)
//                if(tmp[i] != order[i])
//                    ok = false;
//            if(sz(order) > sz(tmp) && !good_vec(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 <map>
#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 Y second
#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);
int good_vec(vi a){
    map<int,int> cnt;
    for(int x : a)
        cnt[x] ^= 1;
    int s = 0;
    for(auto _ : cnt)
        s += _.Y;
    return s <= 1;
}
bool solve(vvi grid){
    int n = sz(grid);
    int half = n/2;
    rep(i,n)
        sort(all(grid[i]));
    sort(all(grid));
    rep(bm,1<<n){
        if(__builtin_popcount(bm) != half) continue;
        vvi tmp,order;
        rep(i,n)
            if(bm&(1<<i))
                tmp.pb(grid[i]);
            else
                order.pb(grid[i]);
        do{
            bool ok = true;
            rep(i,half)
                if(tmp[i] != order[i])
                    ok = false;
            if(sz(order) > sz(tmp) && !good_vec(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 3658 Byte
Status WA
Exec Time 99 ms
Memory 3620 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 10 ms 3608 KB
10.txt AC 23 ms 3496 KB
100.txt WA 2 ms 3492 KB
11.txt AC 4 ms 3436 KB
12.txt AC 4 ms 3564 KB
13.txt AC 35 ms 3504 KB
14.txt AC 19 ms 3444 KB
15.txt AC 39 ms 3500 KB
16.txt AC 25 ms 3608 KB
17.txt AC 99 ms 3556 KB
18.txt AC 37 ms 3568 KB
19.txt AC 77 ms 3556 KB
2.txt AC 4 ms 3616 KB
20.txt AC 17 ms 3496 KB
21.txt AC 93 ms 3604 KB
22.txt AC 25 ms 3608 KB
23.txt AC 46 ms 3436 KB
24.txt AC 43 ms 3440 KB
25.txt AC 16 ms 3496 KB
26.txt AC 62 ms 3440 KB
27.txt AC 94 ms 3492 KB
28.txt AC 24 ms 3568 KB
29.txt AC 21 ms 3568 KB
3.txt AC 2 ms 3496 KB
30.txt AC 42 ms 3564 KB
31.txt AC 44 ms 3612 KB
32.txt AC 13 ms 3492 KB
33.txt AC 95 ms 3516 KB
34.txt AC 29 ms 3564 KB
35.txt AC 48 ms 3500 KB
36.txt AC 48 ms 3608 KB
37.txt AC 15 ms 3496 KB
38.txt AC 40 ms 3556 KB
39.txt AC 27 ms 3520 KB
4.txt AC 7 ms 3612 KB
40.txt AC 22 ms 3496 KB
41.txt AC 90 ms 3428 KB
42.txt AC 22 ms 3492 KB
43.txt AC 24 ms 3608 KB
44.txt AC 26 ms 3568 KB
45.txt AC 30 ms 3620 KB
46.txt AC 33 ms 3500 KB
47.txt AC 14 ms 3608 KB
48.txt AC 46 ms 3440 KB
49.txt AC 20 ms 3496 KB
5.txt AC 11 ms 3608 KB
50.txt AC 81 ms 3564 KB
51.txt AC 15 ms 3444 KB
52.txt AC 33 ms 3608 KB
53.txt AC 28 ms 3612 KB
54.txt AC 2 ms 3612 KB
55.txt AC 3 ms 3436 KB
56.txt AC 22 ms 3612 KB
6.txt AC 9 ms 3612 KB
7.txt AC 2 ms 3444 KB
8.txt AC 10 ms 3444 KB
9.txt AC 2 ms 3436 KB
sample1.txt AC 2 ms 3568 KB
sample2.txt AC 2 ms 3436 KB
sample3.txt AC 18 ms 3448 KB