Skip to content

Commit f749ae6

Browse files
committed
update
1 parent d7475cc commit f749ae6

7 files changed

+187
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// AC: 311 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_1877A_Goals_of_Victory {
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(), sum = 0;
14+
for (int j = 0; j < n - 1; j++) {
15+
sum += sc.nextInt();
16+
}
17+
System.out.println(-sum);
18+
}
19+
}
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// AC: 358 ms
2+
// Memory: 900 KB
3+
// Just assure the first element is the smallest of the permutation.
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1896A_Jagged_Swaps {
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(), start = 0;
14+
boolean flag = true;
15+
for (int j = 0; j < n; j++) {
16+
int a = sc.nextInt();
17+
if (!flag) {
18+
continue;
19+
}
20+
if (j == 0) {
21+
start = a;
22+
} else {
23+
if (a < start) {
24+
flag = false;
25+
}
26+
}
27+
}
28+
29+
System.out.println(flag ? "YES" : "NO");
30+
}
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// AC: 296 ms
2+
// Memory: 900 KB
3+
// .
4+
// T:O(sum(ni)), S:O(max(ni))
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1900A_Cover_in_Water {
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 = 0;
14+
String s = sc.next();
15+
if (s.contains("...")) {
16+
ret = 2;
17+
} else {
18+
for (char c : s.toCharArray()) {
19+
if (c == '.') {
20+
ret++;
21+
}
22+
}
23+
}
24+
25+
System.out.println(ret);
26+
}
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// AC: 327 ms
2+
// Memory: 800 K
3+
// .
4+
// T:O(t), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_1913A_Rating_Increase {
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 s = sc.next();
14+
int len = s.length(), a = 0, b = 0;
15+
for (int j = 1; j <= len / 2; j++) {
16+
if (s.charAt(j) == '0') {
17+
continue;
18+
}
19+
int a1 = Integer.parseInt(s.substring(0, j)), b1 = Integer.parseInt(s.substring(j));
20+
if (b1 > a1) {
21+
b = b1;
22+
a = a1;
23+
break;
24+
}
25+
}
26+
27+
System.out.println(a == 0 ? -1 : (a + " " + b));
28+
}
29+
}
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Runtime 0 ms Beats 100.00%
2+
// Memory 40.63 MB Beats 100.00%
3+
// .
4+
// T:O(1), S:O(1)
5+
//
6+
class Solution {
7+
public int smallestNumber(int n, int t) {
8+
int ret = 0, digitProduct = 1, n2 = n / 10;
9+
while (n2 > 0) {
10+
digitProduct *= n2 % 10;
11+
n2 /= 10;
12+
}
13+
for (int i = n; i <= (n / 10 * 10 + 10); i++) {
14+
if ((digitProduct * (i % 10)) % t == 0) {
15+
ret = i;
16+
break;
17+
}
18+
}
19+
20+
return ret;
21+
}
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Runtime 1 ms Beats 100.00%
2+
// Memory 44.36 MB Beats 100.00%
3+
// Array.
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
8+
if (k == 1) {
9+
return true;
10+
}
11+
int len = nums.size(), cur = 1, prevIncrLen = 0;
12+
for (int i = 1; i < len; i++) {
13+
if (nums.get(i) > nums.get(i - 1)) {
14+
cur++;
15+
if (cur >= 2 * k || (cur >= k && prevIncrLen >= k)) {
16+
return true;
17+
}
18+
} else {
19+
if (cur >= k && prevIncrLen >= k) {
20+
return true;
21+
}
22+
prevIncrLen = cur;
23+
cur = 1;
24+
}
25+
}
26+
27+
return false;
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Runtime 14 ms Beats 100.00%
2+
// Memory 88.69 MB Beats 66.67%
3+
// Array. Same as: Leetcode 3349.
4+
// T:O(n), S:O(1)
5+
//
6+
class Solution {
7+
public int maxIncreasingSubarrays(List<Integer> nums) {
8+
int len = nums.size(), k = 1;
9+
if (len == 2) {
10+
return k;
11+
}
12+
int cur = 1, prevIncrLen = 0;
13+
for (int i = 1; i < len; i++) {
14+
if (nums.get(i) > nums.get(i - 1)) {
15+
cur++;
16+
k = Math.max(k, cur / 2);
17+
} else {
18+
prevIncrLen = cur;
19+
cur = 1;
20+
}
21+
k = Math.max(k, Math.min(prevIncrLen, cur));
22+
}
23+
24+
return k;
25+
}
26+
}

0 commit comments

Comments
 (0)