Submission #24376419
Source Code Expand
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] c = new int[n];
for(int i = 0; i < n; i++){
c[i] = sc.nextInt();
}
sc.close();
HashMap<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < k; i++){
map.put(c[i], map.getOrDefault(c[i], 0) + 1);
}
int ans = map.size();
for(int i = k; i < n; i++){
map.put(c[i-k], map.get(c[i-k])-1);
if(map.get(c[i-k]) == 0){
map.remove(c[i-k]);
}
map.put(c[i], map.getOrDefault(c[i], 0) + 1);
ans = Math.max(ans, map.size());
}
System.out.println(ans);
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Colorful Candies |
| User | T6XECZ |
| Language | Java (OpenJDK 11.0.6) |
| Score | 300 |
| Code Size | 860 Byte |
| Status | AC |
| Exec Time | 819 ms |
| Memory | 66240 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 122 ms | 35492 KiB |
| 001.txt | AC | 759 ms | 60908 KiB |
| 002.txt | AC | 709 ms | 61180 KiB |
| 003.txt | AC | 720 ms | 60600 KiB |
| 004.txt | AC | 757 ms | 61220 KiB |
| 005.txt | AC | 713 ms | 64028 KiB |
| 006.txt | AC | 682 ms | 59392 KiB |
| 007.txt | AC | 672 ms | 60796 KiB |
| 008.txt | AC | 776 ms | 62960 KiB |
| 009.txt | AC | 819 ms | 65504 KiB |
| 010.txt | AC | 793 ms | 66240 KiB |
| 011.txt | AC | 814 ms | 64748 KiB |
| 012.txt | AC | 679 ms | 60456 KiB |
| 013.txt | AC | 738 ms | 60796 KiB |
| 014.txt | AC | 699 ms | 60568 KiB |
| 015.txt | AC | 715 ms | 60776 KiB |
| 016.txt | AC | 607 ms | 63180 KiB |
| 017.txt | AC | 497 ms | 57592 KiB |
| 018.txt | AC | 506 ms | 57000 KiB |
| 019.txt | AC | 629 ms | 58868 KiB |
| 020.txt | AC | 638 ms | 60164 KiB |
| example0.txt | AC | 117 ms | 35484 KiB |
| example1.txt | AC | 108 ms | 35404 KiB |
| example2.txt | AC | 106 ms | 35660 KiB |