Skip to content

Commit 73b5023

Browse files
committed
update
1 parent 81759de commit 73b5023

7 files changed

+184
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// AC: 528 ms
2+
// Memory: 0 KB
3+
// Hashmap.
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.HashMap;
7+
import java.util.HashSet;
8+
import java.util.LinkedList;
9+
import java.util.List;
10+
import java.util.Scanner;
11+
12+
public class Codeforces_0002A_Winner {
13+
public static void main(String[] args) {
14+
Scanner sc = new Scanner(System.in);
15+
int t = sc.nextInt(), maxScore = 0;
16+
HashMap<String, Integer> nameSore = new HashMap<>();
17+
List<String> record = new LinkedList<>();
18+
for (int i = 0; i < t; i++) {
19+
String name = sc.next();
20+
int score = sc.nextInt();
21+
nameSore.merge(name, score, Integer::sum);
22+
record.add(name + "#" + score);
23+
}
24+
for (String key : nameSore.keySet()) {
25+
maxScore = Math.max(maxScore, nameSore.get(key));
26+
}
27+
HashSet<String> names = new HashSet<>();
28+
for (String key : nameSore.keySet()) {
29+
if (nameSore.get(key).equals(maxScore)) {
30+
names.add(key);
31+
}
32+
}
33+
nameSore.clear();
34+
for (String item : record) {
35+
String[] arr = item.split("#");
36+
String name = arr[0];
37+
int score = Integer.parseInt(arr[1]);
38+
nameSore.merge(name, score, Integer::sum);
39+
if (nameSore.get(name) >= maxScore && names.contains(name)) {
40+
System.out.println(name);
41+
return;
42+
}
43+
}
44+
}
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// AC: 560 ms
2+
// Memory: 100 KB
3+
// Math theory: If 5555... can be devide by 9, then the number of 5's is also divided by 9.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_0352A_Jeff_and_Digits {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt(), countZero = 0, countFive = 0;
12+
for (int i = 0; i < t; i++) {
13+
int a = sc.nextInt();
14+
if (a == 0) {
15+
countZero++;
16+
} else if (a == 5) {
17+
countFive++;
18+
}
19+
}
20+
if (countZero > 0) {
21+
if (countFive >= 9) {
22+
String ret = "5".repeat(countFive / 9 * 9) + "0".repeat(countZero);
23+
System.out.println(ret);
24+
} else {
25+
System.out.println(0);
26+
}
27+
} else {
28+
System.out.println(-1);
29+
}
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// AC: 202 ms
2+
// Memory: 0 KB
3+
// Just find first K elements missing how many elements in permutation [1...k]
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1712A_Wonderful_Permutation {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt(), maxScore = 0;
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), k = sc.nextInt(), countOneToK = 0;
14+
for (int j = 0; j < n; j++) {
15+
int p = sc.nextInt();
16+
if (j < k && p <= k) {
17+
countOneToK++;
18+
}
19+
}
20+
System.out.println(k - countOneToK);
21+
}
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// AC: 420 ms
2+
// Memory: 0 KB
3+
// Calculate range.
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1878C_Vasilije_in_Cacak {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int n = sc.nextInt(), k = sc.nextInt();
14+
long x = sc.nextLong();
15+
long minSum = (long) (1 + k) * k / 2, maxSum = (long) (n + n - k + 1) * k / 2;
16+
System.out.println((x >= minSum && x <= maxSum) ? "YES" : "NO");
17+
}
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// AC: 186 ms
2+
// Memory: 24700 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1915A_Odd_One_Out {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), ret = a;
14+
if (b != c) {
15+
ret = a == c ? b : c;
16+
}
17+
System.out.println(ret);
18+
}
19+
}
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// AC: 171 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1915B_Not_Quite_Latin_Square {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
char ret = ' ';
14+
for (int j = 0; j < 3; j++) {
15+
String row = sc.next();
16+
if (row.contains("?")) {
17+
int sum = 0;
18+
for (char c : row.toCharArray()) {
19+
if (c != '?') {
20+
sum += c;
21+
}
22+
}
23+
ret = (char) ('A' + 'B' + 'C' - sum);
24+
}
25+
}
26+
System.out.println(ret);
27+
}
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// AC: Runtime 2 ms Beats 100.00% of users with Java
2+
// Memory 44.80 MB Beats 66.67% of users with Java
3+
// .
4+
// T:O(nlogn), S:O(logn)
5+
//
6+
class Solution {
7+
public int[] numberGame(int[] nums) {
8+
Arrays.sort(nums);
9+
int[] ret = new int[nums.length];
10+
for (int i = 0; i < nums.length / 2; i++) {
11+
ret[2 * i] = nums[2 * i + 1];
12+
ret[2 * i + 1] = nums[2 * i];
13+
}
14+
15+
return ret;
16+
}
17+
}

0 commit comments

Comments
 (0)