Advertisement
paranid5

11.02

Feb 13th, 2022
2,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.56 KB | None | 0 0
  1. import groovy.transform.Field
  2.  
  3. final boolean arrow(final boolean a, final boolean b) { return !(a && !b) }
  4.  
  5. final String repeat(final CharSequence string, final int count) {
  6.     final builder = new StringBuilder(string.size() * count)
  7.     1.upto(count) { builder.append(string) }
  8.     return builder.toString()
  9. }
  10.  
  11. @Field
  12. final Tuple2<Integer, Integer> invalid = new Tuple2<>(1e9.toInteger(), 0)
  13.  
  14. final Tuple2<Integer, Integer> dfs(
  15.         final List<List<Integer>> table,
  16.         final List<List<Tuple2<Integer, Integer>>> dp,
  17.         final int n = table.size() - 1,
  18.         final int m = table.size() - 1
  19. ) {
  20.     if (n < 0 || m < 0)
  21.         return invalid
  22.  
  23.     if (dp[n][m] != invalid)
  24.         return dp[n][m]
  25.  
  26.     final isOk = { final int x, final int y ->
  27.         (x >= 1 && x <= 6 && y >= 1 && y <= 3) ||
  28.                 (x == 3 && y >= 8 && y <= 15) ||
  29.                 (x >= 9 && x <= 16 && y == 5) ||
  30.                 (x >= 9 && x <= 14 && y >= 11 && y <= 15)
  31.     }
  32.  
  33.     final first = dfs(table, dp, n - 1, m)
  34.     final second = dfs(table, dp, n, m - 1)
  35.     final third = isOk(n - 1, m - 1) ? invalid : dfs(table, dp, n - 1, m - 1)
  36.  
  37.     dp[n][m] = new Tuple2<>(
  38.             [first.first, second.first, third.first].min() + table[n][m],
  39.             [first.second, second.second, third.second].max() + table[n][m]
  40.     )
  41.  
  42.     return dp[n][m]
  43. }
  44.  
  45. final int _rec(
  46.         final int cnt = 0,
  47.         final List<Integer> nums = new ArrayList<>(),
  48.         final int n = 2,
  49.         final int end = 25,
  50.         final List<Integer> contains = [17],
  51.         final List<Integer> notContains = [22]
  52. ) {
  53.     if (n >= end)
  54.         return cnt + (n == end &&
  55.                 contains.every { nums.contains(it) } &&
  56.                 !notContains.any { nums.contains(it) } ? 1 : 0)
  57.  
  58.     final plus = nums + n
  59.     return _rec(cnt, plus, n + 1) + _rec(cnt, plus, n + 3) + _rec(cnt, plus, n * n)
  60. }
  61.  
  62. final List<Integer> getDivs(final int n, final List<Integer> exclusive = [1, n]) {
  63.     final list = new ArrayList()
  64.  
  65.     for (int i = 1; i * i <= n; i++) {
  66.         if (n % i == 0 && !exclusive.contains(i)) {
  67.             list.add(i)
  68.  
  69.             if (i * i != n && !exclusive.contains(n.intdiv(i)))
  70.                 list.add(n.intdiv(i))
  71.         }
  72.     }
  73.  
  74.     return list
  75. }
  76.  
  77. final list = (1200000..0)
  78.         .collect {
  79.             final list = getDivs(it).sort().take(2)
  80.             new Tuple2<>(it, list.size() == 2 ? (int)list.sum() : 0)
  81.         }
  82.         .findAll { it.second != 0 && it.second % 2022 == 0 }
  83.         .take(5)
  84.         .forEach { println(it) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement