結果

問題 No.1448 和差算
ユーザー neko_the_shadowneko_the_shadow
提出日時 2021-04-08 13:00:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 5,197 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 84,176 KB
実行使用メモリ 38,360 KB
最終ジャッジ日時 2024-06-23 16:48:20
合計ジャッジ時間 7,541 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
38,252 KB
testcase_01 AC 64 ms
38,020 KB
testcase_02 AC 59 ms
38,068 KB
testcase_03 AC 61 ms
37,840 KB
testcase_04 AC 58 ms
37,844 KB
testcase_05 AC 58 ms
38,108 KB
testcase_06 AC 67 ms
37,812 KB
testcase_07 AC 60 ms
38,000 KB
testcase_08 AC 60 ms
37,536 KB
testcase_09 AC 68 ms
37,828 KB
testcase_10 AC 59 ms
38,208 KB
testcase_11 AC 62 ms
38,104 KB
testcase_12 AC 61 ms
37,800 KB
testcase_13 AC 64 ms
38,136 KB
testcase_14 AC 65 ms
37,972 KB
testcase_15 AC 64 ms
37,756 KB
testcase_16 AC 66 ms
38,360 KB
testcase_17 AC 61 ms
37,840 KB
testcase_18 AC 65 ms
37,856 KB
testcase_19 AC 63 ms
38,208 KB
testcase_20 AC 63 ms
37,980 KB
testcase_21 AC 65 ms
37,720 KB
testcase_22 AC 63 ms
38,076 KB
testcase_23 AC 60 ms
37,840 KB
testcase_24 AC 65 ms
38,220 KB
testcase_25 AC 65 ms
38,248 KB
testcase_26 AC 62 ms
37,752 KB
testcase_27 AC 67 ms
37,844 KB
testcase_28 AC 61 ms
37,728 KB
testcase_29 AC 60 ms
37,980 KB
testcase_30 AC 58 ms
37,596 KB
testcase_31 AC 59 ms
37,440 KB
testcase_32 AC 62 ms
37,696 KB
testcase_33 AC 62 ms
38,336 KB
testcase_34 AC 69 ms
38,004 KB
testcase_35 AC 61 ms
38,156 KB
testcase_36 AC 60 ms
38,120 KB
testcase_37 AC 58 ms
37,852 KB
testcase_38 AC 57 ms
37,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.function.Supplier;
import java.util.regex.Pattern;

public class Main {
    public void exec() {
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();
        long n = stdin.nextLong();
        
        long ans = Long.MIN_VALUE;
        for (long p : new long[] {a, b}) {
            for (long q : new long[] {c, d}) {
                long x = p;
                long y = q;
                for (int i = 0; i < n%8; i++) {
                    long nx = x-y;
                    long ny = x+y;
                    x = nx;
                    y = ny;
                }
                ans = Math.max(ans, x+y);
            }
        }
        
        long mod = 1000000007;
        stdout.println((ans%mod+mod)%mod*modPow(16, n/8, mod)%mod);
    }
    
    public long modPow(long x, long y, long mod) {
        return BigInteger.valueOf(x).modPow(BigInteger.valueOf(y), BigInteger.valueOf(mod)).longValue();
    }

    private static final Stdin stdin = new Stdin(System.in);
    private static final Stdout stdout = new Stdout(System.out);

    public static void main(String[] args) {
        try {
            new Main().exec();
        } finally {
            stdout.flush();
        }
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader in;
        private Pattern space;

        public Stdin(InputStream in) {
            this.queue = new ArrayDeque<>();
            this.in = new BufferedReader(new InputStreamReader(in));
            this.space = Pattern.compile(" ");
        }

        public String nextString() {
            if (queue.isEmpty()) {
                try {
                    String line = in.readLine();
                    if (line == null) {
                        throw new EOFException();
                    }
                    space.splitAsStream(line).forEach(this.queue::addLast);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return queue.removeFirst();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public double nextDouble() {
            return Double.parseDouble(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }
        
        public BigInteger nextBigInteger() {
            return new BigInteger(nextString());
        }

        public String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) a[i] = nextString();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
        
        public BigInteger[] nexBigIntegerArray(int n) {
            BigInteger[] a = new BigInteger[n];
            for (int i = 0; i < n; i++) a[i] = nextBigInteger();
            return a;
        }
        
        public List<Integer> nextIntegerList(int n) {
            return nextList(n, this::nextInt);
        }
        
        public List<Long> nextLongList(int n) {
            return nextList(n, this::nextLong);
        }
        
        public List<Double> nextDoubleList(int n) {
            return nextList(n, this::nextDouble);
        }
        
        public List<String> nextStringList(int n) {
            return nextList(n, this::nextString);
        }
        
        public List<BigInteger> nextBigIntegerList(int n) {
            return nextList(n, this::nextBigInteger);
        }
        
        private <T> List<T> nextList(int n, Supplier<T> supplier) {
            List<T> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(supplier.get());
            return a;
        }
    }

    public static class Stdout {
        private PrintWriter stdout;

        public Stdout(PrintStream stdout) {
            this.stdout =  new PrintWriter(stdout, false);
        }

        public void println(Object ... objs) {
            for (int i = 0, len = objs.length; i < len; i++) {
                stdout.print(objs[i]);
                if (i != len-1) stdout.print(' ');
            }
            stdout.println();
        }

        public void flush() {
            stdout.flush();
        }
    }
}
0