Submission #3613270


Source Code Expand

#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;

int main()
{
  int n, m;
  string s[15], row[25];
  int size[15];
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
    size[i] = s[i].size();
  }
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> row[i];
  }

  char sheet[40][40];
  for (int i = 0; i < 40; i++)
  {
    for (int j = 0; j < 40; j++)
    {
      sheet[i][j] = '#';
    }
  }

  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < m; j++)
    {
      sheet[i + 1][j + 1] = row[i].at(j);
    }
  }	//1,1から

  int x[15], y[15], length[15];
  string ad[15];

  int index = 0;
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < m; j++)
    {
      if (sheet[i + 1][j + 1] == '.' && sheet[i + 1][j + 2] == '.' && sheet[i + 1][j] == '#')
      {
        x[index] = i + 1;
        y[index] = j + 1;
        ad[index] = "across";
        int check = 0;
        while (sheet[i + 1][j + 1 + check] == '.')
        {
          check++;
        }
        length[index] = check;
        index++;
      }

      if (sheet[i + 1][j + 1] == '.' && sheet[i + 2][j + 1] == '.' && sheet[i][j + 1] == '#')
      {
        x[index] = i + 1;
        y[index] = j + 1;
        ad[index] = "down";
        int check = 0;
        while (sheet[i + 1 + check][j + 1] == '.')
        {
          check++;
        }
        length[index] = check;
        index++;
      }
    }
  }

  vector<int> sort_n(n);
  for (int i = 0; i < n; i++)
  {
    sort_n[i] = i;
  }

  do
  {
    char sheet[40][40] = {'#'};
    for (int i = 0; i < m; i++)
    {
      for (int j = 0; j < m; j++)
      {
        sheet[i + 1][j + 1] = row[i].at(j);
      }
    }
    bool ditect = true;

    for (int i = 0; i < n; i++)
    {
      if (size[i] != length[sort_n[i]])
      {
        ditect = false;
      }
      else
      if (ad[sort_n[i]] == "across")
      {
        for (int j = 0; j < size[i]; j++)
        {
          if (sheet[x[sort_n[i]]][y[sort_n[i]] + j] != '.' && s[i].at(j) != sheet[x[sort_n[i]]][y[sort_n[i]] + j])
          {
            ditect = false;
          }
          else
          {
            sheet[x[sort_n[i]]][y[sort_n[i]] + j] = s[i].at(j);
          }
        }
      }
      else
      if (ad[sort_n[i]] == "down")
      {
        for (int j = 0; j < size[i]; j++)
        {
          if (sheet[x[sort_n[i]] + j][y[sort_n[i]]] != '.' && s[i].at(j) != sheet[x[sort_n[i]] + j][y[sort_n[i]]])
          {
            ditect = false;
          }
          else
          {
            sheet[x[sort_n[i]] + j][y[sort_n[i]]] = s[i].at(j);
          }
        }
      }
    }
    if (ditect)
    {
      cout << m << endl;
      for (int i = 0; i < m; i++)
      {
        for (int j = 0; j < m; j++)
        {
          cout << sheet[i + 1][j + 1];
        }
        cout << endl;
      }
    }
  }
  while (next_permutation(sort_n.begin(), sort_n.end()));
}

Submission Info

Submission Time
Task H - 恐怖!不幸を呼ぶ盾
User shirara
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3086 Byte
Status TLE
Exec Time 2103 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 18
TLE × 4
Set Name Test Cases
All 00_sample_00.txt, 00_sample_01.txt, 10_min_00.txt, 10_min_01.txt, 10_min_02.txt, 20_max_00.txt, 20_max_01.txt, 20_max_02.txt, 50_small_00.txt, 50_small_01.txt, 50_small_02.txt, 90_random_00.txt, 90_random_01.txt, 90_random_02.txt, 90_random_03.txt, 90_random_04.txt, 90_random_05.txt, 90_random_06.txt, 90_random_07.txt, 90_random_08.txt, 90_random_09.txt, 99_final_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
10_min_00.txt AC 1 ms 256 KB
10_min_01.txt AC 1 ms 256 KB
10_min_02.txt AC 1 ms 256 KB
20_max_00.txt TLE 2103 ms 256 KB
20_max_01.txt TLE 2103 ms 256 KB
20_max_02.txt TLE 2103 ms 256 KB
50_small_00.txt AC 1 ms 256 KB
50_small_01.txt AC 1 ms 256 KB
50_small_02.txt AC 1 ms 256 KB
90_random_00.txt AC 1 ms 256 KB
90_random_01.txt AC 2 ms 256 KB
90_random_02.txt AC 1 ms 256 KB
90_random_03.txt AC 1 ms 256 KB
90_random_04.txt AC 1 ms 256 KB
90_random_05.txt AC 2 ms 256 KB
90_random_06.txt AC 1 ms 256 KB
90_random_07.txt AC 1 ms 256 KB
90_random_08.txt AC 1 ms 256 KB
90_random_09.txt AC 1 ms 256 KB
99_final_00.txt TLE 2103 ms 256 KB