Submission #19402148


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);
  vi cen(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];
        }
      }     
      for(auto tmp: p) cout << tmp << " ";
      cout << "\n";
      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);
      }
      return ;
    }
    while(f[id] || cen[id]) id++;
    p[cnt] = id;
    f[id] = 1;
    for (int i = id+1; i < h; i++) {
      if(f[i] || cen[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) {
      cen[i] = 1;
      p[h/2] = i;
      rec(rec, 0, 0);
      cen[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 2705 Byte
Status WA
Exec Time 35 ms
Memory 3580 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
WA × 3
WA × 63
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 9 ms 3460 KB
10.txt WA 2 ms 3540 KB
100.txt WA 3 ms 3452 KB
11.txt WA 7 ms 3460 KB
12.txt WA 6 ms 3500 KB
13.txt WA 6 ms 3404 KB
14.txt WA 18 ms 3548 KB
15.txt WA 27 ms 3408 KB
16.txt WA 27 ms 3540 KB
17.txt WA 28 ms 3400 KB
18.txt WA 10 ms 3448 KB
19.txt WA 28 ms 3516 KB
2.txt WA 2 ms 3540 KB
20.txt WA 23 ms 3380 KB
21.txt WA 28 ms 3436 KB
22.txt WA 33 ms 3384 KB
23.txt WA 31 ms 3404 KB
24.txt WA 19 ms 3460 KB
25.txt WA 12 ms 3540 KB
26.txt WA 33 ms 3432 KB
27.txt WA 29 ms 3548 KB
28.txt WA 35 ms 3484 KB
29.txt WA 11 ms 3376 KB
3.txt WA 2 ms 3400 KB
30.txt WA 33 ms 3548 KB
31.txt WA 25 ms 3456 KB
32.txt WA 13 ms 3400 KB
33.txt WA 27 ms 3500 KB
34.txt WA 33 ms 3428 KB
35.txt WA 32 ms 3568 KB
36.txt WA 20 ms 3380 KB
37.txt WA 26 ms 3484 KB
38.txt WA 25 ms 3380 KB
39.txt WA 22 ms 3448 KB
4.txt WA 2 ms 3536 KB
40.txt WA 33 ms 3464 KB
41.txt WA 31 ms 3540 KB
42.txt WA 34 ms 3496 KB
43.txt WA 27 ms 3404 KB
44.txt WA 10 ms 3380 KB
45.txt WA 26 ms 3568 KB
46.txt WA 17 ms 3464 KB
47.txt WA 26 ms 3464 KB
48.txt WA 30 ms 3576 KB
49.txt WA 32 ms 3484 KB
5.txt WA 2 ms 3480 KB
50.txt WA 33 ms 3496 KB
51.txt WA 28 ms 3580 KB
52.txt WA 25 ms 3520 KB
53.txt WA 31 ms 3464 KB
54.txt WA 5 ms 3372 KB
55.txt WA 2 ms 3376 KB
56.txt WA 31 ms 3552 KB
6.txt WA 2 ms 3380 KB
7.txt WA 2 ms 3460 KB
8.txt WA 2 ms 3448 KB
9.txt WA 2 ms 3376 KB
sample1.txt WA 3 ms 3536 KB
sample2.txt WA 3 ms 3548 KB
sample3.txt WA 18 ms 3464 KB