Submission #19304776


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]));
//    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]));
    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 3612 Byte
Status WA
Exec Time 70 ms
Memory 3652 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 59
WA × 4
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 WA 7 ms 3548 KB
10.txt AC 4 ms 3440 KB
100.txt WA 1 ms 3608 KB
11.txt AC 3 ms 3608 KB
12.txt AC 3 ms 3508 KB
13.txt AC 19 ms 3564 KB
14.txt AC 4 ms 3560 KB
15.txt AC 17 ms 3504 KB
16.txt AC 14 ms 3500 KB
17.txt AC 64 ms 3504 KB
18.txt AC 12 ms 3612 KB
19.txt AC 44 ms 3500 KB
2.txt AC 2 ms 3556 KB
20.txt AC 6 ms 3504 KB
21.txt AC 70 ms 3544 KB
22.txt AC 18 ms 3500 KB
23.txt AC 27 ms 3652 KB
24.txt AC 10 ms 3488 KB
25.txt AC 2 ms 3552 KB
26.txt AC 34 ms 3504 KB
27.txt AC 55 ms 3444 KB
28.txt AC 11 ms 3640 KB
29.txt WA 24 ms 3604 KB
3.txt AC 3 ms 3564 KB
30.txt AC 22 ms 3568 KB
31.txt AC 22 ms 3444 KB
32.txt AC 4 ms 3652 KB
33.txt AC 26 ms 3504 KB
34.txt AC 21 ms 3564 KB
35.txt AC 28 ms 3612 KB
36.txt AC 11 ms 3480 KB
37.txt AC 4 ms 3556 KB
38.txt AC 33 ms 3484 KB
39.txt AC 3 ms 3568 KB
4.txt AC 3 ms 3560 KB
40.txt AC 26 ms 3648 KB
41.txt AC 61 ms 3608 KB
42.txt AC 21 ms 3564 KB
43.txt AC 22 ms 3636 KB
44.txt AC 17 ms 3504 KB
45.txt AC 18 ms 3568 KB
46.txt AC 20 ms 3500 KB
47.txt AC 6 ms 3612 KB
48.txt AC 12 ms 3608 KB
49.txt AC 17 ms 3608 KB
5.txt AC 9 ms 3444 KB
50.txt AC 56 ms 3572 KB
51.txt AC 4 ms 3604 KB
52.txt AC 19 ms 3648 KB
53.txt AC 13 ms 3444 KB
54.txt AC 2 ms 3552 KB
55.txt AC 1 ms 3444 KB
56.txt AC 20 ms 3604 KB
6.txt AC 3 ms 3560 KB
7.txt AC 2 ms 3608 KB
8.txt WA 18 ms 3648 KB
9.txt AC 2 ms 3500 KB
sample1.txt AC 3 ms 3564 KB
sample2.txt AC 2 ms 3652 KB
sample3.txt AC 8 ms 3636 KB