Submission #54352678


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, n) for (int i = a; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using lli = long long int;

int N;


template <typename T>
inline constexpr typename std::enable_if<std::is_integral<T>::value, T>::type
ipow(T x, std::size_t N, T res = 1) {
  return N < 1 ? res : ipow(x * x, N/2, (N&1) ? (res * x) : res);
}


bool isblack(int x, int y, int k3) {
  if (k3 == 1) { return true; }

  int k13 = k3/3;
  REP(i, 3) REP(j, 3) {
    int x1 =  i * k13;
    int x2 = x1 + k13;
    int y1 =  j * k13;
    int y2 = y1 + k13;
    if (!(x1 <= x && x < x2 && y1 <= y && y < y2)) { continue; }
    if (i == 1 && j == 1) { return false; }
    return isblack(x - x1, y - y1, k13);
  }
  return true;
}


int main() {
  cin >> N;

  int k3 = ipow(3, N);

  REP(i, k3) {
    REP(j, k3) { cout << (isblack(i, j, k3) ? '#' : '.'); }
    cout << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task C - Sierpinski carpet
User ryo_ryo66
Language C++ 20 (gcc 12.2)
Score 250
Code Size 995 Byte
Status AC
Exec Time 30 ms
Memory 3572 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 2
AC × 9
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3456 KiB
example_01.txt AC 1 ms 3436 KiB
test_00.txt AC 4 ms 3468 KiB
test_01.txt AC 1 ms 3564 KiB
test_02.txt AC 1 ms 3452 KiB
test_03.txt AC 1 ms 3572 KiB
test_04.txt AC 1 ms 3492 KiB
test_05.txt AC 30 ms 3372 KiB
test_06.txt AC 1 ms 3460 KiB