From f26558f316043d0e3302f770f4bd4b833d641395 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Sun, 15 Nov 2026 23:30:57 +0900 Subject: [PATCH] 988. Smallest String Starting From Leaf --- ... on Array to Maximize Sum of Squares.java" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/2897. Apply Operations on Array to Maximize Sum of Squares.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/2897. Apply Operations on Array to Maximize Sum of Squares.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/2897. Apply Operations on Array to Maximize Sum of Squares.java" new file mode 100644 index 00000000..4e6808ea --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/2897. Apply Operations on Array to Maximize Sum of Squares.java" @@ -0,0 +1,36 @@ +/* + 시간 초과로 실패, 다시 풀어볼 예정... + */ + + +class Solution { + private static final int MOD = 1_000_000_007; + private static final int BITS = 30; + + public int maxSum(List nums, int k) { + int[] bitCount = new int[BITS]; + + for (int num : nums) { + for (int b = 0; b < BITS; b++) { + if ((num & (1 << b)) != 0) { + bitCount[b]++; + } + } + } + + long ans = 0; + for (int i = 0; i < k; i++) { + long current = 0; + for (int b = 0; b < BITS; b++) { + if (bitCount[b] > 0) { + current |= (1L << b); + bitCount[b]--; + } + } + long sq = (current % MOD) * (current % MOD) % MOD; + ans = (ans + sq) % MOD; + } + + return (int) ans; + } +} \ No newline at end of file