-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCodeforces_0219A_k_String.java
More file actions
34 lines (32 loc) · 956 Bytes
/
Codeforces_0219A_k_String.java
File metadata and controls
34 lines (32 loc) · 956 Bytes
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
32
33
34
// AC: 374 ms
// Memory: 0 KB
// Hashtable
// T:O(n), S:O(n), n = s.length()
//
import java.util.HashMap;
import java.util.Scanner;
public class Codeforces_0219A_k_String {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
String s = sc.next();
if (k == 1) {
System.out.println(s);
return;
}
HashMap<Character, Integer> charCount = new HashMap<>();
for (char c : s.toCharArray()) {
charCount.merge(c, 1, Integer::sum);
}
StringBuilder ret = new StringBuilder();
for (char c : charCount.keySet()) {
int time = charCount.get(c);
if (time % k != 0) {
System.out.println(-1);
return;
}
ret.append(String.valueOf(c).repeat(time / k));
}
System.out.println(ret.toString().repeat(k));
}
}