QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519130#8520. Xor PartitionsSocialPandaCompile Error//Python31.2kb2024-08-14 16:30:352024-08-14 16:30:35

Judging History

你现在查看的是最新测评结果

  • [2024-08-14 16:30:35]
  • 评测
  • [2024-08-14 16:30:35]
  • 提交

answer

import java.math.BigInteger;
import java.util.Scanner;

public class PartitionXorSum {
    private static final BigInteger MOD = BigInteger.valueOf(1_000_000_007);

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] a = new long[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextLong();
        }
        
        BigInteger result = calculatePartitionSum(n, a);
        System.out.println(result);
    }

    private static BigInteger calculatePartitionSum(int n, long[] a) {
        long[] xorSum = new long[n + 1];
        BigInteger[] dp = new BigInteger[n + 1];
        dp[0] = BigInteger.ONE; // Base case: one way to partition an empty sequence
        
        for (int i = 1; i <= n; i++) {
            xorSum[i] = 0;
            dp[i] = BigInteger.ZERO;
            for (int j = i; j > 0; j--) {
                xorSum[j] ^= a[i - 1];
                dp[i] = dp[i].add(dp[j - 1].multiply(BigInteger.valueOf(xorSum[j])));
                dp[i] = dp[i].mod(MOD);
            }
        }
        
        return dp[n];
    }
}

详细

  File "answer.code", line 4
    public class PartitionXorSum {
           ^^^^^
SyntaxError: invalid syntax