Submission #2384052


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

bool is_sym(const string& s, const string &t) {
  int w = s.size();
  REP(i,w) {
    if (s[i] != t[w-i-1]) return false;
  }
  return true;
}

bool isok(const vector<string>& t) {
  int h = t.size();
  int w = t[0].size();
  vector<string> u(h);
  REP(i,h) u[i] = string(w, '.');
  vector<string> rem;
  REP(i,w) {
    string s;
    REP(j,h) s += t[j][i];
    rem.push_back(s);
  }
  int k = 0;
  while (!rem.empty()) {
    bool ok = false;
    FOR(i,1,rem.size()) {
      if (is_sym(rem[0], rem[i])) {
        REP(j,h) {
          u[j][k] = rem[0][j];
          u[j][w-k-1] = rem[i][j];
        }
        ++k;
        ok = true;
        rem.erase(begin(rem) + i);
        break;
      }
    }
    if (!ok) {
      if (is_sym(rem[0], rem[0]) && (w%2) == 1 && u[0][w/2] == '.') {
        REP(j,h) {
          u[j][w/2] = rem[0][j];
        }
      } else {
        return false;
      }
    }
    rem.erase(begin(rem));
  }
  return true;
}

bool solve(const vector<string>& t, int k = 0) {
  int h = t.size();
  if (2*k >= h-1) return isok(t);
  FOR(i,k+1,h-k) {
    vector<string> s = t;
    swap(s[i], s[h-k-1]);
    if (solve(s, k+1)) return true;
  }
  return false;
}

int main()
{
  int h, w;
  cin>>h>>w;
  vector<string> t(h);
  REP(i,h) cin>>t[i];
  bool res = solve(t);
  if (res) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task E - Symmetric Grid
User primenumber
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1669 Byte
Status WA
Exec Time 50 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 56
WA × 7
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 1 ms 256 KB
10.txt WA 1 ms 256 KB
100.txt AC 1 ms 256 KB
11.txt AC 5 ms 256 KB
12.txt AC 5 ms 256 KB
13.txt WA 18 ms 256 KB
14.txt AC 13 ms 256 KB
15.txt AC 15 ms 256 KB
16.txt AC 49 ms 256 KB
17.txt AC 18 ms 256 KB
18.txt AC 12 ms 256 KB
19.txt AC 17 ms 256 KB
2.txt AC 1 ms 256 KB
20.txt AC 33 ms 256 KB
21.txt AC 18 ms 256 KB
22.txt AC 46 ms 256 KB
23.txt AC 17 ms 256 KB
24.txt AC 6 ms 256 KB
25.txt AC 10 ms 256 KB
26.txt AC 18 ms 256 KB
27.txt AC 18 ms 256 KB
28.txt AC 50 ms 256 KB
29.txt AC 10 ms 256 KB
3.txt AC 1 ms 256 KB
30.txt WA 17 ms 256 KB
31.txt AC 17 ms 256 KB
32.txt AC 6 ms 256 KB
33.txt AC 18 ms 256 KB
34.txt AC 47 ms 256 KB
35.txt AC 47 ms 256 KB
36.txt WA 17 ms 256 KB
37.txt AC 41 ms 256 KB
38.txt AC 18 ms 256 KB
39.txt AC 16 ms 256 KB
4.txt AC 1 ms 256 KB
40.txt AC 47 ms 256 KB
41.txt AC 17 ms 256 KB
42.txt AC 46 ms 256 KB
43.txt AC 50 ms 256 KB
44.txt WA 18 ms 256 KB
45.txt AC 46 ms 256 KB
46.txt WA 17 ms 256 KB
47.txt AC 43 ms 256 KB
48.txt AC 18 ms 256 KB
49.txt AC 47 ms 256 KB
5.txt AC 1 ms 256 KB
50.txt AC 17 ms 256 KB
51.txt AC 46 ms 256 KB
52.txt AC 48 ms 256 KB
53.txt AC 49 ms 256 KB
54.txt AC 1 ms 256 KB
55.txt AC 1 ms 256 KB
56.txt AC 50 ms 256 KB
6.txt AC 1 ms 256 KB
7.txt AC 1 ms 256 KB
8.txt AC 1 ms 256 KB
9.txt AC 1 ms 256 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 22 ms 256 KB