Skip to content

Commit 8c2ae1d

Browse files
committed
update
1 parent ca218cc commit 8c2ae1d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Time: 296 ms
2+
// Memory: 500 KB
3+
// .
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2106A_Dr_TC {
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(), count1 = 0, count0 = 0, ret = 0;
14+
String s = sc.next();
15+
for (char c : s.toCharArray()) {
16+
if (c == '1') {
17+
count1++;
18+
} else {
19+
count0++;
20+
}
21+
}
22+
ret = count1 * (n - 1) + count0;
23+
24+
System.out.println(ret);
25+
}
26+
}
27+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Time: 280 ms
2+
// Memory: 700 KB
3+
// .
4+
// T:O(sum(ni)), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2117A_False_Alarm {
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(), x = sc.nextInt(), firstCloseIndex = -1, lastCloseIndex = 0;
14+
for (int j = 0; j < n; j++) {
15+
int a = sc.nextInt();
16+
if (a == 1) {
17+
if (firstCloseIndex == -1) {
18+
firstCloseIndex = j;
19+
}
20+
lastCloseIndex = j;
21+
}
22+
}
23+
boolean ret = false;
24+
if (firstCloseIndex == -1) {
25+
ret = true;
26+
} else {
27+
ret = lastCloseIndex - firstCloseIndex < x;
28+
}
29+
30+
System.out.println(ret ? "YES" : "NO");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)