結果
| 問題 |
No.988 N×Mマス計算(総和)
|
| コンテスト | |
| ユーザー |
Tatsuyaaaa
|
| 提出日時 | 2020-02-14 21:56:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 315 ms / 2,000 ms |
| コード長 | 2,567 bytes |
| コンパイル時間 | 1,823 ms |
| コンパイル使用メモリ | 77,796 KB |
| 実行使用メモリ | 59,752 KB |
| 最終ジャッジ日時 | 2024-07-06 07:13:58 |
| 合計ジャッジ時間 | 5,650 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
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());
}
}
}
Tatsuyaaaa