結果

問題 No.988 N×Mマス計算(総和)
ユーザー TatsuyaaaaTatsuyaaaa
提出日時 2020-02-14 21:56:18
言語 Java19
(openjdk 21)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 2,567 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 74,196 KB
実行使用メモリ 59,488 KB
最終ジャッジ日時 2023-09-20 11:52:37
合計ジャッジ時間 6,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,968 KB
testcase_01 AC 43 ms
49,628 KB
testcase_02 AC 45 ms
49,744 KB
testcase_03 AC 47 ms
49,704 KB
testcase_04 AC 46 ms
49,484 KB
testcase_05 AC 45 ms
49,696 KB
testcase_06 AC 45 ms
49,508 KB
testcase_07 AC 45 ms
49,240 KB
testcase_08 AC 46 ms
49,408 KB
testcase_09 AC 45 ms
49,812 KB
testcase_10 AC 215 ms
56,032 KB
testcase_11 AC 218 ms
55,056 KB
testcase_12 AC 288 ms
58,068 KB
testcase_13 AC 230 ms
56,080 KB
testcase_14 AC 224 ms
56,356 KB
testcase_15 AC 164 ms
54,932 KB
testcase_16 AC 286 ms
56,616 KB
testcase_17 AC 274 ms
56,068 KB
testcase_18 AC 199 ms
55,804 KB
testcase_19 AC 294 ms
57,908 KB
testcase_20 AC 338 ms
59,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int N = in.nextInt();
        int M = in.nextInt();
        int K = in.nextInt();
        String S = in.next();
        long[] B = new long[M];
        long[] A = new long[N];
        long B_sum = 0L;
        long A_sum = 0L;
        for (int i=0;i<M;i++) {
            B[i] = in.nextLong();
            B_sum += B[i];
        }
        for (int i=0;i<N;i++) {
            A[i] = in.nextLong();
            A_sum += A[i];
        }
        B_sum%=K;
        A_sum%=K;

        if (S.charAt(0)=='+') {
            out.println((N*B_sum%K+M*A_sum%K)%K);
        } else { // S.charAt(0)=='*'
            long ans = 0L;
            out.println(B_sum*A_sum%K);
        }
        // for (int i=0;i<N;i++) {
        //     StringBuilder sb = new StringBuilder();
        //     for (int j=0;j<M;j++) {
        //         long tmp = 0;
        //         if (S.charAt(0)=='+') {
        //             tmp = A[i]+B[j];
        //         } else { // S.charAt(0)=='*'
        //             tmp = A[i]*B[j];
        //         }
        //         sb.append(tmp);
        //         if (j!=M-1) sb.append(" ");
        //     }
        //     System.out.println(sb);
        // }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
0