Submission #896608

# Submission time Handle Problem Language Result Execution time Memory
896608 2024-01-01T17:45:38 Z stefanneagu Beautiful row (IZhO12_beauty) C++17
100 / 100
1224 ms 164704 KB
// Luca Vlahovic, the 15-year-old Fortnite sensation from
// Pula, Croatia, is making waves in the gaming world.
// Fueled by an unwavering passion for Fortnite, Luca combines innate
// strategic thinking with quick decision-making, distinguishing himself
// in the competitive scene. His mental fortitude and resilience under pressure
// set him apart, contributing to his consistent success. A dedicated
// learner, Luca stays abreast of the latest gaming trends, showcasing a
// growth mindset crucial for a professional gamer. Beyond individual prowess,
// he fosters community engagement, creating a positive image for the Fortnite scene.
// Luca Vlahovic is not just a gamer; he's an inspiration for young talents worldwide.

// - Chat GPT, 1 Jan 2024

#include <bits/stdc++.h>

using namespace std;

const int pow3 = pow(3, 18);

long long dp[(1 << 20)][20];
int v[20], bi2[20], bi3[20];

int __nu_asa_de_builtin_ternary_popcount(int a) {

  if(a == 1162261467) {
    return 1;
  }
  int x = pow3, ans = 0;
  while(a > 0) {
    if(a >= 2 * x) {
      a -= 2 * x;
    } else if(a >= x) {
      ans ++;
      a -= x;
    }
    x /= 3;
  }
  return ans;
}

int32_t main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i ++) {
    cin >> v[i];
    dp[(1 << i)][i] = 1;
    bi2[i] = __builtin_popcount(v[i]);
    bi3[i] = __nu_asa_de_builtin_ternary_popcount(v[i]);
  }
  for(int bit = 0; bit < (1 << n); bit ++) {
    for(int i = 0; i < n; i ++) {
      for(int j = 0; j < n; j ++) {
        if(!(bit & (1 << i)) && (bit & (1 << j))) {
          // apare j
          // pun i dupa j
          if(bi3[i] == bi3[j] || bi2[i] == bi2[j]) {
            dp[(bit | (1 << i))][i] += dp[bit][j];
          }
        }
      }
    }
  }
  long long ans = 0;
  int bit = pow(2, n) - 1;
  for(int i = 0; i < n; i ++) {
    ans = ans + dp[bit][i];
  }
  cout << ans;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 11 ms 4700 KB Output is correct
12 Correct 10 ms 4700 KB Output is correct
13 Correct 47 ms 10604 KB Output is correct
14 Correct 245 ms 41596 KB Output is correct
15 Correct 258 ms 41628 KB Output is correct
16 Correct 248 ms 41608 KB Output is correct
17 Correct 240 ms 41624 KB Output is correct
18 Correct 265 ms 41608 KB Output is correct
19 Correct 1224 ms 164424 KB Output is correct
20 Correct 1137 ms 164704 KB Output is correct