Submission #19401459


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#include <cstdlib>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int h,w; cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vi p(h);
  vi f(h, 0);
  auto rec = [&](auto self, int id, int cnt)->void {
    if(cnt == h/2) {
      vector<vector<char>> t(h, vector<char>(w));
      rep(j,w) {
        rep(i,h) {
          t[i][j] = s[p[i]][j];
        }
      }     
      bool center = true;
      vi ff(w,0);
      rep(i,w) {
        rep(j,w) {
          if(i >= j) continue;
          if(ff[i] || ff[j]) continue;          
          bool flag = true;
          rep(k,h) {
            if(t[k][i] != t[h-1-k][j]) {
              flag = false;
              break;
            }
          }
          if(flag) {
            ff[i] = 1;
            ff[j] = 1;
            break;
          }
        }
        if(!ff[i]) {
          if(w % 2 == 0) {}
          else {
            bool ffff = true;
            rep(k,h) if(t[k][i] != t[h-1-k][i]) ffff = false;
            if(ffff && center) {
              center = false;
              ff[i] = 1;
            }
          }
        }
      }
      bool fff = true;
      rep(i,w) {
        fff &= ff[i];
      }
      if(fff) {
        cout << "YES" << "\n";
        exit(0);
      }
    }
    while(f[id]) id++;
    p[cnt] = id;
    f[id] = 1;
    for (int i = id+1; i < h; i++) {
      if(f[i]) continue;
      p[h-1-cnt] = i;
      f[i] = 1;
      self(self, id, cnt+1);
      f[i] = 0;
    }
    f[id] = 0;
  };
  if(h % 2 == 0) { 
    rec(rec, 0, 0);
    cout << "NO\n";
  }
  else {
    rep(i,h) {
      f[i] = 1;
      p[h/2] = i;
      rec(rec, 0, 0);
      f[i] = 0;
    }
    cout << "NO\n";
  }
  return 0;
}

Submission Info

Submission Time
Task E - Symmetric Grid
User kkktym
Language C++ (GCC 9.2.1)
Score 0
Code Size 2578 Byte
Status RE
Exec Time 119 ms
Memory 3628 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 42
RE × 21
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 3400 KB
10.txt AC 3 ms 3564 KB
100.txt AC 2 ms 3564 KB
11.txt AC 4 ms 3396 KB
12.txt AC 4 ms 3560 KB
13.txt RE 115 ms 3208 KB
14.txt AC 9 ms 3400 KB
15.txt RE 109 ms 3144 KB
16.txt AC 18 ms 3468 KB
17.txt RE 107 ms 3304 KB
18.txt AC 7 ms 3572 KB
19.txt RE 110 ms 3148 KB
2.txt AC 2 ms 3460 KB
20.txt AC 13 ms 3396 KB
21.txt RE 112 ms 3320 KB
22.txt AC 18 ms 3464 KB
23.txt RE 109 ms 3204 KB
24.txt RE 109 ms 3280 KB
25.txt AC 10 ms 3396 KB
26.txt RE 111 ms 3296 KB
27.txt RE 110 ms 3316 KB
28.txt AC 17 ms 3628 KB
29.txt AC 6 ms 3460 KB
3.txt AC 2 ms 3568 KB
30.txt RE 113 ms 3220 KB
31.txt RE 109 ms 3324 KB
32.txt AC 10 ms 3516 KB
33.txt RE 111 ms 3316 KB
34.txt AC 21 ms 3588 KB
35.txt AC 18 ms 3564 KB
36.txt RE 109 ms 3376 KB
37.txt AC 17 ms 3568 KB
38.txt RE 119 ms 3212 KB
39.txt RE 110 ms 3292 KB
4.txt AC 2 ms 3456 KB
40.txt AC 18 ms 3564 KB
41.txt RE 108 ms 3216 KB
42.txt AC 20 ms 3584 KB
43.txt AC 15 ms 3460 KB
44.txt RE 109 ms 3148 KB
45.txt AC 17 ms 3452 KB
46.txt RE 111 ms 3376 KB
47.txt AC 16 ms 3568 KB
48.txt RE 111 ms 3148 KB
49.txt AC 17 ms 3400 KB
5.txt AC 2 ms 3396 KB
50.txt RE 109 ms 3280 KB
51.txt AC 16 ms 3392 KB
52.txt AC 16 ms 3464 KB
53.txt AC 19 ms 3568 KB
54.txt AC 2 ms 3400 KB
55.txt AC 3 ms 3552 KB
56.txt AC 16 ms 3464 KB
6.txt AC 2 ms 3392 KB
7.txt AC 4 ms 3404 KB
8.txt AC 2 ms 3460 KB
9.txt RE 107 ms 3372 KB
sample1.txt AC 2 ms 3564 KB
sample2.txt AC 2 ms 3568 KB
sample3.txt AC 9 ms 3464 KB