結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
Tatsuyaaaa
|
| 提出日時 | 2020-02-14 22:52:09 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,997 bytes |
| コンパイル時間 | 2,574 ms |
| コンパイル使用メモリ | 78,988 KB |
| 実行使用メモリ | 66,276 KB |
| 最終ジャッジ日時 | 2024-11-16 01:14:59 |
| 合計ジャッジ時間 | 8,271 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 10 WA * 9 |
ソースコード
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 {
static long gcd(long a,long b) {
long temp;
while ((temp=a%b)!=0) {
a=b;
b=temp;
}
return b;
}
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();
char op = in.next().charAt(0);
long[] B = new long[M];
long[] A = new long[N];
// long B_sum = 0L;
// long A_sum = 0L;
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> mul_map = new HashMap<Integer, Integer>();
for (int i=0;i<M;i++) {
B[i] = in.nextLong();
int remainder = (int)B[i]%K;
if (!map.containsKey(remainder)) {
map.put(remainder, 1);
} else {
map.put(remainder, map.get(remainder)+1);
}
int val = K/(int)gcd(K, B[i]);
if (!mul_map.containsKey(val)) {
mul_map.put(val, 1);
} else {
mul_map.put(val, mul_map.get(val)+1);
}
// B_sum += B[i];
}
long ans_plus = 0L;
long ans_mul = 0L;
ArrayList<Integer> keys = new ArrayList<Integer>(mul_map.keySet());
ArrayList<Integer> vals = new ArrayList<Integer>(mul_map.values());
for (int i=0;i<N;i++) {
A[i] = in.nextLong();
// A_sum += A[i];
int val = K-(int)A[i]%K;
if (map.containsKey(val)) {
ans_plus += map.get(val);
}
if (A[i]%K==0) ans_mul+=M;
else {
int mul_tmp = 0;
// for (int j=0;j<keys.size();j++) {
// if (A[i]%keys.get(j)==0) mul_tmp+=vals.get(j);
// }
// int val_2 = (int)gcd(K, A[i]);
// if (mul_map.containsKey(val_2)) {
// ans_mul += mul_map.get(val_2);
// }
ans_mul+=mul_tmp;
}
}
// out.println("K: "+K);
// out.println(mul_map);
if (op=='+') out.println(ans_plus);
if (op=='*') out.println(ans_mul);
// out.println(map);
// Arrays.sort(B);
// long ans = 0L;
// for (int i=0;i<N;i++) {
// long tmp = 0;
// if (op=='+') tmp = K-A[i];
// if (op=='*') tmp = (K+A[i]-1)/A[i];
// // ans += binary_search(tmp, B, op);
// int index = ~Arrays.binarySearch(B, tmp, (o1, o2)->o1>=o2?1:-1);
// ans += M-index;
// }
// out.println(ans);
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