D: Disastrous Doubling

//就当模板看了

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

public class Main {
    static BigInteger b[] = new BigInteger[110000];
    static BigInteger mo = new BigInteger("1000000007");
    private static Scanner cin;

    public static void main(String[] args) {
        cin = new Scanner(System.in);
        int n;
        n = cin.nextInt();
        BigInteger now = BigInteger.ONE;
        boolean flag = true;
        for (int i = 0; i < n; i++) {
            now = now.add(now);
            b[i] = cin.nextBigInteger();
            if (now.compareTo(b[i]) < 0) {
                flag = false;
            }
            now = now.subtract(b[i]);
        }
        if (!flag) {
            System.out.println("error");
        } else
            System.out.println(now.mod(mo));
    }
}
posted @ 2021-10-15 19:09  梨花满地  阅读(41)  评论(0)    收藏  举报