05-18 01:37
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Polymolphism
- Entity
- systemd
- dbms
- preprocessing
- descriptive statistics
- Java
- 셀레니움
- 리눅스
- literal
- External Scheme
- X윈도우
- Entity Set
- python
- Binary Search
- 리눅스 마스터 1급
- Class
- Operator
- spring
- Reference Type
- OOP
- X.org
- Physical Scheme
- 백준
- BFS
- 자바
- Inheritance
- Mac
- selenium
- Unity
Archives
- Today
- Total
Byeol Lo
N10986 - 나머지 합 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.HashMap;
public class Main {
private static final BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
static final HashMap<Integer, Long> table = new HashMap<>();
public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(BR.readLine());
int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken());
long result = 0;
int[] arr = new int[n+1];
st = new StringTokenizer(BR.readLine());
for(int i = 1; i <= n; i++) {
arr[i] = (Integer.parseInt(st.nextToken()) + arr[i - 1]) % m;
if(!table.containsKey(arr[i])) table.put(arr[i], 1l);
else table.put(arr[i], table.get(arr[i])+1);
}
for(int i : table.keySet()) {
if(i == 0) result += (table.get(i)+1) * table.get(i) / 2;
else result += (table.get(i) - 1) * table.get(i) / 2;
}
System.out.println(result);
}
}
'Algorithm > Accumulated Sum' 카테고리의 다른 글
N25682 - 체스판 다시 칠하기 2 (1) | 2024.02.13 |
---|---|
N11660 - 구간 합 구하기 5 (1) | 2024.02.13 |
Comments