Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. vector<int> prisonAfterNDays(vector<int>& c, int N) {
  2.   vector<int> f_c, next_c(c.size(), 0);
  3.   for (int cycle = 0; N-- > 0; c = next_c, ++cycle) {
  4.     for (auto i = 1; i < c.size() - 1; ++i) next_c[i] = c[i - 1] == c[i + 1];
  5.     if (cycle == 0) f_c = next_c;
  6.     else if (next_c == f_c) N %= cycle;
  7.   }
  8.   return c;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement