Submission #19304941


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);
//    rep(i,n)
//        sort(all(grid[i]));
//    sort(all(grid));
//    do{
//        bool ok = true;
//        rep(i,n)
//            if(grid[i] != grid[n-1-i])
//                ok = false;
//        if(n%2 && !good_vec(grid[n/2]))
//            ok = false;
//        if(ok)
//            return true;
//    }while(next_permutation(all(grid)));
//    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 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);
    rep(i,n)
        sort(all(grid[i]));
    sort(all(grid));
    do{
        bool ok = true;
        rep(i,n)
            if(grid[i] != grid[n-1-i])
                ok = false;
        if(n%2 && !good_vec(grid[n/2]))
            ok = false;
        if(ok)
            return true;
    }while(next_permutation(all(grid)));
    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 2976 Byte
Status WA
Exec Time 2205 ms
Memory 3652 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 59
WA × 1
TLE × 3
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 3640 KB
10.txt AC 19 ms 3652 KB
100.txt WA 2 ms 3444 KB
11.txt AC 36 ms 3564 KB
12.txt AC 38 ms 3596 KB
13.txt AC 102 ms 3596 KB
14.txt AC 38 ms 3652 KB
15.txt AC 99 ms 3560 KB
16.txt AC 1715 ms 3568 KB
17.txt TLE 2028 ms 3600 KB
18.txt AC 100 ms 3488 KB
19.txt AC 931 ms 3564 KB
2.txt AC 3 ms 3648 KB
20.txt AC 42 ms 3508 KB
21.txt AC 1956 ms 3608 KB
22.txt AC 1888 ms 3564 KB
23.txt AC 116 ms 3560 KB
24.txt AC 42 ms 3608 KB
25.txt AC 38 ms 3508 KB
26.txt AC 469 ms 3564 KB
27.txt AC 1968 ms 3504 KB
28.txt AC 355 ms 3596 KB
29.txt AC 42 ms 3608 KB
3.txt AC 3 ms 3636 KB
30.txt AC 57 ms 3484 KB
31.txt AC 104 ms 3640 KB
32.txt AC 35 ms 3564 KB
33.txt AC 1985 ms 3564 KB
34.txt AC 1790 ms 3544 KB
35.txt AC 120 ms 3448 KB
36.txt AC 46 ms 3508 KB
37.txt AC 36 ms 3444 KB
38.txt AC 104 ms 3544 KB
39.txt AC 37 ms 3640 KB
4.txt AC 8 ms 3604 KB
40.txt AC 1809 ms 3604 KB
41.txt AC 1826 ms 3560 KB
42.txt AC 336 ms 3504 KB
43.txt AC 1755 ms 3640 KB
44.txt AC 39 ms 3564 KB
45.txt AC 42 ms 3448 KB
46.txt AC 45 ms 3564 KB
47.txt AC 31 ms 3640 KB
48.txt AC 1853 ms 3508 KB
49.txt AC 1739 ms 3544 KB
5.txt AC 27 ms 3572 KB
50.txt AC 971 ms 3652 KB
51.txt AC 39 ms 3604 KB
52.txt TLE 2205 ms 3360 KB
53.txt TLE 2205 ms 3180 KB
54.txt AC 8 ms 3640 KB
55.txt AC 2 ms 3496 KB
56.txt AC 339 ms 3484 KB
6.txt AC 12 ms 3600 KB
7.txt AC 2 ms 3604 KB
8.txt AC 20 ms 3608 KB
9.txt AC 2 ms 3544 KB
sample1.txt AC 2 ms 3560 KB
sample2.txt AC 2 ms 3444 KB
sample3.txt AC 35 ms 3548 KB