Skip to content

Commit 16c2961

Browse files
committed
update
1 parent 1c5772c commit 16c2961

7 files changed

+177
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: 249 ms
2+
// Memory: 600 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2033A_Sakurako_and_Kosuke {
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();
14+
System.out.println(n % 2 == 0 ? "Sakurako" : "Kosuke");
15+
}
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// AC: 265 ms
2+
// Memory: 400 KB
3+
// .
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2036A_Quintomania {
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(), prev = -1;
14+
boolean flag = true;
15+
for (int j = 0; j < n; j++) {
16+
int a = sc.nextInt(), diff = Math.abs(a - prev);
17+
if (j == 0) {
18+
prev = a;
19+
continue;
20+
}
21+
if (flag && (diff != 5 && diff != 7)) {
22+
flag = false;
23+
}
24+
prev = a;
25+
}
26+
27+
System.out.println(flag ? "YES" : "NO");
28+
}
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// AC: 1264 ms
2+
// Memory: 15900 KB
3+
// greedy.
4+
// T:O(sum(nilogni)), S:O(max(ni))
5+
//
6+
import java.util.ArrayList;
7+
import java.util.Collections;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Scanner;
11+
12+
public class Codeforces_2036B_Startup {
13+
public static void main(String[] args) {
14+
Scanner sc = new Scanner(System.in);
15+
int t = sc.nextInt();
16+
for (int i = 0; i < t; i++) {
17+
int n = sc.nextInt(), k = sc.nextInt(), ret = 0;
18+
HashMap<Integer, Integer> typeToCost = new HashMap<>();
19+
for (int j = 0; j < k; j++) {
20+
int b = sc.nextInt(), c = sc.nextInt();
21+
typeToCost.merge(b, c, Integer::sum);
22+
}
23+
List<Integer> costs = new ArrayList<>(typeToCost.values());
24+
Collections.sort(costs, Collections.reverseOrder());
25+
for (int j = 0; j < Math.min(n, costs.size()); j++) {
26+
ret += costs.get(j);
27+
}
28+
29+
System.out.println(ret);
30+
}
31+
}
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// AC: 296 ms
2+
// Memory: 0 KB
3+
// .
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.HashMap;
7+
import java.util.Scanner;
8+
9+
public class Codeforces_2037A_Twice {
10+
public static void main(String[] args) {
11+
Scanner sc = new Scanner(System.in);
12+
int t = sc.nextInt();
13+
for (int i = 0; i < t; i++) {
14+
int n = sc.nextInt(), ret = 0;
15+
HashMap<Integer, Integer> record = new HashMap<>();
16+
for (int j = 0; j < n; j++) {
17+
int a = sc.nextInt();
18+
record.merge(a, 1, Integer::sum);
19+
}
20+
for (int j : record.keySet()) {
21+
ret += record.get(j) / 2;
22+
}
23+
24+
System.out.println(ret);
25+
}
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: 312 ms
2+
// Memory: 500 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2044C_Hard_Problem {
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 m = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), ret = 0;
14+
ret = Math.min(m, a) + Math.min(m, b);
15+
ret = Math.min(2 * m, ret + c);
16+
17+
System.out.println(ret);
18+
}
19+
}
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// AC: 358 ms
2+
// Memory: 800 KB
3+
// .
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2050A_Line_Breaks {
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(), m = sc.nextInt(), curLen = 0, ret = 0;
14+
boolean flag = true;
15+
for (int j = 0; j < n; j++) {
16+
String s = sc.next();
17+
if (!flag) {
18+
continue;
19+
}
20+
if (curLen + s.length() <= m) {
21+
curLen += s.length();
22+
ret++;
23+
} else {
24+
flag = false;
25+
}
26+
}
27+
System.out.println(ret);
28+
}
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Runtime 0 ms Beats 100.00%
2+
// Memory 41.89 MB Beats 87.69%
3+
// .
4+
// T:O(1), S:O(n)
5+
//
6+
class Solution {
7+
public int countPartitions(int[] nums) {
8+
int sum = 0, cur = 0, ret = 0;
9+
for (int i : nums) {
10+
sum += i;
11+
}
12+
for (int i = 0; i < nums.length - 1; i++) {
13+
cur += nums[i];
14+
if ((sum - 2 * cur) % 2 == 0) {
15+
ret++;
16+
}
17+
}
18+
19+
return ret;
20+
}
21+
}

0 commit comments

Comments
 (0)