Submission #10688750


Source Code Expand

Copy
#define DEBUG 0
/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2020/3/8 22:03:07
 * Powered by Visual Studio Code
 */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// ----- boost -----
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// ----- using directives and manipulations -----
using namespace std;
using boost::rational;
using boost::multiprecision::cpp_int;
using ll = long long;
template <typename T>
using max_heap = priority_queue<T>;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
// ----- constexpr for Mint and Combination -----
constexpr ll MOD{1000000007LL};
// constexpr ll MOD{998244353LL}; // be careful
constexpr ll MAX_SIZE{3000010LL};
// constexpr ll MAX_SIZE{30000010LL}; // if 10^7 is needed
// ----- ch_max and ch_min -----
template <typename T>
void ch_max(T &left, T right)
{
  if (left < right)
  {
    left = right;
  }
}
template <typename T>
void ch_min(T &left, T right)
{
  if (left > right)
  {
    left = right;
  }
}
// ----- Mint -----
template <ll MOD = MOD>
class Mint
{
public:
  ll x;
  Mint() : x{0LL} {}
  Mint(ll x) : x{(x % MOD + MOD) % MOD} {}
  Mint operator-() const { return x ? MOD - x : 0; }
  Mint &operator+=(const Mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  Mint &operator-=(const Mint &a) { return *this += -a; }
  Mint &operator++() { return *this += 1; }
  Mint &operator++(int)
  {
    Mint tmp{*this};
    ++*this;
    return tmp;
  }
  Mint &operator--() { return *this -= 1; }
  Mint &operator--(int)
  {
    Mint tmp{*this};
    --*this;
    return tmp;
  }
  Mint &operator*=(const Mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  Mint &operator/=(const Mint &a)
  {
    Mint b{a};
    return *this *= b.power(MOD - 2);
  }
  Mint operator+(const Mint &a) const { return Mint(*this) += a; }
  Mint operator-(const Mint &a) const { return Mint(*this) -= a; }
  Mint operator*(const Mint &a) const { return Mint(*this) *= a; }
  Mint operator/(const Mint &a) const { return Mint(*this) /= a; }
  bool operator<(const Mint &a) const { return x < a.x; }
  bool operator<=(const Mint &a) const { return x <= a.x; }
  bool operator>(const Mint &a) const { return x > a.x; }
  bool operator>=(const Mint &a) const { return x >= a.x; }
  bool operator==(const Mint &a) const { return x == a.x; }
  bool operator!=(const Mint &a) const { return !(*this == a); }
  const Mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      Mint half = power(N / 2);
      return half * half;
    }
  }
};
template <ll MOD>
Mint<MOD> operator+(ll lhs, const Mint<MOD> &rhs)
{
  return rhs + lhs;
}
template <ll MOD>
Mint<MOD> operator-(ll lhs, const Mint<MOD> &rhs)
{
  return -rhs + lhs;
}
template <ll MOD>
Mint<MOD> operator*(ll lhs, const Mint<MOD> &rhs)
{
  return rhs * lhs;
}
template <ll MOD>
Mint<MOD> operator/(ll lhs, const Mint<MOD> &rhs)
{
  return Mint<MOD>{lhs} / rhs;
}
template <ll MOD>
istream &operator>>(istream &stream, Mint<MOD> &a)
{
  return stream >> a.x;
}
template <ll MOD>
ostream &operator<<(ostream &stream, const Mint<MOD> &a)
{
  return stream << a.x;
}
// ----- Combination -----
template <ll MOD = MOD, ll MAX_SIZE = MAX_SIZE>
class Combination
{
public:
  vector<Mint<MOD>> inv, fact, factinv;
  Combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2LL; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[MOD % i]) * (MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1LL; i < MAX_SIZE; i++)
    {
      fact[i] = Mint<MOD>(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  Mint<MOD> operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
  Mint<MOD> catalan(int x, int y)
  {
    return (*this)(x + y, y) - (*this)(x + y, y - 1);
  }
};
// ----- for C++14 -----
using mint = Mint<MOD>;
using combination = Combination<MOD, MAX_SIZE>;
template <typename T>
T gcd(T x, T y) { return y ? gcd(y, x % y) : x; }
template <typename T>
T lcm(T x, T y) { return x / gcd(x, y) * y; }
// ----- for C++17 -----
template <typename T>
int popcount(T x) // C++20
{
  int ans{0};
  while (x != 0)
  {
    ans += x & 1;
    x >>= 1;
  }
  return ans;
}
// ----- frequently used constexpr -----
// constexpr double epsilon{1e-10};
// constexpr ll infty{1000000000000000LL}; // or
// constexpr int infty{1'000'000'010};
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
// ----- Yes() and No() -----
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}
// ----- main() -----

using field = vector<vector<int>>;

class Solve
{
  int N, M;
  int R, C;
  vector<field> V;

public:
  Solve(int N, int M) : N{N}, M{M}
  {
    R = (1 << N) - 1;
    C = (1 << M) - 1;
    /*
    all();
    int maxi{max_score()};
    cerr << "maxi = " << maxi << endl;
    flush_score_ban(maxi);
    */
    if (R == 1 && C == 1)
    {
      cout << 1 << endl;
      return;
    }
    for (auto i = 0; i < R; ++i)
    {
      for (auto j = 0; j < C; ++j)
      {
        if (i == R / 2 && j == C / 2)
        {
          cout << 0;
        }
        else
        {
          cout << 1;
        }
      }
      cout << endl;
    }
  }

private:
  void all()
  {
    ll X{1LL << (R * C)};
    for (auto i = 0; i < X; ++i)
    {
      field ban(R, vector<int>(C, 0));
      for (auto j = 0; j < R * C; ++j)
      {
        if ((i >> j) & 1)
        {
          ban[j / C][j % C] = 1;
        }
      }
      V.push_back(ban);
    }
  }

  int score(field const &ban)
  {
    int ans{0};
    for (auto i = 0; i < R; ++i)
    {
      for (auto j = i + 1; j <= R; ++j)
      {
        for (auto k = 0; k < C; ++k)
        {
          for (auto l = k + 1; l <= C; ++l)
          {
            int t{0};
            for (auto a = i; a < j; ++a)
            {
              for (auto b = k; b < l; ++b)
              {
                t += ban[a][b];
              }
            }
            if (t % 2 == 1)
            {
              ++ans;
            }
          }
        }
      }
    }
    return ans;
  }

  int max_score()
  {
    int ans{0};
    for (auto const &ban : V)
    {
      ch_max(ans, score(ban));
    }
    return ans;
  }

  void flush_score_ban(int s)
  {
    for (auto const &ban : V)
    {
      if (score(ban) == s)
      {
        cerr << "----" << endl;
        for (auto i = 0; i < R; ++i)
        {
          for (auto j = 0; j < C; ++j)
          {
            cerr << ban[i][j];
          }
          cerr << endl;
        }
      }
    }
  }
};

int main()
{
  int N, M;
  cin >> N >> M;
  Solve solve(N, M);
}

Submission Info

Submission Time
Task E - Odd Sum Rectangles
User kazunetakahashi
Language C++14 (GCC 5.4.1)
Score 0
Code Size 7608 Byte
Status
Exec Time 51 ms
Memory 1280 KB

Judge Result

Set Name Score / Max Score Test Cases
All 0 / 900 00_sample_01, 02_random_01, 02_random_02, 02_random_03, 02_random_04, 02_random_05, 02_random_06, 02_random_07, 02_random_08, 02_random_09, 02_random_10, 02_random_11, 02_random_12, 02_random_13, 02_random_14, 02_random_15, 02_random_16
sample 0 / 0 00_sample_01
Case Name Status Exec Time Memory
00_sample_01 1 ms 256 KB
02_random_01 1 ms 256 KB
02_random_02 1 ms 256 KB
02_random_03 1 ms 256 KB
02_random_04 1 ms 256 KB
02_random_05 3 ms 256 KB
02_random_06 51 ms 1280 KB
02_random_07 26 ms 768 KB
02_random_08 27 ms 768 KB
02_random_09 7 ms 384 KB
02_random_10 15 ms 512 KB
02_random_11 1 ms 256 KB
02_random_12 2 ms 256 KB
02_random_13 1 ms 256 KB
02_random_14 2 ms 256 KB
02_random_15 1 ms 256 KB
02_random_16 1 ms 256 KB