aboutsummaryrefslogtreecommitdiff
path: root/count_total_coloured_cell.c
blob: 4e86d1bbccacc7aae0341a9f6d8281c28fbb379a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 2579. Count Total Number of Colored Cells
#include "leetcode.h"

/*
 * there exists an infinitely large two-dimensional grid of uncoloured unit
 * cells. you are given a positive integer 'n', indicating that you must do the
 * following routine for 'n' minutes: at the first minute, colour any arbitrary
 * unit cell blue, and every minute thereafter, colour blue every uncoloured
 * cell that touches a blue cell.
 */

long long coloredCells(int n) { return 2L * n * (n - 1) + 1; }

int main() {
  printf("%lld\n", coloredCells(1)); // expect: 1
  printf("%lld\n", coloredCells(2)); // expect: 5
}