Skip to content

Commit fe9e0c1

Browse files
committed
update
1 parent 2a3d2d4 commit fe9e0c1

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Time: 921 ms
2+
// Memory: 14700 KB
3+
// Prefix sum | dp.
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_1915E_Romantic_Glasses {
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();
15+
HashMap<Long, Boolean> record = new HashMap<>();
16+
record.put(0L, true);
17+
long sumEven = 0, sumOdd = 0;
18+
boolean ret = false;
19+
for (int j = 0; j < n; j++) {
20+
int a = sc.nextInt();
21+
if (ret) {
22+
continue;
23+
}
24+
if ((j & 1) == 0) {
25+
sumOdd += a;
26+
} else {
27+
sumEven += a;
28+
}
29+
if (record.containsKey(sumOdd - sumEven)) {
30+
ret = true;
31+
}
32+
record.put(sumOdd - sumEven, true);
33+
}
34+
35+
System.out.println(ret ? "YES" : "NO");
36+
}
37+
}
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Runtime 5 ms Beats 100.00%
2+
// Memory 44.50 MB Beats 77.29%
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public String generateTag(String caption) {
8+
String[] arr = caption.trim().split(" ");
9+
StringBuilder ret = new StringBuilder();
10+
ret.append("#");
11+
for (int i = 0; i < arr.length; i++) {
12+
if (arr[i].trim().isEmpty()) {
13+
continue;
14+
}
15+
if (i == 0) {
16+
ret.append(String.valueOf(arr[i].charAt(0)).toLowerCase()).append(arr[i].substring(1).toLowerCase());
17+
} else {
18+
ret.append(String.valueOf(arr[i].charAt(0)).toUpperCase()).append(arr[i].substring(1).toLowerCase());
19+
}
20+
}
21+
22+
return ret.length() > 100 ? ret.substring(0, 100) : ret.toString();
23+
}
24+
}

0 commit comments

Comments
 (0)