Submission #19401646


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) break;
          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.assign(h, 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 2588 Byte
Status RE
Exec Time 109 ms
Memory 3576 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 7 ms 3576 KB
10.txt AC 2 ms 3544 KB
100.txt AC 2 ms 3484 KB
11.txt AC 3 ms 3380 KB
12.txt AC 4 ms 3432 KB
13.txt RE 102 ms 3240 KB
14.txt AC 9 ms 3540 KB
15.txt RE 102 ms 3180 KB
16.txt AC 17 ms 3380 KB
17.txt RE 101 ms 3124 KB
18.txt AC 10 ms 3380 KB
19.txt RE 101 ms 3280 KB
2.txt AC 2 ms 3440 KB
20.txt AC 11 ms 3576 KB
21.txt RE 106 ms 3224 KB
22.txt AC 18 ms 3360 KB
23.txt RE 103 ms 3184 KB
24.txt RE 103 ms 3180 KB
25.txt AC 4 ms 3472 KB
26.txt RE 102 ms 3108 KB
27.txt RE 100 ms 3348 KB
28.txt AC 13 ms 3544 KB
29.txt AC 8 ms 3364 KB
3.txt AC 2 ms 3368 KB
30.txt RE 108 ms 3240 KB
31.txt RE 102 ms 3348 KB
32.txt AC 3 ms 3540 KB
33.txt RE 109 ms 3176 KB
34.txt AC 16 ms 3376 KB
35.txt AC 15 ms 3364 KB
36.txt RE 105 ms 3240 KB
37.txt AC 17 ms 3500 KB
38.txt RE 103 ms 3176 KB
39.txt RE 101 ms 3120 KB
4.txt AC 2 ms 3536 KB
40.txt AC 19 ms 3372 KB
41.txt RE 103 ms 3348 KB
42.txt AC 17 ms 3476 KB
43.txt AC 15 ms 3432 KB
44.txt RE 106 ms 3260 KB
45.txt AC 22 ms 3444 KB
46.txt RE 102 ms 3224 KB
47.txt AC 15 ms 3484 KB
48.txt RE 101 ms 3288 KB
49.txt AC 23 ms 3496 KB
5.txt AC 2 ms 3436 KB
50.txt RE 103 ms 3284 KB
51.txt AC 13 ms 3540 KB
52.txt AC 13 ms 3372 KB
53.txt AC 16 ms 3540 KB
54.txt AC 2 ms 3384 KB
55.txt AC 2 ms 3548 KB
56.txt AC 13 ms 3536 KB
6.txt AC 2 ms 3532 KB
7.txt AC 2 ms 3572 KB
8.txt AC 2 ms 3380 KB
9.txt RE 106 ms 3240 KB
sample1.txt AC 2 ms 3376 KB
sample2.txt AC 2 ms 3484 KB
sample3.txt AC 7 ms 3380 KB