結果
| 問題 |
No.1525 Meximum Sum
|
| ユーザー |
tenten
|
| 提出日時 | 2021-05-31 18:34:58 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,637 bytes |
| コンパイル時間 | 2,449 ms |
| コンパイル使用メモリ | 78,408 KB |
| 実行使用メモリ | 83,092 KB |
| 最終ジャッジ日時 | 2024-11-08 21:19:57 |
| 合計ジャッジ時間 | 13,764 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 RE * 2 |
| other | AC * 1 WA * 12 RE * 10 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
TreeMap<Integer, HashSet<Integer>> map = new TreeMap<>();
for (int i = 0; i < m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
if (!map.containsKey(x)) {
map.put(x, new HashSet<>());
}
map.get(x).add(y);
}
HashSet<Integer> enable = new HashSet<>();
enable.add(n);
for (HashSet<Integer> exist : map.values()) {
HashSet<Integer> next = new HashSet<>();
for (int x : exist) {
if (enable.contains(x - 1) || enable.contains(x + 1)) {
next.add(x);
}
}
for (int x : exist) {
enable.remove(x);
}
enable.addAll(next);
}
System.out.println(enable.size());
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten