Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-mong3125 #17

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions mong3125/μˆ˜ν•™/BOJ10986.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ10986 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

st = new StringTokenizer(br.readLine());
int[] remainders = new int[N + 1]; // λΆ€λΆ„ 합을 M으둜 λ‚˜λˆˆ 리슀트
int[] remainders_count = new int[M]; // λ‚˜λ¨Έμ§€ 개수
for (int i = 1; i <= N; i++) {
remainders[i] = (remainders[i - 1] + Integer.parseInt(st.nextToken())) % M;
remainders_count[remainders[i]] += 1;
Comment on lines +18 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쒋은 μ½”λ“œμΈ 것 κ°™μŠ΅λ‹ˆλ‹€

}

long count = 0;
for (int i = 0; i < M; i++) {
count += (long) remainders_count[i] * (remainders_count[i] - 1) / 2; // μ‘°ν•©
}
Comment on lines +23 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쑰합을 ν•œλ‹€κ³  ν•˜μ…¨λŠ”λ° μ–΄λ–€ μ›λ¦¬λ‘œ 쑰합을 ν•˜λŠ”κ±΄μ§€ 이 뢀뢄은 잘 이해가 가지 μ•Šλ„€μš”.
ꡬ간 ν•©μ˜ λ‚˜λ¨Έμ§€μΈ 1~M이 λ‚˜μ˜¨ 횟수λ₯Ό μ΄μš©ν•˜μ—¬ κ΅¬ν•œ 것 같은데 λΆ€μ—° μ„€λͺ…이 ν•„μš”ν•  것 κ°™μŠ΅λ‹ˆλ‹€.


count += remainders_count[0]; // λ‚˜λ¨Έμ§€κ°€ 0μΌλ•Œ (i = j μΌλ•Œ)

System.out.println(count);
}
}