Skip to content

Commit 31de666

Browse files
authored
Update kilonova-ssdj.mdx
1 parent 33204ea commit 31de666

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

solutions/gold/kilonova-ssdj.mdx

+16-16
Original file line numberDiff line numberDiff line change
@@ -56,50 +56,50 @@ int main() {
5656
for (int i = 1; i <= n; i++) { lst2[n + 1][i] = n + 2; }
5757
for (char i = 'z'; i >= 'a'; i--) {
5858
for (int row = 1; row <= n; row++) {
59-
int cnt = 0;
59+
int stackSize = 0;
6060
for (int col = 1; col <= n; col++) {
6161
if (mat[row][col] >= i) {
6262
lst[row][col] = row;
6363
} else {
6464
lst[row][col] = lst[row - 1][col];
6565
}
66-
while (cnt && lst[row - 1][col] >= lst[row][d[cnt]]) { --cnt; }
66+
while (stackSize && lst[row - 1][col] >= lst[row][d[stackSize]]) { --stackSize; }
6767
if (mat[row][col] == i) {
68-
ans += cnt;
69-
if (cnt && d[1] == col) { --ans; }
68+
ans += stackSize;
69+
if (stackSize && d[1] == col) { --stackSize; }
7070
}
71-
while (cnt && lst[row][col] >= lst[row][d[cnt]]) { --cnt; }
71+
while (stackSize && lst[row][col] >= lst[row][d[stackSize]]) { --stackSize; }
7272
if (lst[row][col] <= (row - 1) && lst[row][col] != 0) {
73-
d[++cnt] = col;
73+
d[++stackSize] = col;
7474
}
7575
}
7676
}
7777

7878
for (int row = n; row >= 1; row--) {
79-
int cnt = 0;
79+
int stackSize = 0;
8080
int hm = 0;
8181
for (int col = n; col >= 1; col--) {
8282
if (mat[row][col] >= i) {
8383
lst2[row][col] = row;
8484
} else {
8585
lst2[row][col] = lst2[row + 1][col];
8686
}
87-
while (cnt && lst2[row + 1][col] <= lst2[row][d[cnt]]) {
88-
if (mat[lst2[row][d[cnt]]][d[cnt]] == i) { hm--; }
89-
cnt--;
87+
while (stackSize && lst2[row + 1][col] <= lst2[row][d[stackSize]]) {
88+
if (mat[lst2[row][d[stackSize]]][d[stackSize]] == i) { hm--; }
89+
stackSize--;
9090
}
9191
if (mat[row][col] == i) {
92-
ans += cnt;
92+
ans += stackSize;
9393
ans -= hm;
94-
if (cnt && d[cnt] == col) { ans--; }
94+
if (stackSize && d[stackSize] == col) { ans--; }
9595
}
96-
while (cnt && lst2[row][col] <= lst2[row][d[cnt]]) {
97-
if (mat[lst2[row][d[cnt]]][d[cnt]] == i) { hm--; }
98-
cnt--;
96+
while (stackSize && lst2[row][col] <= lst2[row][d[stackSize]]) {
97+
if (mat[lst2[row][d[stackSize]]][d[stackSize]] == i) { hm--; }
98+
stackSize--;
9999
}
100100
if (lst2[row][col] >= (row + 1) && lst2[row][col] != (n + 2)) {
101101
if (mat[lst2[row][col]][col] == i) { hm++; }
102-
d[++cnt] = col;
102+
d[++stackSize] = col;
103103
}
104104
}
105105
}

0 commit comments

Comments
 (0)