Skip to content

Commit 96bf6c7

Browse files
committed
update
1 parent 78b51dd commit 96bf6c7

7 files changed

+143
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// AC: 406 ms
2+
// Memory: 1000 KB
3+
// Greedy, implementation.
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1979A_Guess_the_Maximum {
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(), ret = Integer.MAX_VALUE, prev = -1;
14+
for (int j = 0; j < n; j++) {
15+
int a = sc.nextInt();
16+
if (prev == -1) {
17+
prev = a;
18+
continue;
19+
}
20+
int tempMax = Math.max(a, prev);
21+
ret = Math.min(ret, tempMax);
22+
prev = a;
23+
}
24+
25+
System.out.println(ret - 1);
26+
}
27+
}
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// AC: 234 ms
2+
// Memory: 900 KB
3+
// Constructive.
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1983A_Array_Divisibility {
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+
StringBuilder ret = new StringBuilder();
15+
for (int j = 0; j < n; j++) {
16+
ret.append(j + 1);
17+
if (j != n - 1) {
18+
ret.append(" ");
19+
}
20+
}
21+
22+
System.out.println(ret);
23+
}
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// AC: 249 ms
2+
// Memory: 1200 KB
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1985A_Creating_Words {
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+
String a = sc.next(), b = sc.next();
14+
15+
System.out.println(b.charAt(0) + a.substring(1, 3) + " " + a.charAt(0) + b.substring(1, 3));
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// AC: 358 ms
2+
// Memory: 300 KB
3+
// .
4+
// T:O(n), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1989A_Catch_the_Coin {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt();
12+
for (int i = 0; i < n; i++) {
13+
int x = sc.nextInt(), y = sc.nextInt();
14+
15+
System.out.println(y >= -1 ? "YES" : "NO");
16+
}
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Runtime 1 ms Beats 100.00%
2+
// Memory 40.91 MB Beats 100.00%
3+
// .
4+
// T:O(logn), S:O(1)
5+
//
6+
class Solution {
7+
public int generateKey(int num1, int num2, int num3) {
8+
int ret = 0, base = 1;
9+
while (num1 > 0 || num2 > 0 || num3 > 0) {
10+
int digit1 = num1 > 0 ? num1 % 10 : 0, digit2 = num2 > 0 ? num2 % 10 : 0, digit3 = num3 > 0 ? num3 % 10 : 0;
11+
ret += Math.min(digit1, Math.min(digit2, digit3)) * base;
12+
base *= 10;
13+
num1 /= 10;
14+
num2 /= 10;
15+
num3 /= 10;
16+
}
17+
18+
return ret;
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Runtime 2 ms Beats 100.00%
2+
// Memory 44.45 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(n / k)
5+
//
6+
class Solution {
7+
public String stringHash(String s, int k) {
8+
StringBuilder ret = new StringBuilder();
9+
int len = s.length(), gap = len / k;
10+
for (int i = 0; i < gap; i++) {
11+
int count = 0;
12+
for (int j = k * i; j < k * i + k; j++) {
13+
count += s.charAt(j) - 'a';
14+
}
15+
count %= 26;
16+
ret.append((char) ('a' + count));
17+
}
18+
19+
return ret.toString();
20+
}
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Runtime 0 ms Beats 100.00%
2+
// Memory 41.46 MB Beats 100.00%
3+
// .
4+
// T:O(1), S:O(1)
5+
//
6+
class Solution {
7+
public boolean checkTwoChessboards(String coordinate1, String coordinate2) {
8+
int c1 = coordinate1.charAt(0) - 'a', c2 = coordinate1.charAt(1) - '1', c3 = coordinate2.charAt(0) - 'a',
9+
c4 = coordinate2.charAt(1) - '1';
10+
int diff1 = Math.abs(c1 - c3), diff2 = Math.abs(c2 - c4);
11+
return Math.abs(diff1 - diff2) % 2 == 0;
12+
}
13+
}

0 commit comments

Comments
 (0)