fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6. const int n = 16, maxn = 1 << n;
  7. int dp[n + 1][maxn][2][3];
  8.  
  9. signed main()
  10. {
  11. ios::sync_with_stdio(0);
  12. cin.tie(0);
  13. vector<int> posib[n];
  14. for(int i = 0; i < 16; i++)
  15. {
  16. int m;
  17. cin >> m;
  18. posib[i].resize(m);
  19. for(int j = 0; j < m; j++)
  20. cin >> posib[i][j];
  21. }
  22. dp[0][0][0][2] = 1;
  23. for(int i = 0; i < n; i++)
  24. {
  25. for(int j = 0; j < posib[i].size(); j++)
  26. {
  27. if(posib[i][j] == 0)
  28. {
  29. for(int k = 0; k < maxn; k++)
  30. if((k & 1) == 0)
  31. {
  32. dp[i + 1][k ^ 1][0][(i / 4 + 1) % 2] += dp[i][k][0][2],
  33. dp[i + 1][k ^ 1][1][(i / 4 + 1) % 2] += dp[i][k][1][2];
  34. }
  35. }
  36. else
  37. {
  38. int z = posib[i][j];
  39. for(int k = 0; k < maxn; k++)
  40. {
  41. if((k >> z) & 1)
  42. continue;
  43. int t = __builtin_popcount(k >> z) % 2;
  44. for(int l = 0; l < 3; l++)
  45. dp[i + 1][k ^ (1 << z)][t][l] += dp[i][k][0][l],
  46. dp[i + 1][k ^ (1 << z)][t ^ 1][l] += dp[i][k][1][l];
  47. }
  48.  
  49. }
  50. }
  51. }
  52. int ans = 0;
  53. for(int i = 0; i < maxn; i++)
  54. ans += dp[n][i][0][0] + dp[n][i][1][1];
  55. cout << ans << "\n";
  56. return 0;
  57. }
Runtime error #stdin #stdout #stderr 0s 55688KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_default_append