Submission #1608119
Source Code Expand
import java.util.HashMap; import java.util.Scanner; import java.util.StringJoiner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); StringJoiner sj = new StringJoiner("\n"); for (int i = 0; i < 2; i ++) { sj.add(scanner.nextLine()); } System.out.println(solve(sj.toString())); } private static int solve(String stdinString) { String[] splits = stdinString.split("\n"); int N = Integer.parseInt(splits[0]); int[] nums = new int[N]; splits = splits[1].split(" "); for (int i = 0; i < N; i ++) { nums[i] = Integer.parseInt(splits[i]); } int max = Integer.MIN_VALUE; HashMap<Integer, Integer> xCounts = new HashMap<>(); for (int i = 0; i < N; i ++) { xCounts.put(nums[i] - 1, xCounts.getOrDefault(nums[i] - 1, 0) + 1); max = Math.max(max, xCounts.get(nums[i] - 1)); xCounts.put(nums[i], xCounts.getOrDefault(nums[i], 0) + 1); max = Math.max(max, xCounts.get(nums[i])); xCounts.put(nums[i] + 1, xCounts.getOrDefault(nums[i] + 1, 0) + 1); max = Math.max(max, xCounts.get(nums[i] + 1)); } return max; } private static String ex1 = "7\n3 1 4 1 5 9 2"; private static String ex2 = "10\n0 1 2 3 4 5 6 7 8 9"; private static String ex3 = "1\n99999"; private static void tests() { System.out.println(solve(ex1)); System.out.println(solve(ex2)); System.out.println(solve(ex3)); } }
Submission Info
Submission Time | |
---|---|
Task | C - Together |
User | gavotte |
Language | Java8 (OpenJDK 1.8.0) |
Score | 300 |
Code Size | 1668 Byte |
Status | AC |
Exec Time | 404 ms |
Memory | 51988 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 92 ms | 19028 KB |
0_001.txt | AC | 92 ms | 20560 KB |
0_002.txt | AC | 92 ms | 21844 KB |
1_003.txt | AC | 91 ms | 19796 KB |
1_004.txt | AC | 296 ms | 42592 KB |
1_005.txt | AC | 374 ms | 50768 KB |
1_006.txt | AC | 375 ms | 49152 KB |
1_007.txt | AC | 369 ms | 48140 KB |
1_008.txt | AC | 404 ms | 51988 KB |