id
int64 0
14.1k
| problem_id
int64 1
1.31k
| problem_title
stringclasses 441
values | difficulty
stringclasses 3
values | c_source
stringclasses 441
values | architecture
stringclasses 4
values | optimization
stringclasses 4
values | compiler
stringclasses 8
values | assembly
stringlengths 31
174k
|
|---|---|---|---|---|---|---|---|---|
13,900
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
mips64
|
-O0
|
mips64 gcc 15.2.0
|
brokenCalc:
daddiu $sp,$sp,-48
sd $fp,40($sp)
move $fp,$sp
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,16($fp)
sll $2,$2,0
sw $2,20($fp)
sw $0,0($fp)
b .L2
nop
.L5:
lw $2,20($fp)
andi $2,$2,0x1
beq $2,$0,.L3
nop
lw $2,20($fp)
addiu $2,$2,1
sw $2,20($fp)
b .L4
nop
.L3:
lw $2,20($fp)
srl $3,$2,31
addu $2,$3,$2
sra $2,$2,1
sw $2,20($fp)
.L4:
lw $2,0($fp)
addiu $2,$2,1
sw $2,0($fp)
.L2:
lw $3,16($fp)
lw $2,20($fp)
slt $2,$3,$2
bne $2,$0,.L5
nop
lw $3,16($fp)
lw $2,20($fp)
subu $2,$3,$2
lw $3,0($fp)
addu $2,$3,$2
sw $2,0($fp)
lw $2,0($fp)
move $sp,$fp
ld $fp,40($sp)
daddiu $sp,$sp,48
jr $31
nop
.LC0:
.ascii "Usage: ./test x y\000"
.LC1:
.ascii "%d\012\000"
main:
daddiu $sp,$sp,-64
sd $31,56($sp)
sd $fp,48($sp)
sd $28,40($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
move $2,$4
sd $5,24($fp)
sll $2,$2,0
sw $2,16($fp)
lw $2,16($fp)
li $3,3 # 0x3
beq $2,$3,.L8
nop
ld $2,%got_disp(stderr)($28)
ld $2,0($2)
move $7,$2
li $6,17 # 0x11
li $5,1 # 0x1
ld $2,%got_page(.LC0)($28)
daddiu $4,$2,%got_ofst(.LC0)
ld $2,%call16(fwrite)($28)
mtlo $2
mflo $25
jalr $25
nop
li $4,-1 # 0xffffffffffffffff
ld $2,%call16(exit)($28)
mtlo $2
mflo $25
jalr $25
nop
.L8:
ld $2,24($fp)
daddiu $2,$2,8
ld $2,0($2)
move $4,$2
ld $2,%call16(atoi)($28)
mtlo $2
mflo $25
jalr $25
nop
sw $2,0($fp)
ld $2,24($fp)
daddiu $2,$2,16
ld $2,0($2)
move $4,$2
ld $2,%call16(atoi)($28)
mtlo $2
mflo $25
jalr $25
nop
sw $2,4($fp)
lw $3,4($fp)
lw $2,0($fp)
move $5,$3
move $4,$2
ld $2,%got_disp(brokenCalc)($28)
mtlo $2
mflo $25
jalr $25
nop
move $5,$2
ld $2,%got_page(.LC1)($28)
daddiu $4,$2,%got_ofst(.LC1)
ld $2,%call16(printf)($28)
mtlo $2
mflo $25
jalr $25
nop
move $2,$0
move $sp,$fp
ld $31,56($sp)
ld $fp,48($sp)
ld $28,40($sp)
daddiu $sp,$sp,64
jr $31
nop
|
13,901
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
mips64
|
-O1
|
mips64 gcc 15.2.0
|
brokenCalc:
slt $2,$4,$5
beq $2,$0,.L6
move $3,$0
b .L9
andi $6,$5,0x1
.L3:
addu $5,$2,$5
sra $5,$5,1
.L4:
slt $6,$4,$5
beq $6,$0,.L2
addiu $3,$3,1
andi $6,$5,0x1
.L9:
beq $6,$0,.L3
srl $2,$5,31
b .L4
addiu $5,$5,1
.L6:
.L2:
subu $2,$4,$5
jr $31
addu $2,$2,$3
.LC0:
.ascii "Usage: ./test x y\000"
.LC1:
.ascii "%d\012\000"
main:
daddiu $sp,$sp,-32
sd $31,24($sp)
sd $28,16($sp)
sd $17,8($sp)
sd $16,0($sp)
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
li $2,3 # 0x3
bne $2,$4,.L13
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
move $16,$5
li $6,10 # 0xa
move $5,$0
ld $25,%call16(strtol)($28)
1: jalr $25
ld $4,8($16)
move $17,$2
li $6,10 # 0xa
move $5,$0
ld $25,%call16(strtol)($28)
1: jalr $25
ld $4,16($16)
sll $5,$2,0
ld $25,%got_disp(brokenCalc)($28)
1: jalr $25
sll $4,$17,0
move $5,$2
ld $4,%got_page(.LC1)($28)
ld $25,%call16(printf)($28)
1: jalr $25
daddiu $4,$4,%got_ofst(.LC1)
move $2,$0
ld $31,24($sp)
ld $28,16($sp)
ld $17,8($sp)
ld $16,0($sp)
jr $31
daddiu $sp,$sp,32
.L13:
ld $2,%got_disp(stderr)($28)
ld $7,0($2)
li $6,17 # 0x11
li $5,1 # 0x1
ld $4,%got_page(.LC0)($28)
ld $25,%call16(fwrite)($28)
1: jalr $25
daddiu $4,$4,%got_ofst(.LC0)
ld $25,%call16(exit)($28)
1: jalr $25
li $4,-1 # 0xffffffffffffffff
|
13,902
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
mips64
|
-O2
|
mips64 gcc 15.2.0
|
brokenCalc:
slt $2,$4,$5
beq $2,$0,.L2
move $7,$0
.L5:
srl $3,$5,31
andi $6,$5,0x1
addu $3,$3,$5
bne $6,$0,.L4
addiu $5,$5,1
sra $5,$3,1
.L4:
slt $3,$4,$5
bne $3,$0,.L5
addiu $7,$7,1
.L2:
subu $2,$4,$5
jr $31
addu $2,$2,$7
.LC0:
.ascii "Usage: ./test x y\000"
.LC1:
.ascii "%d\012\000"
main:
daddiu $sp,$sp,-32
sd $28,16($sp)
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
li $2,3 # 0x3
sd $31,24($sp)
sd $16,8($sp)
bne $2,$4,.L19
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
ld $4,8($5)
ld $25,%call16(strtol)($28)
move $16,$5
li $6,10 # 0xa
1: jalr $25
move $5,$0
ld $4,16($16)
ld $25,%call16(strtol)($28)
li $6,10 # 0xa
move $5,$0
1: jalr $25
sll $16,$2,0
sll $2,$2,0
slt $3,$16,$2
bne $3,$0,.L15
move $4,$0
b .L21
subu $5,$16,$2
.L20:
slt $3,$16,$2
beq $3,$0,.L12
addiu $4,$4,1
.L15:
andi $3,$2,0x1
bnel $3,$0,.L20
addiu $2,$2,1
srl $3,$2,31
addu $2,$3,$2
sra $2,$2,1
slt $3,$16,$2
bne $3,$0,.L15
addiu $4,$4,1
.L12:
subu $5,$16,$2
.L21:
addu $5,$5,$4
ld $4,%got_page(.LC1)($28)
ld $25,%call16(printf)($28)
1: jalr $25
daddiu $4,$4,%got_ofst(.LC1)
ld $31,24($sp)
ld $28,16($sp)
ld $16,8($sp)
move $2,$0
jr $31
daddiu $sp,$sp,32
.L19:
ld $2,%got_disp(stderr)($28)
ld $4,%got_page(.LC0)($28)
ld $25,%call16(fwrite)($28)
ld $7,0($2)
daddiu $4,$4,%got_ofst(.LC0)
li $6,17 # 0x11
1: jalr $25
li $5,1 # 0x1
ld $25,%call16(exit)($28)
1: jalr $25
li $4,-1 # 0xffffffffffffffff
|
13,903
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
mips64
|
-O3
|
mips64 gcc 15.2.0
|
brokenCalc:
slt $2,$4,$5
beq $2,$0,.L2
move $7,$0
.L5:
srl $3,$5,31
andi $6,$5,0x1
addu $3,$3,$5
bne $6,$0,.L4
addiu $5,$5,1
sra $5,$3,1
.L4:
slt $3,$4,$5
bne $3,$0,.L5
addiu $7,$7,1
.L2:
subu $2,$4,$5
jr $31
addu $2,$2,$7
.LC0:
.ascii "Usage: ./test x y\000"
.LC1:
.ascii "%d\012\000"
main:
daddiu $sp,$sp,-32
sd $28,16($sp)
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
li $2,3 # 0x3
sd $31,24($sp)
sd $16,8($sp)
bne $2,$4,.L19
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
ld $4,8($5)
ld $25,%call16(strtol)($28)
move $16,$5
li $6,10 # 0xa
1: jalr $25
move $5,$0
ld $4,16($16)
ld $25,%call16(strtol)($28)
li $6,10 # 0xa
move $5,$0
1: jalr $25
sll $16,$2,0
sll $2,$2,0
slt $3,$16,$2
bne $3,$0,.L15
move $4,$0
b .L21
subu $5,$16,$2
.L20:
slt $3,$16,$2
beq $3,$0,.L12
addiu $4,$4,1
.L15:
andi $3,$2,0x1
bnel $3,$0,.L20
addiu $2,$2,1
srl $3,$2,31
addu $2,$3,$2
sra $2,$2,1
slt $3,$16,$2
bne $3,$0,.L15
addiu $4,$4,1
.L12:
subu $5,$16,$2
.L21:
addu $5,$5,$4
ld $4,%got_page(.LC1)($28)
ld $25,%call16(printf)($28)
1: jalr $25
daddiu $4,$4,%got_ofst(.LC1)
ld $31,24($sp)
ld $28,16($sp)
ld $16,8($sp)
move $2,$0
jr $31
daddiu $sp,$sp,32
.L19:
ld $2,%got_disp(stderr)($28)
ld $4,%got_page(.LC0)($28)
ld $25,%call16(fwrite)($28)
ld $7,0($2)
daddiu $4,$4,%got_ofst(.LC0)
li $6,17 # 0x11
1: jalr $25
li $5,1 # 0x1
ld $25,%call16(exit)($28)
1: jalr $25
li $4,-1 # 0xffffffffffffffff
|
13,904
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O0
|
RISC-V 64 clang 21.1.0
|
brokenCalc:
addi sp, sp, -48
sd ra, 40(sp)
sd s0, 32(sp)
addi s0, sp, 48
sw a0, -20(s0)
sw a1, -24(s0)
li a0, 0
sw a0, -28(s0)
j .LBB0_1
.LBB0_1:
lw a0, -20(s0)
lw a1, -24(s0)
bge a0, a1, .LBB0_6
j .LBB0_2
.LBB0_2:
lbu a0, -24(s0)
andi a0, a0, 1
beqz a0, .LBB0_4
j .LBB0_3
.LBB0_3:
lw a0, -24(s0)
addiw a0, a0, 1
sd a0, -40(s0)
j .LBB0_5
.LBB0_4:
lw a0, -24(s0)
srliw a1, a0, 31
addw a0, a0, a1
sraiw a0, a0, 1
sd a0, -40(s0)
j .LBB0_5
.LBB0_5:
ld a0, -40(s0)
sw a0, -24(s0)
lw a0, -28(s0)
addiw a0, a0, 1
sw a0, -28(s0)
j .LBB0_1
.LBB0_6:
lw a0, -20(s0)
lw a1, -24(s0)
subw a1, a0, a1
lw a0, -28(s0)
addw a0, a0, a1
sw a0, -28(s0)
lw a0, -28(s0)
ld ra, 40(sp)
ld s0, 32(sp)
addi sp, sp, 48
ret
main:
addi sp, sp, -48
sd ra, 40(sp)
sd s0, 32(sp)
addi s0, sp, 48
li a2, 0
sw a2, -20(s0)
sw a0, -24(s0)
sd a1, -32(s0)
lw a0, -24(s0)
li a1, 3
beq a0, a1, .LBB1_2
j .LBB1_1
.LBB1_1:
.Lpcrel_hi0:
auipc a0, %got_pcrel_hi(stderr)
ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
ld a0, 0(a0)
.Lpcrel_hi1:
auipc a1, %pcrel_hi(.L.str)
addi a1, a1, %pcrel_lo(.Lpcrel_hi1)
call fprintf
li a0, -1
call exit
.LBB1_2:
ld a0, -32(s0)
ld a0, 8(a0)
call atoi
sw a0, -36(s0)
ld a0, -32(s0)
ld a0, 16(a0)
call atoi
sw a0, -40(s0)
lw a0, -36(s0)
lw a1, -40(s0)
call brokenCalc
mv a1, a0
.Lpcrel_hi2:
auipc a0, %pcrel_hi(.L.str.1)
addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
call printf
li a0, 0
ld ra, 40(sp)
ld s0, 32(sp)
addi sp, sp, 48
ret
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,905
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O1
|
RISC-V 64 clang 21.1.0
|
brokenCalc:
li a2, 0
blt a0, a1, .LBB0_2
j .LBB0_4
.LBB0_1:
addiw a1, a1, 1
addi a2, a2, 1
bge a0, a1, .LBB0_4
.LBB0_2:
andi a3, a1, 1
bnez a3, .LBB0_1
sraiw a1, a1, 1
addi a2, a2, 1
blt a0, a1, .LBB0_2
.LBB0_4:
subw a0, a0, a1
addw a0, a0, a2
ret
main:
addi sp, sp, -32
sd ra, 24(sp)
sd s0, 16(sp)
sd s1, 8(sp)
mv s0, a1
li a1, 3
bne a0, a1, .LBB1_7
ld a0, 8(s0)
li a2, 10
li a1, 0
call strtol
ld a1, 16(s0)
mv s0, a0
sext.w s1, a0
li a2, 10
mv a0, a1
li a1, 0
call strtol
sext.w a1, a0
li a2, 0
bge s1, a1, .LBB1_6
li a2, 0
mv a1, a0
j .LBB1_4
.LBB1_3:
addiw a1, a1, 1
addi a2, a2, 1
bge s1, a1, .LBB1_6
.LBB1_4:
andi a0, a1, 1
bnez a0, .LBB1_3
sraiw a1, a1, 1
addi a2, a2, 1
blt s1, a1, .LBB1_4
.LBB1_6:
add a2, a2, s0
subw a1, a2, a1
.Lpcrel_hi2:
auipc a0, %pcrel_hi(.L.str.1)
addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
call printf
li a0, 0
ld ra, 24(sp)
ld s0, 16(sp)
ld s1, 8(sp)
addi sp, sp, 32
ret
.LBB1_7:
.Lpcrel_hi0:
auipc a0, %got_pcrel_hi(stderr)
ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
ld a3, 0(a0)
.Lpcrel_hi1:
auipc a0, %pcrel_hi(.L.str)
li a1, 17
addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
li a2, 1
call fwrite
li a0, -1
call exit
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,906
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O2
|
RISC-V 64 clang 21.1.0
|
brokenCalc:
li a2, 0
blt a0, a1, .LBB0_2
j .LBB0_4
.LBB0_1:
addiw a1, a1, 1
addi a2, a2, 1
bge a0, a1, .LBB0_4
.LBB0_2:
andi a3, a1, 1
bnez a3, .LBB0_1
sraiw a1, a1, 1
addi a2, a2, 1
blt a0, a1, .LBB0_2
.LBB0_4:
subw a0, a0, a1
addw a0, a0, a2
ret
main:
addi sp, sp, -32
sd ra, 24(sp)
sd s0, 16(sp)
sd s1, 8(sp)
mv s0, a1
li a1, 3
bne a0, a1, .LBB1_7
ld a0, 8(s0)
li a2, 10
li a1, 0
call strtol
ld a1, 16(s0)
mv s0, a0
sext.w s1, a0
li a2, 10
mv a0, a1
li a1, 0
call strtol
sext.w a1, a0
li a2, 0
bge s1, a1, .LBB1_6
li a2, 0
mv a1, a0
j .LBB1_4
.LBB1_3:
addiw a1, a1, 1
addi a2, a2, 1
bge s1, a1, .LBB1_6
.LBB1_4:
andi a0, a1, 1
bnez a0, .LBB1_3
sraiw a1, a1, 1
addi a2, a2, 1
blt s1, a1, .LBB1_4
.LBB1_6:
add a2, a2, s0
subw a1, a2, a1
.Lpcrel_hi2:
auipc a0, %pcrel_hi(.L.str.1)
addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
call printf
li a0, 0
ld ra, 24(sp)
ld s0, 16(sp)
ld s1, 8(sp)
addi sp, sp, 32
ret
.LBB1_7:
.Lpcrel_hi0:
auipc a0, %got_pcrel_hi(stderr)
ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
ld a3, 0(a0)
.Lpcrel_hi1:
auipc a0, %pcrel_hi(.L.str)
li a1, 17
addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
li a2, 1
call fwrite
li a0, -1
call exit
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,907
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O3
|
RISC-V 64 clang 21.1.0
|
brokenCalc:
li a2, 0
blt a0, a1, .LBB0_2
j .LBB0_4
.LBB0_1:
addiw a1, a1, 1
addi a2, a2, 1
bge a0, a1, .LBB0_4
.LBB0_2:
andi a3, a1, 1
bnez a3, .LBB0_1
sraiw a1, a1, 1
addi a2, a2, 1
blt a0, a1, .LBB0_2
.LBB0_4:
subw a0, a0, a1
addw a0, a0, a2
ret
main:
addi sp, sp, -32
sd ra, 24(sp)
sd s0, 16(sp)
sd s1, 8(sp)
mv s0, a1
li a1, 3
bne a0, a1, .LBB1_7
ld a0, 8(s0)
li a2, 10
li a1, 0
call strtol
ld a1, 16(s0)
mv s0, a0
sext.w s1, a0
li a2, 10
mv a0, a1
li a1, 0
call strtol
sext.w a1, a0
li a2, 0
bge s1, a1, .LBB1_6
li a2, 0
mv a1, a0
j .LBB1_4
.LBB1_3:
addiw a1, a1, 1
addi a2, a2, 1
bge s1, a1, .LBB1_6
.LBB1_4:
andi a0, a1, 1
bnez a0, .LBB1_3
sraiw a1, a1, 1
addi a2, a2, 1
blt s1, a1, .LBB1_4
.LBB1_6:
add a2, a2, s0
subw a1, a2, a1
.Lpcrel_hi2:
auipc a0, %pcrel_hi(.L.str.1)
addi a0, a0, %pcrel_lo(.Lpcrel_hi2)
call printf
li a0, 0
ld ra, 24(sp)
ld s0, 16(sp)
ld s1, 8(sp)
addi sp, sp, 32
ret
.LBB1_7:
.Lpcrel_hi0:
auipc a0, %got_pcrel_hi(stderr)
ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
ld a3, 0(a0)
.Lpcrel_hi1:
auipc a0, %pcrel_hi(.L.str)
li a1, 17
addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
li a2, 1
call fwrite
li a0, -1
call exit
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,908
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O0
|
RISC-V 64 gcc 15.2.0
|
brokenCalc:
addi sp,sp,-48
sd ra,40(sp)
sd s0,32(sp)
addi s0,sp,48
mv a5,a0
mv a4,a1
sw a5,-36(s0)
mv a5,a4
sw a5,-40(s0)
sw zero,-20(s0)
j .L2
.L5:
lw a5,-40(s0)
andi a5,a5,1
sext.w a5,a5
beq a5,zero,.L3
lw a5,-40(s0)
addiw a5,a5,1
sw a5,-40(s0)
j .L4
.L3:
lw a5,-40(s0)
srliw a4,a5,31
addw a5,a4,a5
sraiw a5,a5,1
sw a5,-40(s0)
.L4:
lw a5,-20(s0)
addiw a5,a5,1
sw a5,-20(s0)
.L2:
lw a5,-36(s0)
mv a4,a5
lw a5,-40(s0)
sext.w a4,a4
sext.w a5,a5
blt a4,a5,.L5
lw a5,-36(s0)
mv a4,a5
lw a5,-40(s0)
subw a5,a4,a5
sext.w a5,a5
lw a4,-20(s0)
addw a5,a4,a5
sw a5,-20(s0)
lw a5,-20(s0)
mv a0,a5
ld ra,40(sp)
ld s0,32(sp)
addi sp,sp,48
jr ra
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
addi sp,sp,-48
sd ra,40(sp)
sd s0,32(sp)
addi s0,sp,48
mv a5,a0
sd a1,-48(s0)
sw a5,-36(s0)
lw a5,-36(s0)
sext.w a4,a5
li a5,3
beq a4,a5,.L8
lui a5,%hi(stderr)
ld a5,%lo(stderr)(a5)
mv a3,a5
li a2,17
li a1,1
lui a5,%hi(.LC0)
addi a0,a5,%lo(.LC0)
call fwrite
li a0,-1
call exit
.L8:
ld a5,-48(s0)
addi a5,a5,8
ld a5,0(a5)
mv a0,a5
call atoi
mv a5,a0
sw a5,-20(s0)
ld a5,-48(s0)
addi a5,a5,16
ld a5,0(a5)
mv a0,a5
call atoi
mv a5,a0
sw a5,-24(s0)
lw a4,-24(s0)
lw a5,-20(s0)
mv a1,a4
mv a0,a5
call brokenCalc
mv a5,a0
mv a1,a5
lui a5,%hi(.LC1)
addi a0,a5,%lo(.LC1)
call printf
li a5,0
mv a0,a5
ld ra,40(sp)
ld s0,32(sp)
addi sp,sp,48
jr ra
|
13,909
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O1
|
RISC-V 64 gcc 15.2.0
|
brokenCalc:
ble a1,a0,.L6
li a5,0
j .L5
.L3:
srliw a4,a1,31
addw a1,a4,a1
sraiw a1,a1,1
.L4:
addiw a5,a5,1
ble a1,a0,.L2
.L5:
andi a4,a1,1
beq a4,zero,.L3
addiw a1,a1,1
j .L4
.L6:
li a5,0
.L2:
subw a0,a0,a1
addw a0,a0,a5
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
sd s1,8(sp)
li a5,3
bne a0,a5,.L11
mv s0,a1
li a2,10
li a1,0
ld a0,8(s0)
call strtol
mv s1,a0
li a2,10
li a1,0
ld a0,16(s0)
call strtol
sext.w a1,a0
sext.w a0,s1
call brokenCalc
mv a1,a0
lui a0,%hi(.LC1)
addi a0,a0,%lo(.LC1)
call printf
li a0,0
ld ra,24(sp)
ld s0,16(sp)
ld s1,8(sp)
addi sp,sp,32
jr ra
.L11:
lui a5,%hi(stderr)
ld a3,%lo(stderr)(a5)
li a2,17
li a1,1
lui a0,%hi(.LC0)
addi a0,a0,%lo(.LC0)
call fwrite
li a0,-1
call exit
|
13,910
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O2
|
RISC-V 64 gcc 15.2.0
|
brokenCalc:
li a3,0
bgt a1,a0,.L5
j .L2
.L9:
addiw a1,a1,1
addiw a3,a3,1
bge a0,a1,.L2
.L5:
srliw a5,a1,31
andi a4,a1,1
addw a5,a5,a1
bne a4,zero,.L9
sraiw a1,a5,1
addiw a3,a3,1
blt a0,a1,.L5
.L2:
subw a0,a0,a1
addw a0,a0,a3
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
sd s1,8(sp)
li a5,3
bne a0,a5,.L19
ld a0,8(a1)
mv s1,a1
li a2,10
li a1,0
call strtol
mv s0,a0
ld a0,16(s1)
li a2,10
li a1,0
call strtol
sext.w s0,s0
sext.w a0,a0
li a5,0
bgt a0,s0,.L15
j .L12
.L20:
addiw a0,a0,1
addiw a5,a5,1
bge s0,a0,.L12
.L15:
andi a4,a0,1
bne a4,zero,.L20
srliw a4,a0,31
addw a0,a4,a0
sraiw a0,a0,1
addiw a5,a5,1
blt s0,a0,.L15
.L12:
subw a1,s0,a0
lui a0,%hi(.LC1)
addw a1,a1,a5
addi a0,a0,%lo(.LC1)
call printf
ld ra,24(sp)
ld s0,16(sp)
ld s1,8(sp)
li a0,0
addi sp,sp,32
jr ra
.L19:
lui a5,%hi(stderr)
ld a3,%lo(stderr)(a5)
lui a0,%hi(.LC0)
addi a0,a0,%lo(.LC0)
li a2,17
li a1,1
call fwrite
li a0,-1
call exit
|
13,911
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
riscv64
|
-O3
|
RISC-V 64 gcc 15.2.0
|
brokenCalc:
li a3,0
bgt a1,a0,.L5
j .L2
.L9:
addiw a1,a1,1
addiw a3,a3,1
bge a0,a1,.L2
.L5:
srliw a5,a1,31
andi a4,a1,1
addw a5,a5,a1
bne a4,zero,.L9
sraiw a1,a5,1
addiw a3,a3,1
blt a0,a1,.L5
.L2:
subw a0,a0,a1
addw a0,a0,a3
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
sd s1,8(sp)
li a5,3
bne a0,a5,.L19
ld a0,8(a1)
mv s1,a1
li a2,10
li a1,0
call strtol
mv s0,a0
ld a0,16(s1)
li a2,10
li a1,0
call strtol
sext.w s0,s0
sext.w a0,a0
li a5,0
bgt a0,s0,.L15
j .L12
.L20:
addiw a0,a0,1
addiw a5,a5,1
bge s0,a0,.L12
.L15:
andi a4,a0,1
bne a4,zero,.L20
srliw a4,a0,31
addw a0,a4,a0
sraiw a0,a0,1
addiw a5,a5,1
blt s0,a0,.L15
.L12:
subw a1,s0,a0
lui a0,%hi(.LC1)
addw a1,a1,a5
addi a0,a0,%lo(.LC1)
call printf
ld ra,24(sp)
ld s0,16(sp)
ld s1,8(sp)
li a0,0
addi sp,sp,32
jr ra
.L19:
lui a5,%hi(stderr)
ld a3,%lo(stderr)(a5)
lui a0,%hi(.LC0)
addi a0,a0,%lo(.LC0)
li a2,17
li a1,1
call fwrite
li a0,-1
call exit
|
13,912
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O0
|
x86-64 clang 21.1.0
|
brokenCalc:
push rbp
mov rbp, rsp
mov dword ptr [rbp - 4], edi
mov dword ptr [rbp - 8], esi
mov dword ptr [rbp - 12], 0
.LBB0_1:
mov eax, dword ptr [rbp - 4]
cmp eax, dword ptr [rbp - 8]
jge .LBB0_6
mov eax, dword ptr [rbp - 8]
and eax, 1
cmp eax, 0
je .LBB0_4
mov eax, dword ptr [rbp - 8]
add eax, 1
mov dword ptr [rbp - 16], eax
jmp .LBB0_5
.LBB0_4:
mov eax, dword ptr [rbp - 8]
mov ecx, 2
cdq
idiv ecx
mov dword ptr [rbp - 16], eax
.LBB0_5:
mov eax, dword ptr [rbp - 16]
mov dword ptr [rbp - 8], eax
mov eax, dword ptr [rbp - 12]
add eax, 1
mov dword ptr [rbp - 12], eax
jmp .LBB0_1
.LBB0_6:
mov eax, dword ptr [rbp - 4]
sub eax, dword ptr [rbp - 8]
add eax, dword ptr [rbp - 12]
mov dword ptr [rbp - 12], eax
mov eax, dword ptr [rbp - 12]
pop rbp
ret
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov dword ptr [rbp - 4], 0
mov dword ptr [rbp - 8], edi
mov qword ptr [rbp - 16], rsi
cmp dword ptr [rbp - 8], 3
je .LBB1_2
mov rax, qword ptr [rip + stderr@GOTPCREL]
mov rdi, qword ptr [rax]
lea rsi, [rip + .L.str]
mov al, 0
call fprintf@PLT
mov edi, 4294967295
call exit@PLT
.LBB1_2:
mov rax, qword ptr [rbp - 16]
mov rdi, qword ptr [rax + 8]
call atoi@PLT
mov dword ptr [rbp - 20], eax
mov rax, qword ptr [rbp - 16]
mov rdi, qword ptr [rax + 16]
call atoi@PLT
mov dword ptr [rbp - 24], eax
mov edi, dword ptr [rbp - 20]
mov esi, dword ptr [rbp - 24]
call brokenCalc
mov esi, eax
lea rdi, [rip + .L.str.1]
mov al, 0
call printf@PLT
xor eax, eax
add rsp, 32
pop rbp
ret
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,913
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O1
|
x86-64 clang 21.1.0
|
brokenCalc:
mov eax, edi
xor ecx, ecx
cmp edi, esi
jge .LBB0_1
xor ecx, ecx
.LBB0_3:
lea edi, [rsi + 1]
mov edx, esi
sar edx
test sil, 1
cmovne edx, edi
inc ecx
mov esi, edx
cmp eax, edx
jl .LBB0_3
jmp .LBB0_4
.LBB0_1:
mov edx, esi
.LBB0_4:
sub eax, edx
add eax, ecx
ret
main:
push r15
push r14
push rbx
cmp edi, 3
jne .LBB1_6
mov r14, rsi
mov rdi, qword ptr [rsi + 8]
xor r15d, r15d
xor esi, esi
mov edx, 10
call strtol@PLT
mov rbx, rax
mov rdi, qword ptr [r14 + 16]
xor esi, esi
mov edx, 10
call strtol@PLT
cmp ebx, eax
jge .LBB1_2
xor r15d, r15d
.LBB1_4:
lea edx, [rax + 1]
mov ecx, eax
sar ecx
test al, 1
cmovne ecx, edx
inc r15d
mov eax, ecx
cmp ecx, ebx
jg .LBB1_4
jmp .LBB1_5
.LBB1_2:
mov ecx, eax
.LBB1_5:
sub ebx, ecx
add ebx, r15d
lea rdi, [rip + .L.str.1]
mov esi, ebx
xor eax, eax
call printf@PLT
xor eax, eax
pop rbx
pop r14
pop r15
ret
.LBB1_6:
mov rax, qword ptr [rip + stderr@GOTPCREL]
mov rcx, qword ptr [rax]
lea rdi, [rip + .L.str]
mov esi, 17
mov edx, 1
call fwrite@PLT
mov edi, -1
call exit@PLT
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,914
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O2
|
x86-64 clang 21.1.0
|
brokenCalc:
mov eax, edi
xor ecx, ecx
cmp edi, esi
jge .LBB0_1
xor ecx, ecx
.LBB0_3:
lea edi, [rsi + 1]
mov edx, esi
sar edx
test sil, 1
cmovne edx, edi
inc ecx
mov esi, edx
cmp eax, edx
jl .LBB0_3
jmp .LBB0_4
.LBB0_1:
mov edx, esi
.LBB0_4:
sub eax, edx
add eax, ecx
ret
main:
push r15
push r14
push rbx
cmp edi, 3
jne .LBB1_6
mov r14, rsi
mov rdi, qword ptr [rsi + 8]
xor r15d, r15d
xor esi, esi
mov edx, 10
call strtol@PLT
mov rbx, rax
mov rdi, qword ptr [r14 + 16]
xor esi, esi
mov edx, 10
call strtol@PLT
cmp ebx, eax
jge .LBB1_2
xor r15d, r15d
.LBB1_4:
lea edx, [rax + 1]
mov ecx, eax
sar ecx
test al, 1
cmovne ecx, edx
inc r15d
mov eax, ecx
cmp ecx, ebx
jg .LBB1_4
jmp .LBB1_5
.LBB1_2:
mov ecx, eax
.LBB1_5:
sub ebx, ecx
add ebx, r15d
lea rdi, [rip + .L.str.1]
mov esi, ebx
xor eax, eax
call printf@PLT
xor eax, eax
pop rbx
pop r14
pop r15
ret
.LBB1_6:
mov rax, qword ptr [rip + stderr@GOTPCREL]
mov rcx, qword ptr [rax]
lea rdi, [rip + .L.str]
mov esi, 17
mov edx, 1
call fwrite@PLT
mov edi, -1
call exit@PLT
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,915
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O3
|
x86-64 clang 21.1.0
|
brokenCalc:
mov eax, edi
xor ecx, ecx
cmp edi, esi
jge .LBB0_1
xor ecx, ecx
.LBB0_3:
lea edi, [rsi + 1]
mov edx, esi
sar edx
test sil, 1
cmovne edx, edi
inc ecx
mov esi, edx
cmp eax, edx
jl .LBB0_3
sub eax, edx
add eax, ecx
ret
.LBB0_1:
mov edx, esi
sub eax, edx
add eax, ecx
ret
main:
push r15
push r14
push rbx
cmp edi, 3
jne .LBB1_6
mov r14, rsi
mov rdi, qword ptr [rsi + 8]
xor r15d, r15d
xor esi, esi
mov edx, 10
call strtol@PLT
mov rbx, rax
mov rdi, qword ptr [r14 + 16]
xor esi, esi
mov edx, 10
call strtol@PLT
cmp ebx, eax
jge .LBB1_2
xor r15d, r15d
.LBB1_4:
lea edx, [rax + 1]
mov ecx, eax
sar ecx
test al, 1
cmovne ecx, edx
inc r15d
mov eax, ecx
cmp ecx, ebx
jg .LBB1_4
jmp .LBB1_5
.LBB1_2:
mov ecx, eax
.LBB1_5:
sub ebx, ecx
add ebx, r15d
lea rdi, [rip + .L.str.1]
mov esi, ebx
xor eax, eax
call printf@PLT
xor eax, eax
pop rbx
pop r14
pop r15
ret
.LBB1_6:
mov rax, qword ptr [rip + stderr@GOTPCREL]
mov rcx, qword ptr [rax]
lea rdi, [rip + .L.str]
mov esi, 17
mov edx, 1
call fwrite@PLT
mov edi, -1
call exit@PLT
.L.str:
.asciz "Usage: ./test x y"
.L.str.1:
.asciz "%d\n"
|
13,916
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O0
|
x86-64 gcc 15.2
|
brokenCalc:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov DWORD PTR [rbp-24], esi
mov DWORD PTR [rbp-4], 0
jmp .L2
.L5:
mov eax, DWORD PTR [rbp-24]
and eax, 1
test eax, eax
je .L3
add DWORD PTR [rbp-24], 1
jmp .L4
.L3:
mov eax, DWORD PTR [rbp-24]
mov edx, eax
shr edx, 31
add eax, edx
sar eax
mov DWORD PTR [rbp-24], eax
.L4:
add DWORD PTR [rbp-4], 1
.L2:
mov eax, DWORD PTR [rbp-20]
cmp eax, DWORD PTR [rbp-24]
jl .L5
mov eax, DWORD PTR [rbp-20]
sub eax, DWORD PTR [rbp-24]
add DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-20], edi
mov QWORD PTR [rbp-32], rsi
cmp DWORD PTR [rbp-20], 3
je .L8
mov rax, QWORD PTR stderr[rip]
mov rcx, rax
mov edx, 17
mov esi, 1
mov edi, OFFSET FLAT:.LC0
call fwrite
mov edi, -1
call exit
.L8:
mov rax, QWORD PTR [rbp-32]
add rax, 8
mov rax, QWORD PTR [rax]
mov rdi, rax
call atoi
mov DWORD PTR [rbp-4], eax
mov rax, QWORD PTR [rbp-32]
add rax, 16
mov rax, QWORD PTR [rax]
mov rdi, rax
call atoi
mov DWORD PTR [rbp-8], eax
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-4]
mov esi, edx
mov edi, eax
call brokenCalc
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
leave
ret
|
13,917
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O1
|
x86-64 gcc 15.2
|
brokenCalc:
cmp esi, edi
jle .L6
mov ecx, 0
.L5:
mov edx, esi
shr edx, 31
add edx, esi
sar edx
lea eax, [rsi+1]
test sil, 1
mov esi, edx
cmovne esi, eax
add ecx, 1
cmp esi, edi
jg .L5
.L2:
sub edi, esi
lea eax, [rdi+rcx]
ret
.L6:
mov ecx, 0
jmp .L2
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
push r14
push rbx
sub rsp, 8
cmp edi, 3
jne .L11
mov rbx, rsi
mov rdi, QWORD PTR [rsi+8]
mov edx, 10
mov esi, 0
call strtol
mov r14, rax
mov rdi, QWORD PTR [rbx+16]
mov edx, 10
mov esi, 0
call strtol
mov esi, eax
mov edi, r14d
call brokenCalc
mov esi, eax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
mov eax, 0
add rsp, 8
pop rbx
pop r14
ret
.L11:
mov rcx, QWORD PTR stderr[rip]
mov edx, 17
mov esi, 1
mov edi, OFFSET FLAT:.LC0
call fwrite
mov edi, -1
call exit
|
13,918
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O2
|
x86-64 gcc 15.2
|
brokenCalc:
xor ecx, ecx
cmp esi, edi
jle .L2
.L5:
mov edx, esi
lea r8d, [rsi+1]
shr edx, 31
add edx, esi
sar edx
and esi, 1
mov esi, edx
cmovne esi, r8d
add ecx, 1
cmp edi, esi
jl .L5
.L2:
sub edi, esi
lea eax, [rdi+rcx]
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
push rbp
push rbx
sub rsp, 8
cmp edi, 3
jne .L18
mov rdi, QWORD PTR [rsi+8]
mov rbp, rsi
mov edx, 10
xor esi, esi
call strtol
mov rdi, QWORD PTR [rbp+16]
mov edx, 10
xor esi, esi
mov rbx, rax
call strtol
xor ecx, ecx
cmp eax, ebx
jle .L11
.L14:
mov edx, eax
lea esi, [rax+1]
shr edx, 31
add edx, eax
sar edx
test al, 1
mov eax, edx
cmovne eax, esi
add ecx, 1
cmp ebx, eax
jl .L14
.L11:
sub ebx, eax
mov edi, OFFSET FLAT:.LC1
xor eax, eax
lea esi, [rbx+rcx]
call printf
add rsp, 8
xor eax, eax
pop rbx
pop rbp
ret
.L18:
mov edi, OFFSET FLAT:.LC0
mov edx, 17
mov esi, 1
mov rcx, QWORD PTR stderr[rip]
call fwrite
mov edi, -1
call exit
|
13,919
| 991
|
Broken Calculator
|
Medium
|
#include <stdio.h>
#include <stdlib.h>
int brokenCalc(int X, int Y)
{
int step = 0;
while (X < Y) {
Y = Y & 1 ? Y + 1 : Y / 2;
step++;
}
step += X - Y;
return step;
}
int main(int argc, char **argv)
{
if (argc != 3) {
fprintf(stderr, "Usage: ./test x y");
exit(-1);
}
int x = atoi(argv[1]);
int y = atoi(argv[2]);
printf("%d\n", brokenCalc(x, y));
return 0;
}
|
x86-64
|
-O3
|
x86-64 gcc 15.2
|
brokenCalc:
xor ecx, ecx
cmp esi, edi
jle .L2
.L5:
mov edx, esi
lea r8d, [rsi+1]
shr edx, 31
add edx, esi
sar edx
and esi, 1
mov esi, edx
cmovne esi, r8d
add ecx, 1
cmp edi, esi
jl .L5
.L2:
sub edi, esi
lea eax, [rdi+rcx]
ret
.LC0:
.string "Usage: ./test x y"
.LC1:
.string "%d\n"
main:
push rbp
push rbx
sub rsp, 8
cmp edi, 3
jne .L18
mov rdi, QWORD PTR [rsi+8]
mov rbp, rsi
mov edx, 10
xor esi, esi
call strtol
mov rdi, QWORD PTR [rbp+16]
mov edx, 10
xor esi, esi
mov rbx, rax
call strtol
xor ecx, ecx
cmp eax, ebx
jle .L11
.L14:
mov edx, eax
lea esi, [rax+1]
shr edx, 31
add edx, eax
sar edx
test al, 1
mov eax, edx
cmovne eax, esi
add ecx, 1
cmp ebx, eax
jl .L14
.L11:
sub ebx, eax
mov edi, OFFSET FLAT:.LC1
xor eax, eax
lea esi, [rbx+rcx]
call printf
add rsp, 8
xor eax, eax
pop rbx
pop rbp
ret
.L18:
mov edi, OFFSET FLAT:.LC0
mov edx, 17
mov esi, 1
mov rcx, QWORD PTR stderr[rip]
call fwrite
mov edi, -1
call exit
|
13,920
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O0
|
ARM64 gcc 15.2.0
|
subarraysWithKDistinct:
sub sp, sp, #2240
sub sp, sp, #77824
stp x29, x30, [sp]
mov x29, sp
str x0, [sp, 24]
str w1, [sp, 20]
str w2, [sp, 16]
add x0, sp, 40
mov x1, 14468
movk x1, 0x1, lsl 16
mov x2, x1
mov w1, 0
bl memset
add x0, sp, 65536
str wzr, [x0, 14524]
add x0, sp, 65536
str wzr, [x0, 14520]
mov w0, 1
add x1, sp, 65536
str w0, [x1, 14516]
add x0, sp, 65536
str wzr, [x0, 14512]
b .L2
.L7:
add x0, sp, 65536
ldr w0, [x0, 14520]
add w1, w0, 1
add x2, sp, 65536
str w1, [x2, 14520]
sxtw x0, w0
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w0, [x0]
add x1, sp, 65536
str w0, [x1, 14508]
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
ldr w0, [x1, x0]
cmp w0, 0
bne .L3
ldr w0, [sp, 16]
sub w0, w0, #1
str w0, [sp, 16]
.L3:
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
ldr w0, [x1, x0]
add w2, w0, 1
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
str w2, [x1, x0]
ldr w0, [sp, 16]
cmp w0, 0
bge .L4
add x0, sp, 65536
ldr w0, [x0, 14524]
add w1, w0, 1
add x2, sp, 65536
str w1, [x2, 14524]
sxtw x0, w0
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w0, [x0]
add x1, sp, 65536
str w0, [x1, 14508]
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
str wzr, [x1, x0]
str wzr, [sp, 16]
mov w0, 1
add x1, sp, 65536
str w0, [x1, 14516]
.L4:
ldr w0, [sp, 16]
cmp w0, 0
bne .L2
b .L5
.L6:
add x0, sp, 65536
ldr w0, [x0, 14524]
add w1, w0, 1
add x2, sp, 65536
str w1, [x2, 14524]
sxtw x0, w0
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w0, [x0]
add x1, sp, 65536
str w0, [x1, 14508]
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
ldr w0, [x1, x0]
sub w2, w0, #1
add x0, sp, 65536
ldrsw x0, [x0, 14508]
lsl x0, x0, 2
add x1, sp, 40
str w2, [x1, x0]
add x0, sp, 65536
ldr w0, [x0, 14516]
add w0, w0, 1
add x1, sp, 65536
str w0, [x1, 14516]
.L5:
add x0, sp, 65536
ldrsw x0, [x0, 14524]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w0, [x0]
sxtw x0, w0
lsl x0, x0, 2
add x1, sp, 40
ldr w0, [x1, x0]
cmp w0, 1
bgt .L6
add x0, sp, 65536
ldr w1, [x0, 14512]
add x0, sp, 65536
ldr w0, [x0, 14516]
add w0, w1, w0
add x1, sp, 65536
str w0, [x1, 14512]
.L2:
add x0, sp, 65536
ldr w1, [x0, 14520]
ldr w0, [sp, 20]
cmp w1, w0
blt .L7
add x0, sp, 65536
ldr w0, [x0, 14512]
ldp x29, x30, [sp]
add sp, sp, 2240
add sp, sp, 77824
ret
|
13,921
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O1
|
ARM64 gcc 15.2.0
|
subarraysWithKDistinct:
sub sp, sp, #2240
sub sp, sp, #77824
stp x29, x30, [sp]
mov x29, sp
stp x19, x20, [sp, 16]
str x21, [sp, 32]
mov x19, x0
mov w21, w1
mov w20, w2
mov x2, 14468
movk x2, 0x1, lsl 16
mov w1, 0
add x0, sp, 56
bl memset
cmp w21, 0
ble .L10
mov x6, x19
add x9, x19, w21, sxtw 2
mov w0, 0
mov w8, 1
mov w5, 0
add x3, sp, 56
mov w10, w8
b .L9
.L4:
cbz w20, .L15
.L6:
add x6, x6, 4
cmp x6, x9
beq .L1
.L9:
ldr w4, [x6]
ldr w1, [x3, w4, sxtw 2]
cmp w1, 0
cset w2, eq
add w1, w1, 1
str w1, [x3, w4, sxtw 2]
subs w20, w20, w2
bpl .L4
add w2, w5, 1
ldrsw x1, [x19, w5, sxtw 2]
str wzr, [x3, x1, lsl 2]
mov w8, w10
.L5:
sbfiz x5, x2, 2, 32
ldr w4, [x19, x5]
ldr w1, [x3, w4, sxtw 2]
cmp w1, 1
ble .L11
mov w11, w2
add w2, w2, 1
sxtw x2, w2
sub x5, x5, x2, lsl 2
add x5, x5, 4
add x5, x19, x5
.L8:
sub w1, w1, #1
str w1, [x3, w4, sxtw 2]
ldr w4, [x5, x2, lsl 2]
ldr w1, [x3, w4, sxtw 2]
mov x7, x2
add x2, x2, 1
cmp w1, 1
bgt .L8
mov w5, w7
sub w8, w8, w11
add w8, w8, w7
.L7:
add w0, w0, w8
mov w20, 0
b .L6
.L15:
mov w2, w5
b .L5
.L11:
mov w5, w2
b .L7
.L10:
mov w0, 0
.L1:
ldp x29, x30, [sp]
ldp x19, x20, [sp, 16]
ldr x21, [sp, 32]
add sp, sp, 2240
add sp, sp, 77824
ret
|
13,922
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O2
|
ARM64 gcc 15.2.0
|
subarraysWithKDistinct:
sub sp, sp, #2240
sub sp, sp, #77824
stp x29, x30, [sp]
mov x29, sp
stp x19, x20, [sp, 16]
mov w19, w2
mov x2, 14468
mov x20, x0
movk x2, 0x1, lsl 16
add x0, sp, 56
str x21, [sp, 32]
mov w21, w1
mov w1, 0
bl memset
cmp w21, 0
ble .L11
ldrsw x2, [x20]
mov x3, x0
mov x6, x20
add x10, x20, w21, uxtw 2
ldr w5, [x0, x2, lsl 2]
cbz w5, .L20
mov w1, w5
mov w0, 0
mov w9, 1
mov w5, 0
.L3:
add w1, w1, 1
str w1, [x3, x2, lsl 2]
tbz w19, #31, .L4
add w8, w5, 1
ldrsw x1, [x20, w5, sxtw 2]
mov w9, 1
sbfiz x5, x8, 2, 32
ldrsw x4, [x20, w8, sxtw 2]
str wzr, [x3, x1, lsl 2]
ldr w1, [x3, x4, lsl 2]
cmp w1, 1
ble .L21
.L5:
add w2, w8, 1
sxtw x2, w2
sub x5, x5, x2, lsl 2
add x5, x5, 4
add x5, x20, x5
.L9:
sub w1, w1, #1
str w1, [x3, x4, lsl 2]
ldrsw x4, [x5, x2, lsl 2]
mov x7, x2
add x2, x2, 1
ldr w1, [x3, x4, lsl 2]
cmp w1, 1
bgt .L9
sub w9, w9, w8
mov w5, w7
add w9, w9, w7
.L6:
add w0, w0, w9
mov w19, 0
.L8:
add x6, x6, 4
cmp x6, x10
beq .L1
ldrsw x2, [x6]
lsl x4, x2, 2
ldr w1, [x3, x4]
cbz w1, .L10
add w1, w1, 1
str w1, [x3, x4]
.L4:
cbnz w19, .L8
mov w8, w5
sbfiz x5, x8, 2, 32
ldrsw x4, [x20, w8, sxtw 2]
ldr w1, [x3, x4, lsl 2]
cmp w1, 1
bgt .L5
.L21:
mov w5, w8
b .L6
.L20:
mov w0, 0
mov w9, 1
.L10:
sub w19, w19, #1
mov w1, 0
b .L3
.L11:
mov w0, 0
.L1:
ldr x21, [sp, 32]
ldp x29, x30, [sp]
ldp x19, x20, [sp, 16]
add sp, sp, 2240
add sp, sp, 77824
ret
|
13,923
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O3
|
ARM64 gcc 15.2.0
|
subarraysWithKDistinct:
sub sp, sp, #2240
sub sp, sp, #77824
stp x29, x30, [sp]
mov x29, sp
stp x19, x20, [sp, 16]
mov w19, w2
mov x2, 14468
mov x20, x0
movk x2, 0x1, lsl 16
add x0, sp, 56
str x21, [sp, 32]
mov w21, w1
mov w1, 0
bl memset
cmp w21, 0
ble .L11
ldrsw x2, [x20]
mov x3, x0
add x10, x20, w21, uxtw 2
mov x6, x20
ldr w7, [x0, x2, lsl 2]
cbz w7, .L21
mov w1, w7
mov w0, 0
mov w7, 0
mov w9, 1
.L3:
add w1, w1, 1
str w1, [x3, x2, lsl 2]
tbz w19, #31, .L4
ldrsw x1, [x20, w7, sxtw 2]
add w7, w7, 1
mov w9, 1
str wzr, [x3, x1, lsl 2]
.L7:
ldrsw x4, [x20, w7, sxtw 2]
sbfiz x5, x7, 2, 32
ldr w1, [x3, x4, lsl 2]
cmp w1, 1
ble .L6
add w2, w7, 1
sxtw x2, w2
sub x5, x5, x2, lsl 2
add x5, x5, 4
add x5, x20, x5
.L9:
sub w1, w1, #1
str w1, [x3, x4, lsl 2]
ldrsw x4, [x5, x2, lsl 2]
mov x8, x2
add x2, x2, 1
ldr w1, [x3, x4, lsl 2]
cmp w1, 1
bgt .L9
sub w9, w9, w7
mov w7, w8
add w9, w9, w8
.L6:
add x6, x6, 4
add w0, w0, w9
mov w19, 0
cmp x10, x6
beq .L1
.L22:
ldrsw x2, [x6]
lsl x4, x2, 2
ldr w1, [x3, x4]
cbz w1, .L10
add w1, w1, 1
str w1, [x3, x4]
.L4:
cbz w19, .L7
add x6, x6, 4
cmp x10, x6
bne .L22
.L1:
ldr x21, [sp, 32]
ldp x29, x30, [sp]
ldp x19, x20, [sp, 16]
add sp, sp, 2240
add sp, sp, 77824
ret
.L21:
mov w0, 0
mov w9, 1
.L10:
sub w19, w19, #1
mov w1, 0
b .L3
.L11:
ldr x21, [sp, 32]
mov w0, 0
ldp x29, x30, [sp]
ldp x19, x20, [sp, 16]
add sp, sp, 2240
add sp, sp, 77824
ret
|
13,924
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O0
|
armv8-a clang 21.1.0
|
subarraysWithKDistinct:
stp x29, x30, [sp, #-32]!
str x28, [sp, #16]
mov x29, sp
sub sp, sp, #19, lsl #12
sub sp, sp, #2224
sub x8, x29, #16
str x8, [sp]
str x0, [x8, #8]
str w1, [x8, #4]
str w2, [x8]
add x0, sp, #28
mov x2, #14468
movk x2, #1, lsl #16
mov w1, wzr
bl memset
str wzr, [sp, #20]
str wzr, [sp, #16]
mov w8, #1
str w8, [sp, #12]
str wzr, [sp, #8]
b .LBB0_1
.LBB0_1:
ldr x9, [sp]
ldr w8, [sp, #16]
ldr w9, [x9, #4]
subs w8, w8, w9
b.ge .LBB0_12
b .LBB0_2
.LBB0_2:
ldr x8, [sp]
ldr x8, [x8, #8]
ldrsw x9, [sp, #16]
mov w10, w9
add w10, w10, #1
str w10, [sp, #16]
ldr w8, [x8, x9, lsl #2]
str w8, [sp, #24]
ldrsw x9, [sp, #24]
add x8, sp, #28
ldr w8, [x8, x9, lsl #2]
cbnz w8, .LBB0_4
b .LBB0_3
.LBB0_3:
ldr x9, [sp]
ldr w8, [x9]
subs w8, w8, #1
str w8, [x9]
b .LBB0_4
.LBB0_4:
ldr x8, [sp]
ldrsw x11, [sp, #24]
add x10, sp, #28
ldr w9, [x10, x11, lsl #2]
add w9, w9, #1
str w9, [x10, x11, lsl #2]
ldr w8, [x8]
tbz w8, #31, .LBB0_6
b .LBB0_5
.LBB0_5:
ldr x9, [sp]
ldr x10, [x9, #8]
ldrsw x11, [sp, #20]
mov w12, w11
mov w8, #1
add w12, w12, #1
str w12, [sp, #20]
ldr w10, [x10, x11, lsl #2]
str w10, [sp, #24]
ldrsw x12, [sp, #24]
add x11, sp, #28
mov w10, wzr
str w10, [x11, x12, lsl #2]
str wzr, [x9]
str w8, [sp, #12]
b .LBB0_6
.LBB0_6:
ldr x8, [sp]
ldr w8, [x8]
cbnz w8, .LBB0_11
b .LBB0_7
.LBB0_7:
b .LBB0_8
.LBB0_8:
ldr x8, [sp]
ldr x8, [x8, #8]
ldrsw x9, [sp, #20]
ldrsw x9, [x8, x9, lsl #2]
add x8, sp, #28
ldr w8, [x8, x9, lsl #2]
subs w8, w8, #1
b.le .LBB0_10
b .LBB0_9
.LBB0_9:
ldr x8, [sp]
ldr x8, [x8, #8]
ldrsw x9, [sp, #20]
mov w10, w9
add w10, w10, #1
str w10, [sp, #20]
ldr w8, [x8, x9, lsl #2]
str w8, [sp, #24]
ldrsw x10, [sp, #24]
add x9, sp, #28
ldr w8, [x9, x10, lsl #2]
subs w8, w8, #1
str w8, [x9, x10, lsl #2]
ldr w8, [sp, #12]
add w8, w8, #1
str w8, [sp, #12]
b .LBB0_8
.LBB0_10:
ldr w9, [sp, #12]
ldr w8, [sp, #8]
add w8, w8, w9
str w8, [sp, #8]
b .LBB0_11
.LBB0_11:
b .LBB0_1
.LBB0_12:
ldr w0, [sp, #8]
add sp, sp, #19, lsl #12
add sp, sp, #2224
ldr x28, [sp, #16]
ldp x29, x30, [sp], #32
ret
|
13,925
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O1
|
armv8-a clang 21.1.0
|
subarraysWithKDistinct:
stp x29, x30, [sp, #-64]!
str x28, [sp, #16]
stp x22, x21, [sp, #32]
stp x20, x19, [sp, #48]
mov x29, sp
sub sp, sp, #19, lsl #12
sub sp, sp, #2192
mov w19, w2
mov w2, #14468
mov w21, w1
mov x20, x0
add x0, sp, #12
mov w1, wzr
movk w2, #1, lsl #16
add x22, sp, #12
bl memset
cmp w21, #1
b.lt .LBB0_10
mov x8, xzr
mov w0, wzr
mov w11, wzr
mov w9, w21
add x10, x20, #4
mov w12, #1
b .LBB0_4
.LBB0_2:
add w0, w12, w0
.LBB0_3:
add x8, x8, #1
cmp x8, x9
b.eq .LBB0_11
.LBB0_4:
ldrsw x13, [x20, x8, lsl #2]
ldr w14, [x22, x13, lsl #2]
cmp w14, #0
add w14, w14, #1
str w14, [x22, x13, lsl #2]
cset w15, eq
subs w19, w19, w15
b.mi .LBB0_6
cbnz w19, .LBB0_3
b .LBB0_7
.LBB0_6:
ldrsw x12, [x20, w11, sxtw #2]
mov w19, wzr
add w11, w11, #1
str wzr, [x22, x12, lsl #2]
mov w12, #1
cbnz w19, .LBB0_3
.LBB0_7:
ldrsw x13, [x20, w11, sxtw #2]
add x13, x22, x13, lsl #2
ldr w14, [x13]
cmp w14, #2
b.lt .LBB0_2
add x15, x10, w11, sxtw #2
.LBB0_9:
ldrsw x16, [x15], #4
sub w14, w14, #1
str w14, [x13]
add w12, w12, #1
add w11, w11, #1
add x13, x22, x16, lsl #2
ldr w14, [x13]
cmp w14, #1
b.gt .LBB0_9
b .LBB0_2
.LBB0_10:
mov w0, wzr
.LBB0_11:
add sp, sp, #19, lsl #12
add sp, sp, #2192
ldp x20, x19, [sp, #48]
ldr x28, [sp, #16]
ldp x22, x21, [sp, #32]
ldp x29, x30, [sp], #64
ret
|
13,926
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O2
|
armv8-a clang 21.1.0
|
subarraysWithKDistinct:
stp x29, x30, [sp, #-64]!
str x28, [sp, #16]
stp x22, x21, [sp, #32]
stp x20, x19, [sp, #48]
mov x29, sp
sub sp, sp, #19, lsl #12
sub sp, sp, #2192
mov w20, w2
mov w2, #14468
mov w21, w1
mov x19, x0
add x0, sp, #12
mov w1, wzr
movk w2, #1, lsl #16
add x22, sp, #12
bl memset
cmp w21, #1
b.lt .LBB0_10
mov x8, xzr
mov w0, wzr
mov w11, wzr
mov w9, w21
add x10, x19, #4
mov w12, #1
b .LBB0_4
.LBB0_2:
mov w20, wzr
add w0, w12, w0
.LBB0_3:
add x8, x8, #1
cmp x8, x9
b.eq .LBB0_11
.LBB0_4:
ldrsw x13, [x19, x8, lsl #2]
ldr w14, [x22, x13, lsl #2]
cmp w14, #0
add w14, w14, #1
str w14, [x22, x13, lsl #2]
cset w15, eq
subs w20, w20, w15
b.mi .LBB0_6
cbnz w20, .LBB0_3
b .LBB0_7
.LBB0_6:
ldrsw x12, [x19, w11, sxtw #2]
add w11, w11, #1
str wzr, [x22, x12, lsl #2]
mov w12, #1
.LBB0_7:
ldrsw x13, [x19, w11, sxtw #2]
add x13, x22, x13, lsl #2
ldr w14, [x13]
cmp w14, #2
b.lt .LBB0_2
sxtw x15, w11
add x15, x10, x15, lsl #2
.LBB0_9:
ldrsw x16, [x15], #4
sub w14, w14, #1
str w14, [x13]
add w12, w12, #1
add w11, w11, #1
add x13, x22, x16, lsl #2
ldr w14, [x13]
cmp w14, #1
b.gt .LBB0_9
b .LBB0_2
.LBB0_10:
mov w0, wzr
.LBB0_11:
add sp, sp, #19, lsl #12
add sp, sp, #2192
ldp x20, x19, [sp, #48]
ldr x28, [sp, #16]
ldp x22, x21, [sp, #32]
ldp x29, x30, [sp], #64
ret
|
13,927
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
aarch64
|
-O3
|
armv8-a clang 21.1.0
|
subarraysWithKDistinct:
stp x29, x30, [sp, #-64]!
str x28, [sp, #16]
stp x22, x21, [sp, #32]
stp x20, x19, [sp, #48]
mov x29, sp
sub sp, sp, #19, lsl #12
sub sp, sp, #2192
mov w20, w2
mov w2, #14468
mov w21, w1
mov x19, x0
add x0, sp, #12
mov w1, wzr
movk w2, #1, lsl #16
add x22, sp, #12
bl memset
cmp w21, #1
b.lt .LBB0_10
mov x8, xzr
mov w0, wzr
mov w11, wzr
mov w9, w21
add x10, x19, #4
mov w12, #1
b .LBB0_4
.LBB0_2:
mov w20, wzr
add w0, w12, w0
.LBB0_3:
add x8, x8, #1
cmp x8, x9
b.eq .LBB0_11
.LBB0_4:
ldrsw x13, [x19, x8, lsl #2]
ldr w14, [x22, x13, lsl #2]
cmp w14, #0
add w14, w14, #1
str w14, [x22, x13, lsl #2]
cset w15, eq
subs w20, w20, w15
b.mi .LBB0_7
cbnz w20, .LBB0_3
ldrsw x13, [x19, w11, sxtw #2]
add x13, x22, x13, lsl #2
ldr w14, [x13]
cmp w14, #2
b.lt .LBB0_2
b .LBB0_8
.LBB0_7:
ldrsw x12, [x19, w11, sxtw #2]
add w11, w11, #1
str wzr, [x22, x12, lsl #2]
mov w12, #1
ldrsw x13, [x19, w11, sxtw #2]
add x13, x22, x13, lsl #2
ldr w14, [x13]
cmp w14, #2
b.lt .LBB0_2
.LBB0_8:
sxtw x15, w11
add x15, x10, x15, lsl #2
.LBB0_9:
ldrsw x16, [x15], #4
sub w14, w14, #1
str w14, [x13]
add w12, w12, #1
add w11, w11, #1
add x13, x22, x16, lsl #2
ldr w14, [x13]
cmp w14, #1
b.gt .LBB0_9
b .LBB0_2
.LBB0_10:
mov w0, wzr
.LBB0_11:
add sp, sp, #19, lsl #12
add sp, sp, #2192
ldp x20, x19, [sp, #48]
ldr x28, [sp, #16]
ldp x22, x21, [sp, #32]
ldp x29, x30, [sp], #64
ret
|
13,928
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O0
|
mips64 clang 21.1.0
|
subarraysWithKDistinct:
.Lfunc_begin0 = .Ltmp0
lui $1, 1
daddiu $1, $1, 14544
dsubu $sp, $sp, $1
lui $1, 1
daddu $1, $sp, $1
sd $ra, 14536($1)
lui $1, 1
daddu $1, $sp, $1
sd $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
sd $gp, 14520($1)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $1, $1, $25
daddiu $gp, $1, %lo(%neg(%gp_rel(subarraysWithKDistinct)))
move $1, $6
move $2, $5
lui $3, 1
daddu $3, $fp, $3
sd $4, 14512($3)
lui $3, 1
daddu $3, $fp, $3
sw $2, 14508($3)
lui $2, 1
daddu $2, $fp, $2
sw $1, 14504($2)
ld $25, %call16(memset)($gp)
lui $1, 1
ori $6, $1, 14468
daddiu $4, $fp, 36
daddiu $5, $zero, 0
jalr $25
nop
sw $zero, 28($fp)
sw $zero, 24($fp)
addiu $1, $zero, 1
sw $1, 20($fp)
sw $zero, 16($fp)
b .LBB0_1
nop
.LBB0_1:
lw $1, 24($fp)
lui $2, 1
daddu $2, $fp, $2
lw $2, 14508($2)
slt $1, $1, $2
beqz $1, .LBB0_17
nop
b .LBB0_3
nop
.LBB0_3:
lui $1, 1
daddu $1, $fp, $1
ld $1, 14512($1)
lw $2, 24($fp)
addiu $3, $2, 1
sw $3, 24($fp)
sll $2, $2, 0
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
sw $1, 32($fp)
lw $1, 32($fp)
dsll $2, $1, 2
daddiu $1, $fp, 36
daddu $1, $1, $2
lw $1, 0($1)
bnez $1, .LBB0_6
nop
b .LBB0_5
nop
.LBB0_5:
lui $1, 1
daddu $1, $fp, $1
lw $1, 14504($1)
addiu $1, $1, -1
lui $2, 1
daddu $2, $fp, $2
sw $1, 14504($2)
b .LBB0_6
nop
.LBB0_6:
lw $1, 32($fp)
dsll $2, $1, 2
daddiu $1, $fp, 36
daddu $2, $1, $2
lw $1, 0($2)
addiu $1, $1, 1
sw $1, 0($2)
lui $1, 1
daddu $1, $fp, $1
lw $1, 14504($1)
bgez $1, .LBB0_9
nop
b .LBB0_8
nop
.LBB0_8:
lui $1, 1
daddu $1, $fp, $1
ld $1, 14512($1)
lw $2, 28($fp)
addiu $3, $2, 1
sw $3, 28($fp)
sll $2, $2, 0
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
sw $1, 32($fp)
lw $1, 32($fp)
dsll $2, $1, 2
daddiu $1, $fp, 36
daddu $1, $1, $2
sw $zero, 0($1)
lui $1, 1
daddu $1, $fp, $1
sw $zero, 14504($1)
addiu $1, $zero, 1
sw $1, 20($fp)
b .LBB0_9
nop
.LBB0_9:
lui $1, 1
daddu $1, $fp, $1
lw $1, 14504($1)
bnez $1, .LBB0_16
nop
b .LBB0_11
nop
.LBB0_11:
b .LBB0_12
nop
.LBB0_12:
lui $1, 1
daddu $1, $fp, $1
ld $1, 14512($1)
lw $2, 28($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
dsll $2, $1, 2
daddiu $1, $fp, 36
daddu $1, $1, $2
lw $1, 0($1)
slti $1, $1, 2
bnez $1, .LBB0_15
nop
b .LBB0_14
nop
.LBB0_14:
lui $1, 1
daddu $1, $fp, $1
ld $1, 14512($1)
lw $2, 28($fp)
addiu $3, $2, 1
sw $3, 28($fp)
sll $2, $2, 0
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
sw $1, 32($fp)
lw $1, 32($fp)
dsll $2, $1, 2
daddiu $1, $fp, 36
daddu $2, $1, $2
lw $1, 0($2)
addiu $1, $1, -1
sw $1, 0($2)
lw $1, 20($fp)
addiu $1, $1, 1
sw $1, 20($fp)
b .LBB0_12
nop
.LBB0_15:
lw $2, 20($fp)
lw $1, 16($fp)
addu $1, $1, $2
sw $1, 16($fp)
b .LBB0_16
nop
.LBB0_16:
b .LBB0_1
nop
.LBB0_17:
lw $2, 16($fp)
move $sp, $fp
lui $1, 1
daddu $1, $sp, $1
ld $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
ld $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
ld $ra, 14536($1)
lui $1, 1
daddiu $1, $1, 14544
daddu $sp, $sp, $1
jr $ra
nop
|
13,929
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O1
|
mips64 clang 21.1.0
|
subarraysWithKDistinct:
.Lfunc_begin0 = .Ltmp0
lui $1, 1
daddiu $1, $1, 14544
dsubu $sp, $sp, $1
lui $1, 1
daddu $1, $sp, $1
sd $ra, 14536($1)
lui $1, 1
daddu $1, $sp, $1
sd $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
sd $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
sd $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
sd $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
sd $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
sd $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
sd $16, 14480($1)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $1, $1, $25
daddiu $gp, $1, %lo(%neg(%gp_rel(subarraysWithKDistinct)))
move $18, $6
move $19, $5
move $16, $4
lui $1, 1
ori $6, $1, 14468
daddiu $17, $fp, 12
daddiu $20, $zero, 0
ld $25, %call16(memset)($gp)
move $4, $17
jalr $25
daddiu $5, $zero, 0
blez $19, .LBB0_12
nop
daddiu $3, $16, 4
sll $4, $19, 0
addiu $6, $zero, 1
addiu $2, $zero, 0
b .LBB0_4
addiu $5, $zero, 0
.LBB0_2:
addu $2, $6, $2
.LBB0_3:
daddiu $20, $20, 1
beq $20, $4, .LBB0_13
nop
.LBB0_4:
dsll $1, $20, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
lw $7, 0($1)
addiu $8, $7, 1
sw $8, 0($1)
sltiu $1, $7, 1
subu $18, $18, $1
bltz $18, .LBB0_7
nop
bnez $18, .LBB0_3
nop
b .LBB0_8
nop
.LBB0_7:
sll $1, $5, 0
dsll $1, $1, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
sw $zero, 0($1)
addiu $5, $5, 1
addiu $18, $zero, 0
bnez $18, .LBB0_3
addiu $6, $zero, 1
.LBB0_8:
sll $1, $5, 0
dsll $8, $1, 2
daddu $1, $16, $8
lw $1, 0($1)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
bnez $1, .LBB0_2
nop
daddu $8, $3, $8
.LBB0_10:
addiu $1, $9, -1
sw $1, 0($7)
lw $1, 0($8)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
daddiu $8, $8, 4
addiu $5, $5, 1
beqz $1, .LBB0_10
addiu $6, $6, 1
b .LBB0_2
nop
.LBB0_12:
addiu $2, $zero, 0
.LBB0_13:
sll $2, $2, 0
move $sp, $fp
lui $1, 1
daddu $1, $sp, $1
ld $16, 14480($1)
lui $1, 1
daddu $1, $sp, $1
ld $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
ld $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
ld $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
ld $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
ld $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
ld $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
ld $ra, 14536($1)
lui $1, 1
daddiu $1, $1, 14544
jr $ra
daddu $sp, $sp, $1
|
13,930
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O2
|
mips64 clang 21.1.0
|
subarraysWithKDistinct:
.Lfunc_begin0 = .Ltmp0
lui $1, 1
daddiu $1, $1, 14544
dsubu $sp, $sp, $1
lui $1, 1
daddu $1, $sp, $1
sd $ra, 14536($1)
lui $1, 1
daddu $1, $sp, $1
sd $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
sd $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
sd $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
sd $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
sd $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
sd $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
sd $16, 14480($1)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $1, $1, $25
daddiu $gp, $1, %lo(%neg(%gp_rel(subarraysWithKDistinct)))
move $18, $6
move $19, $5
move $16, $4
lui $1, 1
ori $6, $1, 14468
daddiu $17, $fp, 12
daddiu $20, $zero, 0
ld $25, %call16(memset)($gp)
move $4, $17
jalr $25
daddiu $5, $zero, 0
blez $19, .LBB0_12
nop
daddiu $3, $16, 4
sll $4, $19, 0
addiu $6, $zero, 1
addiu $2, $zero, 0
b .LBB0_4
addiu $5, $zero, 0
.LBB0_2:
addu $2, $6, $2
addiu $18, $zero, 0
.LBB0_3:
daddiu $20, $20, 1
beq $20, $4, .LBB0_13
nop
.LBB0_4:
dsll $1, $20, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
lw $7, 0($1)
addiu $8, $7, 1
sw $8, 0($1)
sltiu $1, $7, 1
subu $18, $18, $1
bltz $18, .LBB0_7
nop
bnez $18, .LBB0_3
nop
b .LBB0_8
nop
.LBB0_7:
sll $1, $5, 0
dsll $1, $1, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
sw $zero, 0($1)
addiu $5, $5, 1
addiu $6, $zero, 1
.LBB0_8:
sll $1, $5, 0
dsll $8, $1, 2
daddu $1, $16, $8
lw $1, 0($1)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
bnez $1, .LBB0_2
nop
daddu $8, $3, $8
.LBB0_10:
addiu $1, $9, -1
sw $1, 0($7)
lw $1, 0($8)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
daddiu $8, $8, 4
addiu $5, $5, 1
beqz $1, .LBB0_10
addiu $6, $6, 1
b .LBB0_2
nop
.LBB0_12:
addiu $2, $zero, 0
.LBB0_13:
sll $2, $2, 0
move $sp, $fp
lui $1, 1
daddu $1, $sp, $1
ld $16, 14480($1)
lui $1, 1
daddu $1, $sp, $1
ld $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
ld $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
ld $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
ld $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
ld $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
ld $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
ld $ra, 14536($1)
lui $1, 1
daddiu $1, $1, 14544
jr $ra
daddu $sp, $sp, $1
|
13,931
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O3
|
mips64 clang 21.1.0
|
subarraysWithKDistinct:
.Lfunc_begin0 = .Ltmp0
lui $1, 1
daddiu $1, $1, 14544
dsubu $sp, $sp, $1
lui $1, 1
daddu $1, $sp, $1
sd $ra, 14536($1)
lui $1, 1
daddu $1, $sp, $1
sd $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
sd $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
sd $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
sd $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
sd $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
sd $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
sd $16, 14480($1)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddiu $17, $fp, 12
move $19, $5
move $16, $4
move $18, $6
daddiu $5, $zero, 0
daddiu $20, $zero, 0
daddu $1, $1, $25
move $4, $17
daddiu $gp, $1, %lo(%neg(%gp_rel(subarraysWithKDistinct)))
lui $1, 1
ld $25, %call16(memset)($gp)
jalr $25
ori $6, $1, 14468
blez $19, .LBB0_12
nop
daddiu $3, $16, 4
sll $4, $19, 0
addiu $6, $zero, 1
addiu $2, $zero, 0
b .LBB0_4
addiu $5, $zero, 0
.LBB0_2:
addu $2, $6, $2
addiu $18, $zero, 0
.LBB0_3:
daddiu $20, $20, 1
beq $20, $4, .LBB0_13
nop
.LBB0_4:
dsll $1, $20, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
lw $7, 0($1)
addiu $8, $7, 1
sw $8, 0($1)
sltiu $1, $7, 1
subu $18, $18, $1
bltz $18, .LBB0_7
nop
bnez $18, .LBB0_3
nop
b .LBB0_8
nop
.LBB0_7:
sll $1, $5, 0
addiu $5, $5, 1
addiu $6, $zero, 1
dsll $1, $1, 2
daddu $1, $16, $1
lw $1, 0($1)
dsll $1, $1, 2
daddu $1, $17, $1
sw $zero, 0($1)
.LBB0_8:
sll $1, $5, 0
dsll $8, $1, 2
daddu $1, $16, $8
lw $1, 0($1)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
bnez $1, .LBB0_2
nop
daddu $8, $3, $8
.LBB0_10:
addiu $1, $9, -1
addiu $5, $5, 1
addiu $6, $6, 1
sw $1, 0($7)
lw $1, 0($8)
dsll $1, $1, 2
daddu $7, $17, $1
lw $9, 0($7)
slti $1, $9, 2
beqz $1, .LBB0_10
daddiu $8, $8, 4
b .LBB0_2
nop
.LBB0_12:
addiu $2, $zero, 0
.LBB0_13:
sll $2, $2, 0
move $sp, $fp
lui $1, 1
daddu $1, $sp, $1
ld $16, 14480($1)
lui $1, 1
daddu $1, $sp, $1
ld $17, 14488($1)
lui $1, 1
daddu $1, $sp, $1
ld $18, 14496($1)
lui $1, 1
daddu $1, $sp, $1
ld $19, 14504($1)
lui $1, 1
daddu $1, $sp, $1
ld $20, 14512($1)
lui $1, 1
daddu $1, $sp, $1
ld $gp, 14520($1)
lui $1, 1
daddu $1, $sp, $1
ld $fp, 14528($1)
lui $1, 1
daddu $1, $sp, $1
ld $ra, 14536($1)
lui $1, 1
daddiu $1, $1, 14544
jr $ra
daddu $sp, $sp, $1
|
13,932
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O0
|
mips64 gcc 15.2.0
|
subarraysWithKDistinct:
daddiu $sp,$sp,-32752
sd $31,32744($sp)
sd $fp,32736($sp)
sd $28,32728($sp)
li $3,47328 # 0xb8e0
dsubu $sp,$sp,$3
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(subarraysWithKDistinct)))
li $2,65536 # 0x10000
daddu $2,$fp,$2
sd $4,14496($2)
move $3,$5
move $2,$6
sll $3,$3,0
li $4,65536 # 0x10000
daddu $4,$fp,$4
sw $3,14504($4)
sll $2,$2,0
li $3,65536 # 0x10000
daddu $3,$fp,$3
sw $2,14508($3)
daddiu $3,$fp,24
li $2,65536 # 0x10000
ori $2,$2,0x3884
move $6,$2
move $5,$0
move $4,$3
ld $2,%call16(memset)($28)
mtlo $2
mflo $25
jalr $25
nop
sw $0,0($fp)
sw $0,4($fp)
li $2,1 # 0x1
sw $2,8($fp)
sw $0,12($fp)
b .L2
nop
.L7:
lw $2,4($fp)
addiu $3,$2,1
sw $3,4($fp)
dsll $2,$2,2
li $3,65536 # 0x10000
daddu $3,$fp,$3
ld $3,14496($3)
daddu $2,$3,$2
lw $2,0($2)
sw $2,16($fp)
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $2,24($2)
bne $2,$0,.L3
nop
li $2,65536 # 0x10000
daddu $3,$fp,$2
li $2,65536 # 0x10000
daddu $2,$fp,$2
lw $2,14508($2)
addiu $2,$2,-1
sw $2,14508($3)
.L3:
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $2,24($2)
addiu $2,$2,1
move $3,$2
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
sw $3,24($2)
li $2,65536 # 0x10000
daddu $2,$fp,$2
lw $2,14508($2)
bgez $2,.L4
nop
lw $2,0($fp)
addiu $3,$2,1
sw $3,0($fp)
dsll $2,$2,2
li $3,65536 # 0x10000
daddu $3,$fp,$3
ld $3,14496($3)
daddu $2,$3,$2
lw $2,0($2)
sw $2,16($fp)
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
sw $0,24($2)
li $2,65536 # 0x10000
daddu $2,$fp,$2
sw $0,14508($2)
li $2,1 # 0x1
sw $2,8($fp)
.L4:
li $2,65536 # 0x10000
daddu $2,$fp,$2
lw $2,14508($2)
bne $2,$0,.L2
nop
b .L5
nop
.L6:
lw $2,0($fp)
addiu $3,$2,1
sw $3,0($fp)
dsll $2,$2,2
li $3,65536 # 0x10000
daddu $3,$fp,$3
ld $3,14496($3)
daddu $2,$3,$2
lw $2,0($2)
sw $2,16($fp)
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
lw $2,24($2)
addiu $2,$2,-1
move $3,$2
lw $2,16($fp)
dsll $2,$2,2
daddu $2,$fp,$2
sw $3,24($2)
lw $2,8($fp)
addiu $2,$2,1
sw $2,8($fp)
.L5:
lw $2,0($fp)
dsll $2,$2,2
li $3,65536 # 0x10000
daddu $3,$fp,$3
ld $3,14496($3)
daddu $2,$3,$2
lw $2,0($2)
dsll $2,$2,2
daddu $2,$fp,$2
lw $2,24($2)
slt $2,$2,2
beq $2,$0,.L6
nop
lw $3,12($fp)
lw $2,8($fp)
addu $2,$3,$2
sw $2,12($fp)
.L2:
li $2,65536 # 0x10000
daddu $2,$fp,$2
lw $3,4($fp)
lw $2,14504($2)
slt $2,$3,$2
bne $2,$0,.L7
nop
lw $2,12($fp)
li $8,47328 # 0xb8e0
daddu $sp,$fp,$8
ld $31,32744($sp)
ld $fp,32736($sp)
ld $28,32728($sp)
daddiu $sp,$sp,32752
jr $31
nop
|
13,933
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O1
|
mips64 gcc 15.2.0
|
subarraysWithKDistinct:
daddiu $sp,$sp,-32752
sd $31,32744($sp)
sd $28,32736($sp)
sd $18,32728($sp)
sd $17,32720($sp)
sd $16,32712($sp)
li $3,47312 # 0xb8d0
dsubu $sp,$sp,$3
lui $28,%hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(subarraysWithKDistinct)))
move $16,$4
move $18,$5
move $17,$6
li $6,65536 # 0x10000
daddiu $6,$6,14468
move $5,$0
ld $25,%call16(memset)($28)
1: jalr $25
move $4,$sp
blez $18,.L10
dsll $12,$18,2
daddu $12,$12,$16
move $8,$16
move $2,$0
li $9,1 # 0x1
move $4,$0
move $11,$0
b .L9
li $10,1 # 0x1
.L3:
dsll $3,$3,2
.L17:
daddu $3,$sp,$3
addiu $5,$5,1
bltz $17,.L15
sw $5,0($3)
beq $17,$0,.L5
move $13,$4
.L6:
daddiu $8,$8,4
beql $8,$12,.L18
li $8,47312 # 0xb8d0
.L9:
lw $3,0($8)
dsll $5,$3,2
daddu $5,$sp,$5
lw $5,0($5)
beql $5,$0,.L3
addiu $17,$17,-1
b .L17
dsll $3,$3,2
.L15:
addiu $13,$4,1
dsll $4,$4,2
daddu $4,$16,$4
lw $3,0($4)
dsll $3,$3,2
daddu $3,$sp,$3
sw $0,0($3)
move $9,$10
.L5:
dsll $6,$13,2
daddu $3,$16,$6
lw $3,0($3)
dsll $4,$3,2
daddu $4,$sp,$4
lw $5,0($4)
slt $4,$5,2
bne $4,$0,.L7
move $4,$13
daddu $6,$16,$6
.L8:
addiu $4,$4,1
dsll $3,$3,2
daddu $3,$sp,$3
addiu $5,$5,-1
sw $5,0($3)
lw $3,4($6)
dsll $5,$3,2
daddu $5,$sp,$5
lw $5,0($5)
slt $7,$5,2
beq $7,$0,.L8
daddiu $6,$6,4
subu $9,$9,$13
addu $9,$9,$4
.L7:
addu $2,$9,$2
b .L6
move $17,$11
b .L7
move $4,$13
.L10:
move $2,$0
li $8,47312 # 0xb8d0
.L18:
daddu $sp,$sp,$8
ld $31,32744($sp)
ld $28,32736($sp)
ld $18,32728($sp)
ld $17,32720($sp)
ld $16,32712($sp)
jr $31
daddiu $sp,$sp,32752
|
13,934
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O2
|
mips64 gcc 15.2.0
|
subarraysWithKDistinct:
daddiu $sp,$sp,-32752
sd $28,32736($sp)
lui $28,%hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(subarraysWithKDistinct)))
ld $25,%call16(memset)($28)
li $3,47312 # 0xb8d0
sd $18,32728($sp)
sd $17,32720($sp)
sd $16,32712($sp)
sd $31,32744($sp)
move $16,$6
dsubu $sp,$sp,$3
li $6,65536 # 0x10000
move $17,$4
move $18,$5
daddiu $6,$6,14468
move $5,$0
1: jalr $25
move $4,$sp
blez $18,.L11
dsll $10,$18,32
lw $3,0($17)
dsrl $10,$10,32
dsll $3,$3,2
daddu $2,$sp,$3
lw $7,0($2)
dsll $10,$10,2
beq $7,$0,.L21
daddu $10,$17,$10
move $4,$7
move $9,$17
move $2,$0
li $11,1 # 0x1
move $7,$0
.L3:
daddu $3,$sp,$3
addiu $4,$4,1
bgez $16,.L4
sw $4,0($3)
dsll $3,$7,2
daddu $3,$17,$3
lw $3,0($3)
addiu $12,$7,1
li $11,1 # 0x1
dsll $3,$3,2
daddu $3,$sp,$3
sw $0,0($3)
.L7:
dsll $4,$12,2
daddu $4,$17,$4
lw $6,0($4)
dsll $5,$6,2
daddu $3,$sp,$5
lw $3,0($3)
slt $6,$3,2
bne $6,$0,.L6
move $7,$12
.L9:
lw $6,4($4)
daddu $8,$sp,$5
addiu $3,$3,-1
dsll $5,$6,2
sw $3,0($8)
daddu $3,$sp,$5
lw $3,0($3)
addiu $7,$7,1
slt $6,$3,2
beq $6,$0,.L9
daddiu $4,$4,4
subu $11,$11,$12
addu $11,$11,$7
.L6:
addu $2,$11,$2
move $16,$0
daddiu $9,$9,4
.L24:
beq $9,$10,.L22
li $8,47312 # 0xb8d0
lw $3,0($9)
dsll $3,$3,2
daddu $5,$sp,$3
lw $4,0($5)
beql $4,$0,.L23
addiu $16,$16,-1
addiu $4,$4,1
sw $4,0($5)
.L4:
bnel $16,$0,.L24
daddiu $9,$9,4
b .L7
move $12,$7
.L21:
move $2,$0
move $9,$17
li $11,1 # 0x1
addiu $16,$16,-1
.L23:
b .L3
move $4,$0
.L11:
move $2,$0
li $8,47312 # 0xb8d0
.L22:
daddu $sp,$sp,$8
ld $31,32744($sp)
ld $28,32736($sp)
ld $18,32728($sp)
ld $17,32720($sp)
ld $16,32712($sp)
jr $31
daddiu $sp,$sp,32752
|
13,935
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
mips64
|
-O3
|
mips64 gcc 15.2.0
|
subarraysWithKDistinct:
daddiu $sp,$sp,-32752
sd $28,32736($sp)
lui $28,%hi(%neg(%gp_rel(subarraysWithKDistinct)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(subarraysWithKDistinct)))
ld $25,%call16(memset)($28)
li $3,47312 # 0xb8d0
sd $18,32728($sp)
sd $17,32720($sp)
sd $16,32712($sp)
sd $31,32744($sp)
move $16,$6
dsubu $sp,$sp,$3
li $6,65536 # 0x10000
move $17,$4
move $18,$5
daddiu $6,$6,14468
move $5,$0
1: jalr $25
move $4,$sp
blez $18,.L11
dsll $10,$18,32
lw $3,0($17)
dsrl $10,$10,32
dsll $3,$3,2
daddu $2,$sp,$3
lw $7,0($2)
dsll $10,$10,2
beq $7,$0,.L21
daddu $10,$17,$10
move $4,$7
move $9,$17
move $2,$0
li $11,1 # 0x1
move $7,$0
.L3:
daddu $3,$sp,$3
addiu $4,$4,1
bgez $16,.L4
sw $4,0($3)
dsll $3,$7,2
daddu $3,$17,$3
lw $3,0($3)
addiu $12,$7,1
li $11,1 # 0x1
dsll $3,$3,2
daddu $3,$sp,$3
sw $0,0($3)
.L7:
dsll $4,$12,2
daddu $4,$17,$4
lw $6,0($4)
dsll $5,$6,2
daddu $3,$sp,$5
lw $3,0($3)
slt $6,$3,2
bne $6,$0,.L6
move $7,$12
.L9:
lw $6,4($4)
daddu $8,$sp,$5
addiu $3,$3,-1
dsll $5,$6,2
sw $3,0($8)
daddu $3,$sp,$5
lw $3,0($3)
addiu $7,$7,1
slt $6,$3,2
beq $6,$0,.L9
daddiu $4,$4,4
subu $11,$11,$12
addu $11,$11,$7
.L6:
addu $2,$2,$11
move $16,$0
daddiu $9,$9,4
.L24:
beq $10,$9,.L22
li $8,47312 # 0xb8d0
lw $3,0($9)
dsll $3,$3,2
daddu $5,$sp,$3
lw $4,0($5)
beql $4,$0,.L23
addiu $16,$16,-1
addiu $4,$4,1
sw $4,0($5)
.L4:
bnel $16,$0,.L24
daddiu $9,$9,4
b .L7
move $12,$7
.L21:
move $9,$17
move $2,$0
li $11,1 # 0x1
addiu $16,$16,-1
.L23:
b .L3
move $4,$0
.L11:
move $2,$0
li $8,47312 # 0xb8d0
.L22:
daddu $sp,$sp,$8
ld $31,32744($sp)
ld $28,32736($sp)
ld $18,32728($sp)
ld $17,32720($sp)
ld $16,32712($sp)
jr $31
daddiu $sp,$sp,32752
|
13,936
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O0
|
RISC-V 64 clang 21.1.0
|
subarraysWithKDistinct:
addi sp, sp, -496
sd ra, 488(sp)
sd s0, 480(sp)
addi s0, sp, 496
lui a3, 19
addi a3, a3, 1760
sub sp, sp, a3
lui a3, 20
addi a3, a3, -1856
sub a3, s0, a3
lui a4, 20
sub a4, s0, a4
sd a3, 1840(a4)
sd a0, -32(s0)
sw a1, -36(s0)
sw a2, -40(s0)
lui a0, 20
addi a2, a0, -1916
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
li a1, 0
lui a3, 20
sub a3, s0, a3
sd a1, 1848(a3)
call memset
lui a1, 20
sub a1, s0, a1
ld a1, 1840(a1)
lui a0, 20
sub a0, s0, a0
ld a0, 1848(a0)
sw a0, 12(a1)
sw a0, 8(a1)
li a2, 1
sw a2, 4(a1)
sw a0, 0(a1)
j .LBB0_1
.LBB0_1:
lui a0, 20
sub a0, s0, a0
ld a0, 1840(a0)
lw a0, 8(a0)
lw a1, -36(s0)
bge a0, a1, .LBB0_12
j .LBB0_2
.LBB0_2:
lui a0, 20
sub a0, s0, a0
ld a0, 1840(a0)
ld a1, -32(s0)
lw a2, 8(a0)
addiw a3, a2, 1
sw a3, 8(a0)
slli a2, a2, 2
add a1, a1, a2
lw a1, 0(a1)
sw a1, 16(a0)
lw a0, 16(a0)
slli a1, a0, 2
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
add a0, a0, a1
lw a0, 0(a0)
bnez a0, .LBB0_4
j .LBB0_3
.LBB0_3:
lw a0, -40(s0)
addiw a0, a0, -1
sw a0, -40(s0)
j .LBB0_4
.LBB0_4:
lui a0, 20
sub a0, s0, a0
ld a0, 1840(a0)
lw a0, 16(a0)
slli a1, a0, 2
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
add a1, a1, a0
lw a0, 0(a1)
addiw a0, a0, 1
sw a0, 0(a1)
lw a0, -40(s0)
bgez a0, .LBB0_6
j .LBB0_5
.LBB0_5:
lui a0, 20
sub a0, s0, a0
ld a1, 1840(a0)
ld a0, -32(s0)
lw a2, 12(a1)
addiw a3, a2, 1
sw a3, 12(a1)
slli a2, a2, 2
add a0, a0, a2
lw a0, 0(a0)
sw a0, 16(a1)
lw a0, 16(a1)
slli a2, a0, 2
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
add a2, a2, a0
li a0, 0
sw a0, 0(a2)
sw a0, -40(s0)
li a0, 1
sw a0, 4(a1)
j .LBB0_6
.LBB0_6:
lw a0, -40(s0)
bnez a0, .LBB0_11
j .LBB0_7
.LBB0_7:
j .LBB0_8
.LBB0_8:
lui a0, 20
sub a0, s0, a0
ld a1, 1840(a0)
ld a0, -32(s0)
lw a1, 12(a1)
slli a1, a1, 2
add a0, a0, a1
lw a0, 0(a0)
slli a1, a0, 2
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
add a0, a0, a1
lw a0, 0(a0)
li a1, 2
blt a0, a1, .LBB0_10
j .LBB0_9
.LBB0_9:
lui a0, 20
sub a0, s0, a0
ld a1, 1840(a0)
ld a0, -32(s0)
lw a2, 12(a1)
addiw a3, a2, 1
sw a3, 12(a1)
slli a2, a2, 2
add a0, a0, a2
lw a0, 0(a0)
sw a0, 16(a1)
lw a0, 16(a1)
slli a2, a0, 2
lui a0, 20
addi a0, a0, -1876
sub a0, s0, a0
add a2, a2, a0
lw a0, 0(a2)
addiw a0, a0, -1
sw a0, 0(a2)
lw a0, 4(a1)
addiw a0, a0, 1
sw a0, 4(a1)
j .LBB0_8
.LBB0_10:
lui a0, 20
sub a0, s0, a0
ld a1, 1840(a0)
lw a2, 4(a1)
lw a0, 0(a1)
addw a0, a0, a2
sw a0, 0(a1)
j .LBB0_11
.LBB0_11:
j .LBB0_1
.LBB0_12:
lui a0, 20
sub a0, s0, a0
ld a0, 1840(a0)
lw a0, 0(a0)
lui a1, 19
addi a1, a1, 1760
add sp, sp, a1
ld ra, 488(sp)
ld s0, 480(sp)
addi sp, sp, 496
ret
|
13,937
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O1
|
RISC-V 64 clang 21.1.0
|
subarraysWithKDistinct:
addi sp, sp, -496
sd ra, 488(sp)
sd s0, 480(sp)
sd s1, 472(sp)
sd s2, 464(sp)
sd s3, 456(sp)
sd s4, 448(sp)
sd s5, 440(sp)
lui a3, 19
addi a3, a3, 1760
sub sp, sp, a3
mv s5, a2
mv s2, a1
mv s3, a0
lui a0, 20
addi a2, a0, -1916
addi a0, sp, 20
addi s4, sp, 20
li a1, 0
call memset
blez s2, .LBB0_10
li a1, 0
li a0, 0
li a5, 0
addi a7, s3, 4
li t0, 1
li a6, 2
li a4, 1
j .LBB0_4
.LBB0_2:
addw a0, a0, a4
.LBB0_3:
addi a1, a1, 1
beq a1, s2, .LBB0_11
.LBB0_4:
slli a2, a1, 2
add a2, a2, s3
lw a2, 0(a2)
slli a2, a2, 2
add a2, a2, s4
lw a3, 0(a2)
seqz s0, a3
subw s5, s5, s0
addi a3, a3, 1
sw a3, 0(a2)
bltz s5, .LBB0_6
bnez s5, .LBB0_3
j .LBB0_7
.LBB0_6:
li s5, 0
slli a2, a5, 2
add a2, a2, s3
lw a2, 0(a2)
addiw a5, a5, 1
slli a2, a2, 2
add a2, a2, s4
sw zero, 0(a2)
li a4, 1
bnez s5, .LBB0_3
.LBB0_7:
slli a2, a5, 2
add a3, s3, a2
lw a3, 0(a3)
slli a3, a3, 2
add s0, s4, a3
lw a3, 0(s0)
blt a3, a6, .LBB0_2
add a2, a2, a7
.LBB0_9:
lw s1, 0(a2)
addi a3, a3, -1
sw a3, 0(s0)
slli s0, s1, 2
add s0, s0, s4
lw a3, 0(s0)
addi a4, a4, 1
addiw a5, a5, 1
addi a2, a2, 4
blt t0, a3, .LBB0_9
j .LBB0_2
.LBB0_10:
li a0, 0
.LBB0_11:
lui a1, 19
addi a1, a1, 1760
add sp, sp, a1
ld ra, 488(sp)
ld s0, 480(sp)
ld s1, 472(sp)
ld s2, 464(sp)
ld s3, 456(sp)
ld s4, 448(sp)
ld s5, 440(sp)
addi sp, sp, 496
ret
|
13,938
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O2
|
RISC-V 64 clang 21.1.0
|
subarraysWithKDistinct:
addi sp, sp, -496
sd ra, 488(sp)
sd s0, 480(sp)
sd s1, 472(sp)
sd s2, 464(sp)
sd s3, 456(sp)
sd s4, 448(sp)
lui a3, 19
addi a3, a3, 1744
sub sp, sp, a3
mv s0, a2
mv s2, a1
mv s3, a0
lui a0, 20
addi a2, a0, -1916
addi a0, sp, 12
addi s4, sp, 12
li a1, 0
call memset
blez s2, .LBB0_10
li a1, 0
li a0, 0
li a4, 0
addi a7, s3, 4
li t0, 1
li a6, 2
li a5, 1
j .LBB0_4
.LBB0_2:
li s0, 0
addw a0, a0, a5
.LBB0_3:
addi a1, a1, 1
beq a1, s2, .LBB0_11
.LBB0_4:
slli a2, a1, 2
add a2, a2, s3
lw a2, 0(a2)
slli a2, a2, 2
add a2, a2, s4
lw s1, 0(a2)
seqz a3, s1
subw s0, s0, a3
addi s1, s1, 1
sw s1, 0(a2)
bltz s0, .LBB0_6
bnez s0, .LBB0_3
j .LBB0_7
.LBB0_6:
slli a2, a4, 2
add a2, a2, s3
lw a2, 0(a2)
addiw a4, a4, 1
slli a2, a2, 2
add a2, a2, s4
sw zero, 0(a2)
li a5, 1
.LBB0_7:
slli a2, a4, 2
add a3, s3, a2
lw a3, 0(a3)
slli a3, a3, 2
add s1, s4, a3
lw s0, 0(s1)
blt s0, a6, .LBB0_2
add a2, a2, a7
.LBB0_9:
lw a3, 0(a2)
addi s0, s0, -1
sw s0, 0(s1)
slli a3, a3, 2
add s1, s4, a3
lw s0, 0(s1)
addi a5, a5, 1
addiw a4, a4, 1
addi a2, a2, 4
blt t0, s0, .LBB0_9
j .LBB0_2
.LBB0_10:
li a0, 0
.LBB0_11:
lui a1, 19
addi a1, a1, 1744
add sp, sp, a1
ld ra, 488(sp)
ld s0, 480(sp)
ld s1, 472(sp)
ld s2, 464(sp)
ld s3, 456(sp)
ld s4, 448(sp)
addi sp, sp, 496
ret
|
13,939
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O3
|
RISC-V 64 clang 21.1.0
|
subarraysWithKDistinct:
addi sp, sp, -496
sd ra, 488(sp)
sd s0, 480(sp)
sd s1, 472(sp)
sd s2, 464(sp)
sd s3, 456(sp)
sd s4, 448(sp)
lui a3, 19
addi a3, a3, 1744
sub sp, sp, a3
mv s0, a2
mv s2, a1
mv s3, a0
lui a0, 20
addi a2, a0, -1916
addi a0, sp, 12
addi s4, sp, 12
li a1, 0
call memset
blez s2, .LBB0_10
li a1, 0
li a0, 0
li a4, 0
addi a7, s3, 4
li t0, 1
li a6, 2
li a5, 1
j .LBB0_4
.LBB0_2:
li s0, 0
addw a0, a0, a5
.LBB0_3:
addi a1, a1, 1
beq a1, s2, .LBB0_11
.LBB0_4:
slli a2, a1, 2
add a2, a2, s3
lw a2, 0(a2)
slli a2, a2, 2
add a2, a2, s4
lw s1, 0(a2)
seqz a3, s1
subw s0, s0, a3
addi s1, s1, 1
sw s1, 0(a2)
bltz s0, .LBB0_6
bnez s0, .LBB0_3
j .LBB0_7
.LBB0_6:
slli a2, a4, 2
add a2, a2, s3
lw a2, 0(a2)
addiw a4, a4, 1
slli a2, a2, 2
add a2, a2, s4
sw zero, 0(a2)
li a5, 1
.LBB0_7:
slli a2, a4, 2
add a3, s3, a2
lw a3, 0(a3)
slli a3, a3, 2
add s1, s4, a3
lw s0, 0(s1)
blt s0, a6, .LBB0_2
add a2, a2, a7
.LBB0_9:
lw a3, 0(a2)
addi s0, s0, -1
sw s0, 0(s1)
slli a3, a3, 2
add s1, s4, a3
lw s0, 0(s1)
addi a5, a5, 1
addiw a4, a4, 1
addi a2, a2, 4
blt t0, s0, .LBB0_9
j .LBB0_2
.LBB0_10:
li a0, 0
.LBB0_11:
lui a1, 19
addi a1, a1, 1744
add sp, sp, a1
ld ra, 488(sp)
ld s0, 480(sp)
ld s1, 472(sp)
ld s2, 464(sp)
ld s3, 456(sp)
ld s4, 448(sp)
addi sp, sp, 496
ret
|
13,940
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O0
|
RISC-V 64 gcc 15.2.0
|
subarraysWithKDistinct:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
li t0,-81920
addi t0,t0,1872
add sp,sp,t0
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
sd a0,1880(a5)
mv a4,a1
mv a3,a2
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
sw a4,1876(a5)
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
mv a4,a3
sw a4,1872(a5)
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
addi a4,a5,1896
li a5,81920
addi a5,a5,-1916
mv a2,a5
li a1,0
mv a0,a4
call memset
sw zero,-20(s0)
sw zero,-24(s0)
li a5,1
sw a5,-28(s0)
sw zero,-32(s0)
j .L2
.L7:
lw a5,-24(s0)
addiw a4,a5,1
sw a4,-24(s0)
slli a5,a5,2
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
ld a4,1880(a4)
add a5,a4,a5
lw a5,0(a5)
sw a5,-36(s0)
li a5,-81920
addi a5,a5,-16
add a4,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a4,a5
lw a5,1896(a5)
bne a5,zero,.L3
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
lw a4,1872(a4)
addiw a4,a4,-1
sw a4,1872(a5)
.L3:
li a5,-81920
addi a5,a5,-16
add a4,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a4,a5
lw a5,1896(a5)
addiw a5,a5,1
sext.w a4,a5
li a5,-81920
addi a5,a5,-16
add a3,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a3,a5
sw a4,1896(a5)
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
lw a5,1872(a5)
sext.w a5,a5
bge a5,zero,.L4
lw a5,-20(s0)
addiw a4,a5,1
sw a4,-20(s0)
slli a5,a5,2
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
ld a4,1880(a4)
add a5,a4,a5
lw a5,0(a5)
sw a5,-36(s0)
li a5,-81920
addi a5,a5,-16
add a4,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a4,a5
sw zero,1896(a5)
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
sw zero,1872(a5)
li a5,1
sw a5,-28(s0)
.L4:
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
lw a5,1872(a5)
sext.w a5,a5
bne a5,zero,.L2
j .L5
.L6:
lw a5,-20(s0)
addiw a4,a5,1
sw a4,-20(s0)
slli a5,a5,2
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
ld a4,1880(a4)
add a5,a4,a5
lw a5,0(a5)
sw a5,-36(s0)
li a5,-81920
addi a5,a5,-16
add a4,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a4,a5
lw a5,1896(a5)
addiw a5,a5,-1
sext.w a4,a5
li a5,-81920
addi a5,a5,-16
add a3,a5,s0
lw a5,-36(s0)
slli a5,a5,2
add a5,a3,a5
sw a4,1896(a5)
lw a5,-28(s0)
addiw a5,a5,1
sw a5,-28(s0)
.L5:
lw a5,-20(s0)
slli a5,a5,2
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
ld a4,1880(a4)
add a5,a4,a5
lw a5,0(a5)
li a4,-81920
addi a4,a4,-16
add a4,a4,s0
slli a5,a5,2
add a5,a4,a5
lw a4,1896(a5)
li a5,1
bgt a4,a5,.L6
lw a5,-32(s0)
mv a4,a5
lw a5,-28(s0)
addw a5,a4,a5
sw a5,-32(s0)
.L2:
li a5,-81920
addi a5,a5,-16
add a5,a5,s0
lw a4,-24(s0)
lw a5,1876(a5)
sext.w a4,a4
sext.w a5,a5
blt a4,a5,.L7
lw a5,-32(s0)
mv a0,a5
li t0,81920
addi t0,t0,-1872
add sp,sp,t0
ld ra,8(sp)
ld s0,0(sp)
addi sp,sp,16
jr ra
|
13,941
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O1
|
RISC-V 64 gcc 15.2.0
|
subarraysWithKDistinct:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
sd s1,8(sp)
sd s2,0(sp)
li t0,-81920
addi t0,t0,1904
add sp,sp,t0
mv s0,a0
mv s2,a1
mv s1,a2
li a2,81920
addi a2,a2,-1916
li a1,0
addi a0,sp,8
call memset
ble s2,zero,.L10
slli t3,s2,2
add t3,t3,s0
mv a7,s0
li a0,0
li t5,1
li a6,0
addi a1,sp,-1904
mv t1,t5
j .L9
.L3:
slli a5,a5,2
add a5,a1,a5
addiw a4,a4,1
sw a4,1912(a5)
blt s1,zero,.L15
beq s1,zero,.L16
.L6:
addi a7,a7,4
beq a7,t3,.L2
.L9:
lw a5,0(a7)
slli a4,a5,2
add a4,a1,a4
lw a4,1912(a4)
bne a4,zero,.L3
addiw s1,s1,-1
j .L3
.L15:
addiw t4,a6,1
slli a6,a6,2
add a6,s0,a6
lw a5,0(a6)
slli a5,a5,2
add a5,a1,a5
sw zero,1912(a5)
mv t5,t1
.L5:
slli a3,t4,2
add a5,s0,a3
lw a5,0(a5)
slli a4,a5,2
add a4,a1,a4
lw a4,1912(a4)
ble a4,t1,.L11
add a3,s0,a3
mv a6,t4
.L8:
addiw a2,a6,1
mv a6,a2
slli a5,a5,2
add a5,a1,a5
addiw a4,a4,-1
sw a4,1912(a5)
lw a5,4(a3)
slli a4,a5,2
add a4,a1,a4
lw a4,1912(a4)
addi a3,a3,4
bgt a4,t1,.L8
subw t4,t5,t4
addw t5,t4,a2
.L7:
addw a0,t5,a0
li s1,0
j .L6
.L16:
mv t4,a6
j .L5
.L11:
mv a6,t4
j .L7
.L10:
li a0,0
.L2:
li t0,81920
addi t0,t0,-1904
add sp,sp,t0
ld ra,24(sp)
ld s0,16(sp)
ld s1,8(sp)
ld s2,0(sp)
addi sp,sp,32
jr ra
|
13,942
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O2
|
RISC-V 64 gcc 15.2.0
|
subarraysWithKDistinct:
li t0,-81920
addi sp,sp,-48
addi t0,t0,1904
sd s0,32(sp)
sd s1,24(sp)
sd s3,8(sp)
sd ra,40(sp)
sd s2,16(sp)
mv s1,a2
add sp,sp,t0
li a2,81920
mv s3,a1
mv s0,a0
addi a2,a2,-1916
addi a0,sp,8
li a1,0
call memset
ble s3,zero,.L11
lw a4,0(s0)
slli t3,s3,2
add t3,s0,t3
slli a4,a4,2
add s2,sp,a4
lw a1,8(s2)
beq a1,zero,.L21
mv a3,a1
mv t1,s0
li a0,0
li t4,1
li a1,0
.L3:
addi a5,sp,-1904
addiw a3,a3,1
add a4,a5,a4
sw a3,1912(a4)
bge s1,zero,.L4
slli a4,a1,2
add a4,s0,a4
lw a4,0(a4)
addiw t6,a1,1
li t4,1
slli a4,a4,2
add a5,a5,a4
sw zero,1912(a5)
.L7:
slli a4,t6,2
add a4,s0,a4
lw a6,0(a4)
addi a2,sp,-1904
li t5,1
slli a3,a6,2
add a5,a2,a3
lw a5,1912(a5)
mv a1,t6
ble a5,t5,.L6
.L9:
lw a6,4(a4)
add a7,a2,a3
addiw a5,a5,-1
slli a3,a6,2
sw a5,1912(a7)
add a5,a2,a3
lw a5,1912(a5)
addiw a1,a1,1
addi a4,a4,4
bgt a5,t5,.L9
subw t6,t4,t6
addw t4,t6,a1
.L6:
addw a0,t4,a0
li s1,0
.L8:
addi t1,t1,4
beq t1,t3,.L2
lw a4,0(t1)
addi a5,sp,-1904
slli a4,a4,2
add a5,a5,a4
lw a3,1912(a5)
beq a3,zero,.L10
addiw a3,a3,1
sw a3,1912(a5)
.L4:
bne s1,zero,.L8
mv t6,a1
j .L7
.L21:
li a0,0
mv t1,s0
li t4,1
.L10:
addiw s1,s1,-1
li a3,0
j .L3
.L11:
li a0,0
.L2:
li t0,81920
addi t0,t0,-1904
add sp,sp,t0
ld ra,40(sp)
ld s0,32(sp)
ld s1,24(sp)
ld s2,16(sp)
ld s3,8(sp)
addi sp,sp,48
jr ra
|
13,943
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
riscv64
|
-O3
|
RISC-V 64 gcc 15.2.0
|
subarraysWithKDistinct:
li t0,-81920
addi sp,sp,-48
addi t0,t0,1904
sd s0,32(sp)
sd s1,24(sp)
sd s3,8(sp)
sd ra,40(sp)
sd s2,16(sp)
mv s1,a2
add sp,sp,t0
li a2,81920
mv s3,a1
mv s0,a0
addi a2,a2,-1916
addi a0,sp,8
li a1,0
call memset
ble s3,zero,.L11
lw a4,0(s0)
slli t3,s3,2
add t3,s0,t3
slli a4,a4,2
add s2,sp,a4
lw a1,8(s2)
beq a1,zero,.L21
mv a3,a1
mv t1,s0
li a0,0
li t4,1
li a1,0
.L3:
addi a5,sp,-1904
addiw a3,a3,1
add a4,a5,a4
sw a3,1912(a4)
bge s1,zero,.L4
slli a4,a1,2
add a4,s0,a4
lw a4,0(a4)
addiw t6,a1,1
li t4,1
slli a4,a4,2
add a5,a5,a4
sw zero,1912(a5)
.L7:
slli a4,t6,2
add a4,s0,a4
lw a6,0(a4)
addi a2,sp,-1904
li t5,1
slli a3,a6,2
add a5,a2,a3
lw a5,1912(a5)
mv a1,t6
ble a5,t5,.L6
.L9:
lw a6,4(a4)
add a7,a2,a3
addiw a5,a5,-1
slli a3,a6,2
sw a5,1912(a7)
add a5,a2,a3
lw a5,1912(a5)
addiw a1,a1,1
addi a4,a4,4
bgt a5,t5,.L9
subw t6,t4,t6
addw t4,t6,a1
.L6:
addw a0,a0,t4
li s1,0
.L8:
addi t1,t1,4
beq t3,t1,.L2
lw a4,0(t1)
addi a5,sp,-1904
slli a4,a4,2
add a5,a5,a4
lw a3,1912(a5)
beq a3,zero,.L10
addiw a3,a3,1
sw a3,1912(a5)
.L4:
bne s1,zero,.L8
mv t6,a1
j .L7
.L21:
mv t1,s0
li a0,0
li t4,1
.L10:
addiw s1,s1,-1
li a3,0
j .L3
.L11:
li a0,0
.L2:
li t0,81920
addi t0,t0,-1904
add sp,sp,t0
ld ra,40(sp)
ld s0,32(sp)
ld s1,24(sp)
ld s2,16(sp)
ld s3,8(sp)
addi sp,sp,48
jr ra
|
13,944
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O0
|
x86-64 clang 21.1.0
|
subarraysWithKDistinct:
push rbp
mov rbp, rsp
sub rsp, 80064
mov qword ptr [rbp - 8], rdi
mov dword ptr [rbp - 12], esi
mov dword ptr [rbp - 16], edx
lea rdi, [rbp - 80032]
xor esi, esi
mov edx, 80004
call memset@PLT
mov dword ptr [rbp - 80040], 0
mov dword ptr [rbp - 80044], 0
mov dword ptr [rbp - 80048], 1
mov dword ptr [rbp - 80052], 0
.LBB0_1:
mov eax, dword ptr [rbp - 80044]
cmp eax, dword ptr [rbp - 12]
jge .LBB0_12
mov rax, qword ptr [rbp - 8]
mov ecx, dword ptr [rbp - 80044]
mov edx, ecx
add edx, 1
mov dword ptr [rbp - 80044], edx
movsxd rcx, ecx
mov eax, dword ptr [rax + 4*rcx]
mov dword ptr [rbp - 80036], eax
movsxd rax, dword ptr [rbp - 80036]
cmp dword ptr [rbp + 4*rax - 80032], 0
jne .LBB0_4
mov eax, dword ptr [rbp - 16]
add eax, -1
mov dword ptr [rbp - 16], eax
.LBB0_4:
movsxd rax, dword ptr [rbp - 80036]
mov ecx, dword ptr [rbp + 4*rax - 80032]
add ecx, 1
mov dword ptr [rbp + 4*rax - 80032], ecx
cmp dword ptr [rbp - 16], 0
jge .LBB0_6
mov rax, qword ptr [rbp - 8]
mov ecx, dword ptr [rbp - 80040]
mov edx, ecx
add edx, 1
mov dword ptr [rbp - 80040], edx
movsxd rcx, ecx
mov eax, dword ptr [rax + 4*rcx]
mov dword ptr [rbp - 80036], eax
movsxd rax, dword ptr [rbp - 80036]
mov dword ptr [rbp + 4*rax - 80032], 0
mov dword ptr [rbp - 16], 0
mov dword ptr [rbp - 80048], 1
.LBB0_6:
cmp dword ptr [rbp - 16], 0
jne .LBB0_11
jmp .LBB0_8
.LBB0_8:
mov rax, qword ptr [rbp - 8]
movsxd rcx, dword ptr [rbp - 80040]
movsxd rax, dword ptr [rax + 4*rcx]
cmp dword ptr [rbp + 4*rax - 80032], 1
jle .LBB0_10
mov rax, qword ptr [rbp - 8]
mov ecx, dword ptr [rbp - 80040]
mov edx, ecx
add edx, 1
mov dword ptr [rbp - 80040], edx
movsxd rcx, ecx
mov eax, dword ptr [rax + 4*rcx]
mov dword ptr [rbp - 80036], eax
movsxd rax, dword ptr [rbp - 80036]
mov ecx, dword ptr [rbp + 4*rax - 80032]
add ecx, -1
mov dword ptr [rbp + 4*rax - 80032], ecx
mov eax, dword ptr [rbp - 80048]
add eax, 1
mov dword ptr [rbp - 80048], eax
jmp .LBB0_8
.LBB0_10:
mov eax, dword ptr [rbp - 80048]
add eax, dword ptr [rbp - 80052]
mov dword ptr [rbp - 80052], eax
.LBB0_11:
jmp .LBB0_1
.LBB0_12:
mov eax, dword ptr [rbp - 80052]
add rsp, 80064
pop rbp
ret
|
13,945
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O1
|
x86-64 clang 21.1.0
|
subarraysWithKDistinct:
push rbp
push r15
push r14
push rbx
sub rsp, 80008
mov ebp, edx
mov r15d, esi
mov rbx, rdi
mov rdi, rsp
xor r14d, r14d
mov edx, 80004
xor esi, esi
call memset@PLT
test r15d, r15d
jle .LBB0_10
mov eax, r15d
lea rcx, [rbx + 4]
mov edi, 1
xor edx, edx
xor r14d, r14d
xor esi, esi
jmp .LBB0_2
.LBB0_8:
add r14d, edi
.LBB0_9:
inc rdx
cmp rdx, rax
je .LBB0_10
.LBB0_2:
movsxd r8, dword ptr [rbx + 4*rdx]
mov r9d, dword ptr [rsp + 4*r8]
xor r10d, r10d
test r9d, r9d
sete r10b
inc r9d
sub ebp, r10d
mov dword ptr [rsp + 4*r8], r9d
js .LBB0_3
test ebp, ebp
jne .LBB0_9
jmp .LBB0_5
.LBB0_3:
movsxd rdi, esi
inc esi
movsxd rdi, dword ptr [rbx + 4*rdi]
mov dword ptr [rsp + 4*rdi], 0
mov edi, 1
xor ebp, ebp
test ebp, ebp
jne .LBB0_9
.LBB0_5:
movsxd r8, esi
movsxd r10, dword ptr [rbx + 4*r8]
mov r9d, dword ptr [rsp + 4*r10]
cmp r9d, 2
jl .LBB0_8
lea r10, [rsp + 4*r10]
lea r8, [rcx + 4*r8]
.LBB0_7:
dec r9d
mov dword ptr [r10], r9d
inc edi
movsxd r9, dword ptr [r8]
lea r10, [rsp + 4*r9]
mov r9d, dword ptr [rsp + 4*r9]
inc esi
add r8, 4
cmp r9d, 1
jg .LBB0_7
jmp .LBB0_8
.LBB0_10:
mov eax, r14d
add rsp, 80008
pop rbx
pop r14
pop r15
pop rbp
ret
|
13,946
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O2
|
x86-64 clang 21.1.0
|
subarraysWithKDistinct:
push rbp
push r15
push r14
push rbx
sub rsp, 80008
mov r14d, edx
mov r15d, esi
mov rbx, rdi
mov rdi, rsp
xor ebp, ebp
mov edx, 80004
xor esi, esi
call memset@PLT
test r15d, r15d
jle .LBB0_10
mov eax, r15d
lea rcx, [rbx + 4]
mov edi, 1
xor edx, edx
xor ebp, ebp
xor esi, esi
jmp .LBB0_2
.LBB0_8:
add ebp, edi
xor r14d, r14d
.LBB0_9:
inc rdx
cmp rdx, rax
je .LBB0_10
.LBB0_2:
movsxd r8, dword ptr [rbx + 4*rdx]
mov r9d, dword ptr [rsp + 4*r8]
xor r10d, r10d
test r9d, r9d
sete r10b
inc r9d
sub r14d, r10d
mov dword ptr [rsp + 4*r8], r9d
js .LBB0_3
jne .LBB0_9
jmp .LBB0_5
.LBB0_3:
movsxd rdi, esi
inc esi
movsxd rdi, dword ptr [rbx + 4*rdi]
mov dword ptr [rsp + 4*rdi], 0
mov edi, 1
.LBB0_5:
movsxd r8, esi
movsxd r10, dword ptr [rbx + 4*r8]
mov r9d, dword ptr [rsp + 4*r10]
cmp r9d, 2
jl .LBB0_8
lea r10, [rsp + 4*r10]
lea r8, [rcx + 4*r8]
.LBB0_7:
dec r9d
mov dword ptr [r10], r9d
inc edi
movsxd r9, dword ptr [r8]
lea r10, [rsp + 4*r9]
mov r9d, dword ptr [rsp + 4*r9]
inc esi
add r8, 4
cmp r9d, 1
jg .LBB0_7
jmp .LBB0_8
.LBB0_10:
mov eax, ebp
add rsp, 80008
pop rbx
pop r14
pop r15
pop rbp
ret
|
13,947
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O3
|
x86-64 clang 21.1.0
|
subarraysWithKDistinct:
push rbp
push r15
push r14
push rbx
sub rsp, 80008
mov r14d, edx
mov r15d, esi
mov rbx, rdi
mov rdi, rsp
xor ebp, ebp
mov edx, 80004
xor esi, esi
call memset@PLT
test r15d, r15d
jle .LBB0_10
mov eax, r15d
lea rcx, [rbx + 4]
mov edi, 1
xor edx, edx
xor ebp, ebp
xor esi, esi
jmp .LBB0_2
.LBB0_8:
add ebp, edi
xor r14d, r14d
.LBB0_9:
inc rdx
cmp rdx, rax
je .LBB0_10
.LBB0_2:
movsxd r8, dword ptr [rbx + 4*rdx]
mov r9d, dword ptr [rsp + 4*r8]
xor r10d, r10d
test r9d, r9d
sete r10b
inc r9d
sub r14d, r10d
mov dword ptr [rsp + 4*r8], r9d
js .LBB0_3
jne .LBB0_9
jmp .LBB0_5
.LBB0_3:
movsxd rdi, esi
inc esi
movsxd rdi, dword ptr [rbx + 4*rdi]
mov dword ptr [rsp + 4*rdi], 0
mov edi, 1
.LBB0_5:
movsxd r8, esi
movsxd r10, dword ptr [rbx + 4*r8]
mov r9d, dword ptr [rsp + 4*r10]
cmp r9d, 2
jl .LBB0_8
lea r10, [rsp + 4*r10]
lea r8, [rcx + 4*r8]
.LBB0_7:
dec r9d
mov dword ptr [r10], r9d
inc edi
movsxd r9, dword ptr [r8]
lea r10, [rsp + 4*r9]
mov r9d, dword ptr [rsp + 4*r9]
inc esi
add r8, 4
cmp r9d, 1
jg .LBB0_7
jmp .LBB0_8
.LBB0_10:
mov eax, ebp
add rsp, 80008
pop rbx
pop r14
pop r15
pop rbp
ret
|
13,948
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O0
|
x86-64 gcc 15.2
|
subarraysWithKDistinct:
push rbp
mov rbp, rsp
sub rsp, 80048
mov QWORD PTR [rbp-80040], rdi
mov DWORD PTR [rbp-80044], esi
mov DWORD PTR [rbp-80048], edx
lea rax, [rbp-80032]
mov edx, 80004
mov esi, 0
mov rdi, rax
call memset
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 0
mov DWORD PTR [rbp-12], 1
mov DWORD PTR [rbp-16], 0
jmp .L2
.L7:
mov eax, DWORD PTR [rbp-8]
lea edx, [rax+1]
mov DWORD PTR [rbp-8], edx
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-80040]
add rax, rdx
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-20]
cdqe
mov eax, DWORD PTR [rbp-80032+rax*4]
test eax, eax
jne .L3
sub DWORD PTR [rbp-80048], 1
.L3:
mov eax, DWORD PTR [rbp-20]
cdqe
mov eax, DWORD PTR [rbp-80032+rax*4]
lea edx, [rax+1]
mov eax, DWORD PTR [rbp-20]
cdqe
mov DWORD PTR [rbp-80032+rax*4], edx
cmp DWORD PTR [rbp-80048], 0
jns .L4
mov eax, DWORD PTR [rbp-4]
lea edx, [rax+1]
mov DWORD PTR [rbp-4], edx
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-80040]
add rax, rdx
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-20]
cdqe
mov DWORD PTR [rbp-80032+rax*4], 0
mov DWORD PTR [rbp-80048], 0
mov DWORD PTR [rbp-12], 1
.L4:
cmp DWORD PTR [rbp-80048], 0
jne .L2
jmp .L5
.L6:
mov eax, DWORD PTR [rbp-4]
lea edx, [rax+1]
mov DWORD PTR [rbp-4], edx
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-80040]
add rax, rdx
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-20]
cdqe
mov eax, DWORD PTR [rbp-80032+rax*4]
lea edx, [rax-1]
mov eax, DWORD PTR [rbp-20]
cdqe
mov DWORD PTR [rbp-80032+rax*4], edx
add DWORD PTR [rbp-12], 1
.L5:
mov eax, DWORD PTR [rbp-4]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-80040]
add rax, rdx
mov eax, DWORD PTR [rax]
cdqe
mov eax, DWORD PTR [rbp-80032+rax*4]
cmp eax, 1
jg .L6
mov eax, DWORD PTR [rbp-12]
add DWORD PTR [rbp-16], eax
.L2:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-80044]
jl .L7
mov eax, DWORD PTR [rbp-16]
leave
ret
|
13,949
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O1
|
x86-64 gcc 15.2
|
subarraysWithKDistinct:
push r12
push rbp
push rbx
sub rsp, 80016
mov rbx, rdi
mov r12d, esi
mov ebp, edx
mov rdi, rsp
mov edx, 80004
mov esi, 0
call memset
test r12d, r12d
jle .L10
mov rcx, rbx
movsx r12, r12d
lea rdi, [rbx+r12*4]
mov r8d, 0
mov esi, 1
mov r11d, 0
mov r9d, 1
jmp .L9
.L4:
je .L15
.L6:
add rcx, 4
cmp rcx, rdi
je .L1
.L9:
mov eax, DWORD PTR [rcx]
movsx rdx, eax
mov edx, DWORD PTR [rsp+rdx*4]
cmp edx, 1
sbb ebp, 0
cdqe
add edx, 1
mov DWORD PTR [rsp+rax*4], edx
test ebp, ebp
jns .L4
lea r10d, [r11+1]
movsx r11, r11d
movsx rax, DWORD PTR [rbx+r11*4]
mov DWORD PTR [rsp+rax*4], 0
mov esi, r9d
.L5:
movsx rax, r10d
lea r11, [0+rax*4]
mov eax, DWORD PTR [rbx+rax*4]
movsx rdx, eax
mov edx, DWORD PTR [rsp+rdx*4]
cmp edx, 1
jle .L11
mov ebp, r10d
add r10d, 1
movsx r10, r10d
mov r12, r10
neg r12
lea r11, [r11+r12*4]
add r11, rbx
.L8:
cdqe
sub edx, 1
mov DWORD PTR [rsp+rax*4], edx
mov eax, DWORD PTR [r11+4+r10*4]
movsx rdx, eax
mov edx, DWORD PTR [rsp+rdx*4]
mov r12, r10
add r10, 1
cmp edx, 1
jg .L8
mov r11d, r12d
sub esi, ebp
add esi, r12d
.L7:
add r8d, esi
mov ebp, 0
jmp .L6
.L15:
mov r10d, r11d
jmp .L5
.L11:
mov r11d, r10d
jmp .L7
.L10:
mov r8d, 0
.L1:
mov eax, r8d
add rsp, 80016
pop rbx
pop rbp
pop r12
ret
|
13,950
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O2
|
x86-64 gcc 15.2
|
subarraysWithKDistinct:
push r12
movsx r12, esi
xor esi, esi
push rbp
mov ebp, edx
mov edx, 80004
push rbx
mov rbx, rdi
sub rsp, 80016
mov rdi, rsp
call memset
test r12d, r12d
jle .L11
movsx rdx, DWORD PTR [rbx]
mov rsi, rbx
lea r9, [rbx+r12*4]
movsx rcx, DWORD PTR [rsp+rdx*4]
test ecx, ecx
je .L20
mov eax, ecx
xor r10d, r10d
mov r8d, 1
xor ecx, ecx
.L3:
add eax, 1
mov DWORD PTR [rsp+rdx*4], eax
test ebp, ebp
jns .L4
movsx rax, DWORD PTR [rbx+rcx*4]
lea ebp, [rcx+1]
mov r8d, 1
mov DWORD PTR [rsp+rax*4], 0
.L7:
movsx rax, ebp
movsx rcx, DWORD PTR [rbx+rax*4]
lea rdi, [0+rax*4]
mov eax, DWORD PTR [rsp+rcx*4]
cmp eax, 1
jle .L21
lea edx, [rbp+1]
movsx rdx, edx
mov r11, rdx
neg r11
lea rdi, [rdi+r11*4]
add rdi, rbx
.L9:
sub eax, 1
mov r11, rdx
mov DWORD PTR [rsp+rcx*4], eax
movsx rcx, DWORD PTR [rdi+4+rdx*4]
add rdx, 1
mov eax, DWORD PTR [rsp+rcx*4]
cmp eax, 1
jg .L9
sub r8d, ebp
movsx rcx, r11d
add r8d, r11d
.L6:
add r10d, r8d
xor ebp, ebp
.L8:
add rsi, 4
cmp rsi, r9
je .L1
movsx rdx, DWORD PTR [rsi]
mov eax, DWORD PTR [rsp+rdx*4]
test eax, eax
je .L10
add eax, 1
mov DWORD PTR [rsp+rdx*4], eax
.L4:
test ebp, ebp
jne .L8
mov ebp, ecx
jmp .L7
.L20:
xor r10d, r10d
mov r8d, 1
.L10:
sub ebp, 1
xor eax, eax
jmp .L3
.L11:
xor r10d, r10d
.L1:
add rsp, 80016
mov eax, r10d
pop rbx
pop rbp
pop r12
ret
.L21:
movsx rcx, ebp
jmp .L6
|
13,951
| 992
|
Subarrays with K Different Integers
|
Hard
|
/*
992. Subarrays with K Different Integers
Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K.
(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)
Return the number of good subarrays of A.
Example 1:
Input: A = [1,2,1,2,3], K = 2
Output: 7
Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].
Example 2:
Input: A = [1,2,1,3,4], K = 3
Output: 3
Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
Note:
1 <= A.length <= 20000
1 <= A[i] <= A.length
1 <= K <= A.length
*/
int subarraysWithKDistinct(int* A, int ASize, int K) {
int cnt[20001] = { 0 };
int a, l = 0, r = 0, n = 1, t = 0;
while (r < ASize) {
a = A[r ++];
if (cnt[a] == 0) { // reduce K when a new number is pushed in from right
K --;
}
cnt[a] ++;
if (K < 0) { // number on far left is uniq, pop it out and reset all
a = A[l ++];
cnt[a] = 0;
K = 0;
n = 1;
}
if (K == 0) { // a valid result is found
while (cnt[A[l]] > 1) { // pop out all dup numbers from far left
a = A[l ++];
cnt[a] --;
n ++; // all possible combinations after one pop
}
t += n; // all possible combinations so far
}
}
return t;
}
/*
Difficulty:Hard
*/
|
x86-64
|
-O3
|
x86-64 gcc 15.2
|
subarraysWithKDistinct:
push r12
movsx r12, esi
xor esi, esi
push rbp
mov ebp, edx
mov edx, 80004
push rbx
mov rbx, rdi
sub rsp, 80016
mov rdi, rsp
call memset
test r12d, r12d
jle .L11
movsx rdx, DWORD PTR [rbx]
mov rsi, rbx
lea r9, [rbx+r12*4]
movsx rcx, DWORD PTR [rsp+rdx*4]
test ecx, ecx
je .L20
mov eax, ecx
xor r10d, r10d
mov r8d, 1
xor ecx, ecx
.L3:
add eax, 1
mov DWORD PTR [rsp+rdx*4], eax
test ebp, ebp
jns .L4
movsx rax, DWORD PTR [rbx+rcx*4]
lea ebp, [rcx+1]
mov r8d, 1
mov DWORD PTR [rsp+rax*4], 0
.L7:
movsx rax, ebp
movsx rcx, DWORD PTR [rbx+rax*4]
lea rdi, [0+rax*4]
mov eax, DWORD PTR [rsp+rcx*4]
cmp eax, 1
jle .L21
lea edx, [rbp+1]
movsx rdx, edx
mov r11, rdx
neg r11
lea rdi, [rdi+r11*4]
add rdi, rbx
.L9:
sub eax, 1
mov r11, rdx
mov DWORD PTR [rsp+rcx*4], eax
movsx rcx, DWORD PTR [rdi+4+rdx*4]
add rdx, 1
mov eax, DWORD PTR [rsp+rcx*4]
cmp eax, 1
jg .L9
sub r8d, ebp
movsx rcx, r11d
add r8d, r11d
.L6:
add r10d, r8d
xor ebp, ebp
.L8:
add rsi, 4
cmp r9, rsi
je .L1
movsx rdx, DWORD PTR [rsi]
mov eax, DWORD PTR [rsp+rdx*4]
test eax, eax
je .L10
add eax, 1
mov DWORD PTR [rsp+rdx*4], eax
.L4:
test ebp, ebp
jne .L8
mov ebp, ecx
jmp .L7
.L20:
xor r10d, r10d
mov r8d, 1
.L10:
sub ebp, 1
xor eax, eax
jmp .L3
.L11:
xor r10d, r10d
.L1:
add rsp, 80016
mov eax, r10d
pop rbx
pop rbp
pop r12
ret
.L21:
movsx rcx, ebp
jmp .L6
|
13,952
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O0
|
ARM64 gcc 15.2.0
|
minDominoRotations:
sub sp, sp, #64
str x0, [sp, 24]
str w1, [sp, 20]
str x2, [sp, 8]
str w3, [sp, 16]
mov w0, 1
strb w0, [sp, 62]
ldrb w0, [sp, 62]
strb w0, [sp, 63]
str wzr, [sp, 40]
ldr w0, [sp, 40]
str w0, [sp, 44]
ldr w0, [sp, 44]
str w0, [sp, 48]
ldr w0, [sp, 48]
str w0, [sp, 52]
str wzr, [sp, 56]
b .L2
.L11:
ldrb w0, [sp, 63]
and w0, w0, 1
cmp w0, 0
beq .L3
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 24]
ldr w0, [x0]
cmp w1, w0
beq .L3
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 8]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 24]
ldr w0, [x0]
cmp w1, w0
beq .L3
strb wzr, [sp, 63]
.L3:
ldrb w0, [sp, 62]
and w0, w0, 1
cmp w0, 0
beq .L4
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 8]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 8]
ldr w0, [x0]
cmp w1, w0
beq .L4
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 8]
ldr w0, [x0]
cmp w1, w0
beq .L4
strb wzr, [sp, 62]
.L4:
ldrb w0, [sp, 63]
eor w0, w0, 1
and w0, w0, 255
and w0, w0, 1
cmp w0, 0
beq .L5
ldrb w0, [sp, 62]
eor w0, w0, 1
and w0, w0, 255
and w0, w0, 1
cmp w0, 0
beq .L5
mov w0, -1
b .L6
.L5:
ldrb w0, [sp, 63]
and w0, w0, 1
cmp w0, 0
beq .L7
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 24]
ldr w0, [x0]
cmp w1, w0
beq .L8
ldr w0, [sp, 52]
add w0, w0, 1
str w0, [sp, 52]
b .L7
.L8:
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 8]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 24]
ldr w0, [x0]
cmp w1, w0
beq .L7
ldr w0, [sp, 48]
add w0, w0, 1
str w0, [sp, 48]
.L7:
ldrb w0, [sp, 62]
and w0, w0, 1
cmp w0, 0
beq .L9
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 8]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 8]
ldr w0, [x0]
cmp w1, w0
beq .L10
ldr w0, [sp, 44]
add w0, w0, 1
str w0, [sp, 44]
b .L9
.L10:
ldrsw x0, [sp, 56]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 8]
ldr w0, [x0]
cmp w1, w0
beq .L9
ldr w0, [sp, 40]
add w0, w0, 1
str w0, [sp, 40]
.L9:
ldr w0, [sp, 56]
add w0, w0, 1
str w0, [sp, 56]
.L2:
ldr w1, [sp, 56]
ldr w0, [sp, 20]
cmp w1, w0
blt .L11
ldrb w0, [sp, 63]
and w0, w0, 1
cmp w0, 0
beq .L12
ldr w0, [sp, 52]
ldr w2, [sp, 48]
ldr w1, [sp, 48]
cmp w2, w0
csel w0, w1, w0, le
b .L6
.L12:
ldrb w0, [sp, 62]
and w0, w0, 1
cmp w0, 0
beq .L13
ldr w0, [sp, 40]
ldr w2, [sp, 44]
ldr w1, [sp, 44]
cmp w2, w0
csel w0, w1, w0, le
b .L6
.L13:
mov w0, -1
.L6:
add sp, sp, 64
ret
|
13,953
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O1
|
ARM64 gcc 15.2.0
|
minDominoRotations:
cmp w1, 0
ble .L18
sbfiz x5, x1, 2, 32
mov x1, 0
mov w11, 0
mov w6, 0
mov w12, 0
mov w8, 0
mov w4, 1
mov w3, w4
mov w10, w4
b .L13
.L22:
mov w3, w4
b .L15
.L29:
mov w4, w3
.L16:
ldr w3, [x0]
ldr w7, [x0, x1]
cmp w7, w3
beq .L9
add w8, w8, 1
.L10:
mov w3, w10
tbnz x4, 0, .L26
.L11:
add x1, x1, 4
cmp x5, x1
beq .L27
.L13:
tbz x3, 0, .L3
ldr w3, [x0]
ldr w7, [x0, x1]
cmp w7, w3
beq .L4
ldr w7, [x2, x1]
cmp w7, w3
cset w3, eq
tbnz x4, 0, .L15
.L5:
cmp w4, 0
ccmp w3, 0, 0, eq
beq .L19
tbnz x3, 0, .L16
.L8:
ldr w7, [x2]
ldr w9, [x2, x1]
cmp w9, w7
beq .L12
add w6, w6, 1
b .L11
.L26:
mov w3, w4
b .L8
.L27:
tbnz x3, 0, .L2
tbz x4, 0, .L21
cmp w6, w11
csel w0, w6, w11, le
b .L1
.L18:
mov w12, 0
mov w8, 0
.L2:
cmp w8, w12
csel w0, w8, w12, le
b .L1
.L19:
mov w0, -1
b .L1
.L21:
mov w0, -1
b .L1
.L3:
tbz x4, 0, .L28
.L15:
ldr w4, [x2]
ldr w7, [x2, x1]
cmp w7, w4
beq .L6
ldr w7, [x0, x1]
cmp w7, w4
cset w4, eq
b .L5
.L28:
mov w0, -1
.L1:
ret
.L4:
tbnz x4, 0, .L22
ldr w3, [x0]
.L9:
ldr w7, [x2, x1]
cmp w3, w7
cinc w12, w12, ne
b .L10
.L6:
tbnz x3, 0, .L29
ldr w7, [x2]
mov w4, 1
.L12:
ldr w9, [x0, x1]
cmp w7, w9
cinc w11, w11, ne
b .L11
|
13,954
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O2
|
ARM64 gcc 15.2.0
|
minDominoRotations:
cmp w1, 0
ble .L39
ldr w5, [x0]
ubfiz x1, x1, 2, 32
ldr w4, [x2]
mov w12, 0
mov x3, 0
mov w7, 0
mov w8, 0
mov w11, 0
.L3:
ldr w9, [x0, x3]
cmp w9, w5
beq .L54
ldr w6, [x2, x3]
mov w10, w4
cmp w6, w4
beq .L55
cmp w9, w4
beq .L56
cmp w5, w6
bne .L41
add x3, x3, 4
add w7, w7, 1
cmp x3, x1
beq .L33
.L51:
ldr w6, [x0, x3]
mov w4, w5
cmp w6, w5
beq .L57
ldr w6, [x2, x3]
cmp w4, w6
bne .L41
add x3, x3, 4
add w7, w7, 1
cmp x1, x3
bne .L51
.L33:
cmp w7, w8
csel w0, w7, w8, le
ret
.L41:
mov w0, -1
ret
.L57:
ldr w6, [x2, x3]
cmp w6, w4
cinc w8, w8, ne
.L44:
add x3, x3, 4
cmp x1, x3
bne .L51
b .L33
.L54:
ldr w9, [x2, x3]
mov w6, w4
cmp w9, w4
beq .L30
cmp w5, w4
beq .L32
cmp w5, w9
beq .L44
add w8, w8, 1
b .L44
.L32:
mov w6, w9
add w8, w8, 1
mov w9, w4
mov w10, 1
.L12:
cmp w6, w9
beq .L22
.L58:
add x3, x3, 4
add w11, w11, 1
cmp x1, x3
beq .L24
.L46:
cbnz w10, .L3
ldr w6, [x2, x3]
mov w9, w4
mov w10, 0
cmp w6, w4
beq .L22
ldr w9, [x0, x3]
cmp w9, w4
bne .L41
.L10:
mov w9, w4
mov w10, 0
cmp w6, w9
bne .L58
.L22:
ldr w6, [x0, x3]
cmp w6, w9
beq .L25
add x3, x3, 4
add w12, w12, 1
cmp x1, x3
bne .L46
.L24:
cbnz w10, .L33
cmp w12, w11
csel w0, w12, w11, le
ret
.L55:
cmp w5, w4
bne .L10
.L9:
mov w6, w10
add w7, w7, 1
mov w9, w4
mov w10, 1
b .L12
.L25:
add x3, x3, 4
cmp x1, x3
bne .L46
b .L24
.L56:
mov w10, w5
cmp w5, w6
beq .L9
b .L10
.L39:
mov w0, 0
ret
.L30:
cmp w5, w4
bne .L32
mov w9, w5
mov w10, 1
b .L12
|
13,955
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O3
|
ARM64 gcc 15.2.0
|
minDominoRotations:
cmp w1, 0
ble .L39
ldr w5, [x0]
ubfiz x1, x1, 2, 32
ldr w4, [x2]
mov w12, 0
mov w7, 0
mov w8, 0
mov w11, 0
mov x3, 0
.L3:
ldr w9, [x0, x3]
cmp w9, w5
beq .L55
ldr w6, [x2, x3]
mov w10, w4
cmp w6, w4
beq .L56
cmp w9, w4
beq .L57
cmp w5, w6
bne .L41
.L15:
add x3, x3, 4
add w7, w7, 1
cmp x1, x3
beq .L33
.L51:
ldr w6, [x0, x3]
mov w4, w5
cmp w6, w5
beq .L58
ldr w6, [x2, x3]
cmp w4, w6
beq .L15
.L41:
mov w0, -1
ret
.L58:
ldr w6, [x2, x3]
cmp w6, w4
cinc w8, w8, ne
.L44:
add x3, x3, 4
cmp x1, x3
bne .L51
.L33:
cmp w7, w8
csel w0, w7, w8, le
ret
.L55:
ldr w9, [x2, x3]
mov w6, w4
cmp w9, w4
beq .L30
cmp w5, w4
beq .L32
cmp w5, w9
beq .L44
add w8, w8, 1
b .L44
.L32:
mov w6, w9
add w8, w8, 1
mov w9, w4
mov w10, 1
.L12:
cmp w6, w9
beq .L22
.L59:
add x3, x3, 4
add w11, w11, 1
cmp x1, x3
beq .L24
.L46:
cbnz w10, .L3
ldr w6, [x2, x3]
mov w9, w4
mov w10, 0
cmp w6, w4
beq .L22
ldr w9, [x0, x3]
cmp w9, w4
bne .L41
.L10:
mov w9, w4
mov w10, 0
cmp w6, w9
bne .L59
.L22:
ldr w6, [x0, x3]
add x3, x3, 4
cmp w6, w9
beq .L25
add w12, w12, 1
cmp x1, x3
bne .L46
.L24:
cbnz w10, .L33
cmp w12, w11
csel w0, w12, w11, le
ret
.L56:
cmp w5, w4
bne .L10
.L9:
mov w6, w10
add w7, w7, 1
mov w9, w4
mov w10, 1
b .L12
.L25:
cmp x1, x3
bne .L46
b .L24
.L57:
mov w10, w5
cmp w5, w6
beq .L9
b .L10
.L39:
mov w0, 0
ret
.L30:
cmp w5, w4
bne .L32
mov w9, w5
mov w10, 1
b .L12
|
13,956
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O0
|
armv8-a clang 21.1.0
|
minDominoRotations:
sub sp, sp, #80
str x0, [sp, #64]
str w1, [sp, #60]
str x2, [sp, #48]
str w3, [sp, #44]
mov w8, #1
strb w8, [sp, #42]
strb w8, [sp, #43]
str wzr, [sp, #20]
str wzr, [sp, #24]
str wzr, [sp, #28]
str wzr, [sp, #32]
str wzr, [sp, #36]
b .LBB0_1
.LBB0_1:
ldr w8, [sp, #36]
ldr w9, [sp, #60]
subs w8, w8, w9
b.ge .LBB0_29
b .LBB0_2
.LBB0_2:
ldrb w8, [sp, #43]
tbz w8, #0, .LBB0_6
b .LBB0_3
.LBB0_3:
ldr x8, [sp, #64]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #64]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_6
b .LBB0_4
.LBB0_4:
ldr x8, [sp, #48]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #64]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_6
b .LBB0_5
.LBB0_5:
strb wzr, [sp, #43]
b .LBB0_6
.LBB0_6:
ldrb w8, [sp, #42]
tbz w8, #0, .LBB0_10
b .LBB0_7
.LBB0_7:
ldr x8, [sp, #48]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #48]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_10
b .LBB0_8
.LBB0_8:
ldr x8, [sp, #64]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #48]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_10
b .LBB0_9
.LBB0_9:
strb wzr, [sp, #42]
b .LBB0_10
.LBB0_10:
ldrb w8, [sp, #43]
tbnz w8, #0, .LBB0_13
b .LBB0_11
.LBB0_11:
ldrb w8, [sp, #42]
tbnz w8, #0, .LBB0_13
b .LBB0_12
.LBB0_12:
mov w8, #-1
str w8, [sp, #76]
b .LBB0_40
.LBB0_13:
ldrb w8, [sp, #43]
tbz w8, #0, .LBB0_20
b .LBB0_14
.LBB0_14:
ldr x8, [sp, #64]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #64]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_16
b .LBB0_15
.LBB0_15:
ldr w8, [sp, #32]
add w8, w8, #1
str w8, [sp, #32]
b .LBB0_19
.LBB0_16:
ldr x8, [sp, #48]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #64]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_18
b .LBB0_17
.LBB0_17:
ldr w8, [sp, #28]
add w8, w8, #1
str w8, [sp, #28]
b .LBB0_18
.LBB0_18:
b .LBB0_19
.LBB0_19:
b .LBB0_20
.LBB0_20:
ldrb w8, [sp, #42]
tbz w8, #0, .LBB0_27
b .LBB0_21
.LBB0_21:
ldr x8, [sp, #48]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #48]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_23
b .LBB0_22
.LBB0_22:
ldr w8, [sp, #24]
add w8, w8, #1
str w8, [sp, #24]
b .LBB0_26
.LBB0_23:
ldr x8, [sp, #64]
ldrsw x9, [sp, #36]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #48]
ldr w9, [x9]
subs w8, w8, w9
b.eq .LBB0_25
b .LBB0_24
.LBB0_24:
ldr w8, [sp, #20]
add w8, w8, #1
str w8, [sp, #20]
b .LBB0_25
.LBB0_25:
b .LBB0_26
.LBB0_26:
b .LBB0_27
.LBB0_27:
b .LBB0_28
.LBB0_28:
ldr w8, [sp, #36]
add w8, w8, #1
str w8, [sp, #36]
b .LBB0_1
.LBB0_29:
ldrb w8, [sp, #43]
tbz w8, #0, .LBB0_34
b .LBB0_30
.LBB0_30:
ldr w8, [sp, #32]
ldr w9, [sp, #28]
subs w8, w8, w9
b.ge .LBB0_32
b .LBB0_31
.LBB0_31:
ldr w8, [sp, #32]
str w8, [sp, #16]
b .LBB0_33
.LBB0_32:
ldr w8, [sp, #28]
str w8, [sp, #16]
b .LBB0_33
.LBB0_33:
ldr w8, [sp, #16]
str w8, [sp, #76]
b .LBB0_40
.LBB0_34:
ldrb w8, [sp, #42]
tbz w8, #0, .LBB0_39
b .LBB0_35
.LBB0_35:
ldr w8, [sp, #20]
ldr w9, [sp, #24]
subs w8, w8, w9
b.ge .LBB0_37
b .LBB0_36
.LBB0_36:
ldr w8, [sp, #20]
str w8, [sp, #12]
b .LBB0_38
.LBB0_37:
ldr w8, [sp, #24]
str w8, [sp, #12]
b .LBB0_38
.LBB0_38:
ldr w8, [sp, #12]
str w8, [sp, #76]
b .LBB0_40
.LBB0_39:
mov w8, #-1
str w8, [sp, #76]
b .LBB0_40
.LBB0_40:
ldr w0, [sp, #76]
add sp, sp, #80
ret
|
13,957
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O1
|
armv8-a clang 21.1.0
|
minDominoRotations:
cmp w1, #1
b.lt .LBB0_21
ubfiz x14, x1, #2, #32
mov x12, xzr
mov w8, wzr
mov w9, wzr
mov w11, wzr
mov w10, wzr
mov w13, #1
mov w15, #1
b .LBB0_4
.LBB0_2:
ldr w17, [x0, x12]
cmp w17, w16
cinc w8, w8, ne
.LBB0_3:
add x12, x12, #4
cmp x14, x12
b.eq .LBB0_22
.LBB0_4:
tbz w15, #0, .LBB0_7
ldr w16, [x0, x12]
ldr w15, [x0]
cmp w16, w15
b.ne .LBB0_10
mov w15, #1
tbnz w13, #0, .LBB0_8
b .LBB0_11
.LBB0_7:
mov w15, wzr
tbz w13, #0, .LBB0_11
.LBB0_8:
ldr w16, [x2, x12]
ldr w13, [x2]
cmp w16, w13
b.ne .LBB0_12
mov w13, #1
b .LBB0_13
.LBB0_10:
ldr w16, [x2, x12]
cmp w16, w15
cset w15, eq
tbnz w13, #0, .LBB0_8
.LBB0_11:
mov w13, wzr
b .LBB0_13
.LBB0_12:
ldr w16, [x0, x12]
cmp w16, w13
cset w13, eq
.LBB0_13:
orr w16, w15, w13
cmp w16, #1
b.ne .LBB0_25
cbz w15, .LBB0_17
ldr w17, [x0, x12]
ldr w16, [x0]
cmp w17, w16
b.ne .LBB0_20
ldr w17, [x2, x12]
cmp w17, w16
cinc w11, w11, ne
.LBB0_17:
cbz w13, .LBB0_3
.LBB0_18:
ldr w17, [x2, x12]
ldr w16, [x2]
cmp w17, w16
b.eq .LBB0_2
add w9, w9, #1
b .LBB0_3
.LBB0_20:
add w10, w10, #1
cbz w13, .LBB0_3
b .LBB0_18
.LBB0_21:
mov w10, wzr
mov w11, wzr
mov w9, wzr
mov w8, wzr
mov w15, #1
mov w13, #1
.LBB0_22:
cbz w15, .LBB0_24
cmp w10, w11
csel w0, w10, w11, lt
ret
.LBB0_24:
cmp w8, w9
csel w8, w8, w9, lt
cmp w13, #0
csinv w0, w8, wzr, ne
ret
.LBB0_25:
mov w0, #-1
ret
|
13,958
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O2
|
armv8-a clang 21.1.0
|
minDominoRotations:
cmp w1, #1
b.lt .LBB0_21
ubfiz x13, x1, #2, #32
mov x12, xzr
mov w10, wzr
mov w11, wzr
mov w8, wzr
mov w9, wzr
mov w14, #1
mov w15, #1
b .LBB0_4
.LBB0_2:
ldr w17, [x0, x12]
cmp w17, w16
cinc w10, w10, ne
.LBB0_3:
add x12, x12, #4
cmp x13, x12
b.eq .LBB0_22
.LBB0_4:
tbz w15, #0, .LBB0_7
ldr w16, [x0, x12]
ldr w15, [x0]
cmp w16, w15
b.ne .LBB0_10
mov w15, #1
tbnz w14, #0, .LBB0_8
b .LBB0_11
.LBB0_7:
mov w15, wzr
tbz w14, #0, .LBB0_11
.LBB0_8:
ldr w16, [x2, x12]
ldr w14, [x2]
cmp w16, w14
b.ne .LBB0_12
mov w14, #1
b .LBB0_14
.LBB0_10:
ldr w16, [x2, x12]
cmp w16, w15
cset w15, eq
tbnz w14, #0, .LBB0_8
.LBB0_11:
mov w14, wzr
b .LBB0_13
.LBB0_12:
ldr w16, [x0, x12]
cmp w16, w14
cset w14, eq
.LBB0_13:
orr w16, w15, w14
cmp w16, #1
b.ne .LBB0_24
.LBB0_14:
cbz w15, .LBB0_17
ldr w16, [x0, x12]
ldr w17, [x0]
cmp w16, w17
b.ne .LBB0_20
ldr w17, [x2, x12]
cmp w17, w16
cinc w8, w8, ne
.LBB0_17:
cbz w14, .LBB0_3
.LBB0_18:
ldr w16, [x2, x12]
ldr w17, [x2]
cmp w16, w17
b.eq .LBB0_2
add w11, w11, #1
b .LBB0_3
.LBB0_20:
add w9, w9, #1
cbz w14, .LBB0_3
b .LBB0_18
.LBB0_21:
mov w8, wzr
mov w9, wzr
b .LBB0_23
.LBB0_22:
cbz w15, .LBB0_25
.LBB0_23:
cmp w9, w8
csel w0, w9, w8, lt
ret
.LBB0_24:
mov w0, #-1
ret
.LBB0_25:
cmp w10, w11
csel w8, w10, w11, lt
cmp w14, #0
csinv w0, w8, wzr, ne
ret
|
13,959
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O3
|
armv8-a clang 21.1.0
|
minDominoRotations:
cmp w1, #1
b.lt .LBB0_20
ubfiz x13, x1, #2, #32
mov x12, xzr
mov w10, wzr
mov w11, wzr
mov w8, wzr
mov w9, wzr
mov w14, #1
mov w15, #1
b .LBB0_4
.LBB0_2:
ldr w17, [x0, x12]
cmp w17, w16
cinc w10, w10, ne
.LBB0_3:
add x12, x12, #4
cmp x13, x12
b.eq .LBB0_21
.LBB0_4:
tbz w15, #0, .LBB0_7
ldr w16, [x0, x12]
ldr w15, [x0]
cmp w16, w15
b.ne .LBB0_10
mov w15, #1
tbnz w14, #0, .LBB0_8
b .LBB0_11
.LBB0_7:
mov w15, wzr
tbz w14, #0, .LBB0_11
.LBB0_8:
ldr w16, [x2, x12]
ldr w14, [x2]
cmp w16, w14
b.ne .LBB0_12
mov w14, #1
b .LBB0_13
.LBB0_10:
ldr w16, [x2, x12]
cmp w16, w15
cset w15, eq
tbnz w14, #0, .LBB0_8
.LBB0_11:
mov w14, wzr
orr w16, w15, wzr
cmp w16, #1
b.eq .LBB0_13
b .LBB0_23
.LBB0_12:
ldr w16, [x0, x12]
cmp w16, w14
cset w14, eq
orr w16, w15, w14
cmp w16, #1
b.ne .LBB0_23
.LBB0_13:
cbnz w15, .LBB0_17
cbz w14, .LBB0_3
.LBB0_15:
ldr w16, [x2, x12]
ldr w17, [x2]
cmp w16, w17
b.eq .LBB0_2
add w11, w11, #1
b .LBB0_3
.LBB0_17:
ldr w16, [x0, x12]
ldr w17, [x0]
cmp w16, w17
b.ne .LBB0_19
ldr w17, [x2, x12]
cmp w17, w16
cinc w8, w8, ne
cbz w14, .LBB0_3
b .LBB0_15
.LBB0_19:
add w9, w9, #1
cbz w14, .LBB0_3
b .LBB0_15
.LBB0_20:
cmp wzr, wzr
csel w0, wzr, wzr, lt
ret
.LBB0_21:
cbz w15, .LBB0_24
cmp w9, w8
csel w0, w9, w8, lt
ret
.LBB0_23:
mov w0, #-1
ret
.LBB0_24:
cmp w10, w11
csel w8, w10, w11, lt
cmp w14, #0
csinv w0, w8, wzr, ne
ret
|
13,960
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O0
|
mips64 clang 21.1.0
|
minDominoRotations:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -96
sd $ra, 88($sp)
sd $fp, 80($sp)
move $fp, $sp
move $1, $7
move $2, $5
sd $4, 64($fp)
sw $2, 60($fp)
sd $6, 48($fp)
sw $1, 44($fp)
addiu $1, $zero, 1
sb $1, 42($fp)
sb $1, 43($fp)
sw $zero, 20($fp)
sw $zero, 24($fp)
sw $zero, 28($fp)
sw $zero, 32($fp)
sw $zero, 36($fp)
b .LBB0_1
nop
.LBB0_1:
lw $1, 36($fp)
lw $2, 60($fp)
slt $1, $1, $2
beqz $1, .LBB0_44
nop
b .LBB0_3
nop
.LBB0_3:
lbu $1, 43($fp)
andi $1, $1, 1
beqz $1, .LBB0_10
nop
b .LBB0_5
nop
.LBB0_5:
ld $2, 64($fp)
lw $1, 36($fp)
dsll $1, $1, 2
daddu $1, $2, $1
lw $1, 0($1)
lw $2, 0($2)
beq $1, $2, .LBB0_10
nop
b .LBB0_7
nop
.LBB0_7:
ld $1, 48($fp)
lw $2, 36($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
ld $2, 64($fp)
lw $2, 0($2)
beq $1, $2, .LBB0_10
nop
b .LBB0_9
nop
.LBB0_9:
addiu $1, $zero, 0
sb $zero, 43($fp)
b .LBB0_10
nop
.LBB0_10:
lbu $1, 42($fp)
andi $1, $1, 1
beqz $1, .LBB0_17
nop
b .LBB0_12
nop
.LBB0_12:
ld $2, 48($fp)
lw $1, 36($fp)
dsll $1, $1, 2
daddu $1, $2, $1
lw $1, 0($1)
lw $2, 0($2)
beq $1, $2, .LBB0_17
nop
b .LBB0_14
nop
.LBB0_14:
ld $1, 64($fp)
lw $2, 36($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
ld $2, 48($fp)
lw $2, 0($2)
beq $1, $2, .LBB0_17
nop
b .LBB0_16
nop
.LBB0_16:
addiu $1, $zero, 0
sb $zero, 42($fp)
b .LBB0_17
nop
.LBB0_17:
lbu $1, 43($fp)
andi $1, $1, 1
bnez $1, .LBB0_22
nop
b .LBB0_19
nop
.LBB0_19:
lbu $1, 42($fp)
andi $1, $1, 1
bnez $1, .LBB0_22
nop
b .LBB0_21
nop
.LBB0_21:
addiu $1, $zero, -1
sw $1, 76($fp)
b .LBB0_59
nop
.LBB0_22:
lbu $1, 43($fp)
andi $1, $1, 1
beqz $1, .LBB0_32
nop
b .LBB0_24
nop
.LBB0_24:
ld $2, 64($fp)
lw $1, 36($fp)
dsll $1, $1, 2
daddu $1, $2, $1
lw $1, 0($1)
lw $2, 0($2)
beq $1, $2, .LBB0_27
nop
b .LBB0_26
nop
.LBB0_26:
lw $1, 32($fp)
addiu $1, $1, 1
sw $1, 32($fp)
b .LBB0_31
nop
.LBB0_27:
ld $1, 48($fp)
lw $2, 36($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
ld $2, 64($fp)
lw $2, 0($2)
beq $1, $2, .LBB0_30
nop
b .LBB0_29
nop
.LBB0_29:
lw $1, 28($fp)
addiu $1, $1, 1
sw $1, 28($fp)
b .LBB0_30
nop
.LBB0_30:
b .LBB0_31
nop
.LBB0_31:
b .LBB0_32
nop
.LBB0_32:
lbu $1, 42($fp)
andi $1, $1, 1
beqz $1, .LBB0_42
nop
b .LBB0_34
nop
.LBB0_34:
ld $2, 48($fp)
lw $1, 36($fp)
dsll $1, $1, 2
daddu $1, $2, $1
lw $1, 0($1)
lw $2, 0($2)
beq $1, $2, .LBB0_37
nop
b .LBB0_36
nop
.LBB0_36:
lw $1, 24($fp)
addiu $1, $1, 1
sw $1, 24($fp)
b .LBB0_41
nop
.LBB0_37:
ld $1, 64($fp)
lw $2, 36($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
ld $2, 48($fp)
lw $2, 0($2)
beq $1, $2, .LBB0_40
nop
b .LBB0_39
nop
.LBB0_39:
lw $1, 20($fp)
addiu $1, $1, 1
sw $1, 20($fp)
b .LBB0_40
nop
.LBB0_40:
b .LBB0_41
nop
.LBB0_41:
b .LBB0_42
nop
.LBB0_42:
b .LBB0_43
nop
.LBB0_43:
lw $1, 36($fp)
addiu $1, $1, 1
sw $1, 36($fp)
b .LBB0_1
nop
.LBB0_44:
lbu $1, 43($fp)
andi $1, $1, 1
beqz $1, .LBB0_51
nop
b .LBB0_46
nop
.LBB0_46:
lw $1, 32($fp)
lw $2, 28($fp)
slt $1, $1, $2
beqz $1, .LBB0_49
nop
b .LBB0_48
nop
.LBB0_48:
lw $1, 32($fp)
sw $1, 16($fp)
b .LBB0_50
nop
.LBB0_49:
lw $1, 28($fp)
sw $1, 16($fp)
b .LBB0_50
nop
.LBB0_50:
lw $1, 16($fp)
sw $1, 76($fp)
b .LBB0_59
nop
.LBB0_51:
lbu $1, 42($fp)
andi $1, $1, 1
beqz $1, .LBB0_58
nop
b .LBB0_53
nop
.LBB0_53:
lw $1, 20($fp)
lw $2, 24($fp)
slt $1, $1, $2
beqz $1, .LBB0_56
nop
b .LBB0_55
nop
.LBB0_55:
lw $1, 20($fp)
sw $1, 12($fp)
b .LBB0_57
nop
.LBB0_56:
lw $1, 24($fp)
sw $1, 12($fp)
b .LBB0_57
nop
.LBB0_57:
lw $1, 12($fp)
sw $1, 76($fp)
b .LBB0_59
nop
.LBB0_58:
addiu $1, $zero, -1
sw $1, 76($fp)
b .LBB0_59
nop
.LBB0_59:
lw $2, 76($fp)
move $sp, $fp
ld $fp, 80($sp)
ld $ra, 88($sp)
daddiu $sp, $sp, 96
jr $ra
nop
|
13,961
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O1
|
mips64 clang 21.1.0
|
minDominoRotations:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -16
sd $ra, 8($sp)
sd $fp, 0($sp)
move $fp, $sp
blez $5, .LBB0_19
nop
sll $9, $5, 0
addiu $10, $zero, 1
addiu $5, $zero, 0
move $12, $4
move $13, $6
addiu $7, $zero, 0
addiu $2, $zero, 0
addiu $3, $zero, 0
addiu $8, $zero, 1
b .LBB0_4
addiu $11, $zero, 1
.LBB0_2:
lw $1, 0($12)
xor $1, $1, $14
sltu $1, $zero, $1
addu $5, $5, $1
.LBB0_3:
daddiu $9, $9, -1
daddiu $12, $12, 4
beqz $9, .LBB0_20
daddiu $13, $13, 4
.LBB0_4:
andi $1, $11, 1
beqz $1, .LBB0_7
addiu $11, $zero, 0
lw $14, 0($4)
lw $1, 0($12)
beq $1, $14, .LBB0_7
addiu $11, $zero, 1
lw $1, 0($13)
xor $1, $1, $14
sltiu $11, $1, 1
.LBB0_7:
andi $1, $8, 1
beqz $1, .LBB0_10
addiu $8, $zero, 0
lw $14, 0($6)
lw $1, 0($13)
beq $1, $14, .LBB0_10
addiu $8, $zero, 1
lw $1, 0($12)
xor $1, $1, $14
sltiu $8, $1, 1
.LBB0_10:
or $1, $11, $8
bne $1, $10, .LBB0_23
nop
beqz $11, .LBB0_14
nop
lw $14, 0($4)
lw $1, 0($12)
bne $1, $14, .LBB0_17
nop
lw $1, 0($13)
xor $1, $1, $14
sltu $1, $zero, $1
addu $2, $2, $1
.LBB0_14:
beqz $8, .LBB0_3
nop
.LBB0_15:
lw $14, 0($6)
lw $1, 0($13)
beq $1, $14, .LBB0_2
nop
b .LBB0_3
addiu $7, $7, 1
.LBB0_17:
beqz $8, .LBB0_3
addiu $3, $3, 1
b .LBB0_15
nop
.LBB0_19:
addiu $3, $zero, 0
addiu $11, $zero, 1
addiu $8, $zero, 1
addiu $2, $zero, 0
addiu $7, $zero, 0
addiu $5, $zero, 0
.LBB0_20:
beqz $11, .LBB0_22
nop
slt $1, $3, $2
b .LBB0_24
movn $2, $3, $1
.LBB0_22:
slt $1, $5, $7
movn $7, $5, $1
addiu $2, $zero, -1
b .LBB0_24
movn $2, $7, $8
.LBB0_23:
addiu $2, $zero, -1
.LBB0_24:
sll $2, $2, 0
move $sp, $fp
ld $fp, 0($sp)
ld $ra, 8($sp)
jr $ra
daddiu $sp, $sp, 16
|
13,962
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O2
|
mips64 clang 21.1.0
|
minDominoRotations:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -16
sd $ra, 8($sp)
sd $fp, 0($sp)
move $fp, $sp
blez $5, .LBB0_19
nop
sll $8, $5, 0
addiu $9, $zero, 1
addiu $3, $zero, 0
move $10, $4
move $11, $6
addiu $5, $zero, 0
addiu $2, $zero, 0
addiu $7, $zero, 0
addiu $12, $zero, 1
b .LBB0_4
addiu $13, $zero, 1
.LBB0_2:
lw $1, 0($10)
xor $1, $1, $14
sltu $1, $zero, $1
addu $3, $3, $1
.LBB0_3:
daddiu $8, $8, -1
daddiu $10, $10, 4
beqz $8, .LBB0_20
daddiu $11, $11, 4
.LBB0_4:
andi $1, $13, 1
beqz $1, .LBB0_7
addiu $13, $zero, 0
lw $14, 0($4)
lw $1, 0($10)
beq $1, $14, .LBB0_7
addiu $13, $zero, 1
lw $1, 0($11)
xor $1, $1, $14
sltiu $13, $1, 1
.LBB0_7:
andi $1, $12, 1
beqz $1, .LBB0_10
addiu $12, $zero, 0
lw $14, 0($6)
lw $1, 0($11)
beq $1, $14, .LBB0_11
addiu $12, $zero, 1
lw $1, 0($10)
xor $1, $1, $14
sltiu $12, $1, 1
.LBB0_10:
or $1, $13, $12
bne $1, $9, .LBB0_22
nop
.LBB0_11:
beqz $13, .LBB0_14
nop
lw $14, 0($10)
lw $1, 0($4)
bne $14, $1, .LBB0_17
nop
lw $1, 0($11)
xor $1, $1, $14
sltu $1, $zero, $1
addu $2, $2, $1
.LBB0_14:
beqz $12, .LBB0_3
nop
.LBB0_15:
lw $14, 0($11)
lw $1, 0($6)
beq $14, $1, .LBB0_2
nop
b .LBB0_3
addiu $5, $5, 1
.LBB0_17:
beqz $12, .LBB0_3
addiu $7, $7, 1
b .LBB0_15
nop
.LBB0_19:
addiu $2, $zero, 0
b .LBB0_21
addiu $7, $zero, 0
.LBB0_20:
beqz $13, .LBB0_23
nop
.LBB0_21:
slt $1, $7, $2
b .LBB0_24
movn $2, $7, $1
.LBB0_22:
b .LBB0_24
addiu $2, $zero, -1
.LBB0_23:
slt $1, $3, $5
movn $5, $3, $1
addiu $2, $zero, -1
movn $2, $5, $12
.LBB0_24:
sll $2, $2, 0
move $sp, $fp
ld $fp, 0($sp)
ld $ra, 8($sp)
jr $ra
daddiu $sp, $sp, 16
|
13,963
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O3
|
mips64 clang 21.1.0
|
minDominoRotations:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -16
sd $ra, 8($sp)
sd $fp, 0($sp)
move $fp, $sp
blez $5, .LBB0_20
nop
sll $8, $5, 0
addiu $9, $zero, 1
addiu $3, $zero, 0
move $10, $4
move $11, $6
addiu $5, $zero, 0
addiu $2, $zero, 0
addiu $7, $zero, 0
addiu $12, $zero, 1
b .LBB0_4
addiu $13, $zero, 1
.LBB0_2:
lw $1, 0($10)
xor $1, $1, $14
sltu $1, $zero, $1
addu $3, $3, $1
.LBB0_3:
daddiu $8, $8, -1
daddiu $10, $10, 4
beqz $8, .LBB0_21
daddiu $11, $11, 4
.LBB0_4:
andi $1, $13, 1
beqz $1, .LBB0_7
addiu $13, $zero, 0
lw $14, 0($4)
lw $1, 0($10)
beq $1, $14, .LBB0_7
addiu $13, $zero, 1
lw $1, 0($11)
xor $1, $1, $14
sltiu $13, $1, 1
.LBB0_7:
andi $1, $12, 1
beqz $1, .LBB0_10
addiu $12, $zero, 0
lw $14, 0($6)
lw $1, 0($11)
beq $1, $14, .LBB0_11
addiu $12, $zero, 1
lw $1, 0($10)
xor $1, $1, $14
sltiu $12, $1, 1
.LBB0_10:
or $1, $13, $12
bne $1, $9, .LBB0_23
nop
.LBB0_11:
bnez $13, .LBB0_15
nop
beqz $12, .LBB0_3
nop
.LBB0_13:
lw $14, 0($11)
lw $1, 0($6)
beq $14, $1, .LBB0_2
nop
b .LBB0_3
addiu $5, $5, 1
.LBB0_15:
lw $14, 0($10)
lw $1, 0($4)
bne $14, $1, .LBB0_18
nop
lw $1, 0($11)
xor $1, $1, $14
sltu $1, $zero, $1
beqz $12, .LBB0_3
addu $2, $2, $1
b .LBB0_13
nop
.LBB0_18:
beqz $12, .LBB0_3
addiu $7, $7, 1
b .LBB0_13
nop
.LBB0_20:
addiu $2, $zero, 0
b .LBB0_22
addiu $7, $zero, 0
.LBB0_21:
beqz $13, .LBB0_24
nop
.LBB0_22:
slt $1, $7, $2
b .LBB0_25
movn $2, $7, $1
.LBB0_23:
b .LBB0_25
addiu $2, $zero, -1
.LBB0_24:
slt $1, $3, $5
addiu $2, $zero, -1
movn $5, $3, $1
movn $2, $5, $12
.LBB0_25:
sll $2, $2, 0
move $sp, $fp
ld $fp, 0($sp)
ld $ra, 8($sp)
jr $ra
daddiu $sp, $sp, 16
|
13,964
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O0
|
mips64 gcc 15.2.0
|
minDominoRotations:
daddiu $sp,$sp,-80
sd $fp,72($sp)
move $fp,$sp
sd $4,32($fp)
move $3,$5
sd $6,48($fp)
move $2,$7
sll $3,$3,0
sw $3,40($fp)
sll $2,$2,0
sw $2,44($fp)
li $2,1 # 0x1
sb $2,1($fp)
lbu $2,1($fp)
sb $2,0($fp)
sw $0,20($fp)
lw $2,20($fp)
sw $2,16($fp)
lw $2,16($fp)
sw $2,12($fp)
lw $2,12($fp)
sw $2,8($fp)
sw $0,4($fp)
b .L2
nop
.L11:
lbu $2,0($fp)
beq $2,$0,.L3
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,32($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,32($fp)
lw $3,0($3)
beq $2,$3,.L3
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,48($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,32($fp)
lw $3,0($3)
beq $2,$3,.L3
nop
sb $0,0($fp)
.L3:
lbu $2,1($fp)
beq $2,$0,.L4
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,48($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,48($fp)
lw $3,0($3)
beq $2,$3,.L4
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,32($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,48($fp)
lw $3,0($3)
beq $2,$3,.L4
nop
sb $0,1($fp)
.L4:
lbu $2,0($fp)
xori $2,$2,0x1
andi $2,$2,0x00ff
beq $2,$0,.L5
nop
lbu $2,1($fp)
xori $2,$2,0x1
andi $2,$2,0x00ff
beq $2,$0,.L5
nop
li $2,-1 # 0xffffffffffffffff
b .L6
nop
.L5:
lbu $2,0($fp)
beq $2,$0,.L7
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,32($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,32($fp)
lw $3,0($3)
beq $2,$3,.L8
nop
lw $2,8($fp)
addiu $2,$2,1
sw $2,8($fp)
b .L7
nop
.L8:
lw $2,4($fp)
dsll $2,$2,2
ld $3,48($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,32($fp)
lw $3,0($3)
beq $2,$3,.L7
nop
lw $2,12($fp)
addiu $2,$2,1
sw $2,12($fp)
.L7:
lbu $2,1($fp)
beq $2,$0,.L9
nop
lw $2,4($fp)
dsll $2,$2,2
ld $3,48($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,48($fp)
lw $3,0($3)
beq $2,$3,.L10
nop
lw $2,16($fp)
addiu $2,$2,1
sw $2,16($fp)
b .L9
nop
.L10:
lw $2,4($fp)
dsll $2,$2,2
ld $3,32($fp)
daddu $2,$3,$2
lw $2,0($2)
ld $3,48($fp)
lw $3,0($3)
beq $2,$3,.L9
nop
lw $2,20($fp)
addiu $2,$2,1
sw $2,20($fp)
.L9:
lw $2,4($fp)
addiu $2,$2,1
sw $2,4($fp)
.L2:
lw $3,4($fp)
lw $2,40($fp)
slt $2,$3,$2
bne $2,$0,.L11
nop
lbu $2,0($fp)
beq $2,$0,.L12
nop
lw $3,8($fp)
lw $2,12($fp)
slt $4,$3,$2
beq $4,$0,.L13
nop
move $2,$3
.L13:
b .L6
nop
.L12:
lbu $2,1($fp)
beq $2,$0,.L14
nop
lw $3,20($fp)
lw $2,16($fp)
slt $4,$3,$2
beq $4,$0,.L15
nop
move $2,$3
.L15:
b .L6
nop
.L14:
li $2,-1 # 0xffffffffffffffff
.L6:
move $sp,$fp
ld $fp,72($sp)
daddiu $sp,$sp,80
jr $31
nop
|
13,965
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O1
|
mips64 gcc 15.2.0
|
minDominoRotations:
blez $5,.L20
move $2,$4
move $3,$6
dsll $5,$5,2
daddu $9,$5,$4
move $14,$0
move $11,$0
move $15,$0
move $12,$0
li $5,1 # 0x1
li $7,1 # 0x1
b .L14
li $13,1 # 0x1
.L31:
bne $7,$0,.L7
lw $8,0($2)
beql $5,$8,.L33
lw $5,0($6)
jr $31
li $2,-1 # 0xffffffffffffffff
.L7:
xor $5,$5,$8
b .L18
sltu $5,$5,1
.L10:
bnel $10,$8,.L11
addiu $15,$15,1
b .L11
nop
.L13:
beql $8,$5,.L12
li $5,1 # 0x1
addiu $14,$14,1
b .L12
move $5,$13
.L29:
bnel $7,$0,.L34
move $2,$12
beq $5,$0,.L22
nop
move $2,$11
slt $11,$14,$11
beq $11,$0,.L36
nop
jr $31
move $2,$14
.L20:
move $15,$0
move $12,$0
move $2,$12
.L34:
slt $12,$15,$12
beq $12,$0,.L36
nop
jr $31
move $2,$15
.L22:
jr $31
li $2,-1 # 0xffffffffffffffff
.L4:
bnel $5,$0,.L19
move $7,$5
.L18:
lw $8,0($4)
lw $10,0($2)
.L35:
beql $10,$8,.L10
lw $10,0($3)
addiu $12,$12,1
.L11:
bnel $5,$0,.L33
lw $5,0($6)
.L12:
daddiu $2,$2,4
beq $9,$2,.L29
daddiu $3,$3,4
.L14:
beq $7,$0,.L3
nop
lw $8,0($4)
lw $10,0($2)
beq $10,$8,.L4
nop
lw $10,0($3)
xor $7,$8,$10
bne $5,$0,.L19
sltu $7,$7,1
beql $8,$10,.L35
lw $10,0($2)
jr $31
li $2,-1 # 0xffffffffffffffff
.L3:
beql $5,$0,.L36
li $2,-1 # 0xffffffffffffffff
.L19:
lw $5,0($6)
lw $8,0($3)
bne $8,$5,.L31
nop
bnel $7,$0,.L18
move $5,$7
.L33:
lw $8,0($3)
beql $8,$5,.L13
lw $8,0($2)
addiu $11,$11,1
b .L12
move $5,$13
.L36:
jr $31
nop
|
13,966
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O2
|
mips64 gcc 15.2.0
|
minDominoRotations:
blez $5,.L38
dsll $5,$5,32
lw $11,0($4)
dsrl $5,$5,32
move $7,$6
dsll $5,$5,2
move $3,$0
move $15,$0
move $2,$0
move $13,$0
move $14,$0
li $10,1 # 0x1
.L3:
lw $12,0($4)
beq $12,$11,.L66
lw $9,0($7)
.L29:
beq $9,$11,.L7
nop
beq $10,$0,.L43
nop
lw $8,0($6)
beq $9,$8,.L67
nop
bne $12,$8,.L43
daddiu $3,$3,4
beq $5,$3,.L17
addiu $2,$2,1
daddiu $7,$7,4
daddiu $4,$4,4
.L18:
move $9,$8
.L16:
lw $10,0($7)
beq $10,$9,.L68
lw $12,0($4)
bne $12,$8,.L43
move $10,$0
lw $9,0($7)
.L21:
beql $9,$8,.L73
lw $12,0($4)
.L69:
daddiu $3,$3,4
beq $5,$3,.L15
addiu $2,$2,1
.L59:
daddiu $7,$7,4
.L75:
beq $10,$0,.L18
daddiu $4,$4,4
lw $12,0($4)
lw $9,0($7)
bne $12,$11,.L29
li $10,1 # 0x1
.L66:
beq $10,$0,.L4
nop
lw $8,0($6)
beq $8,$9,.L22
nop
bne $12,$8,.L4
nop
.L22:
beq $9,$11,.L21
nop
bne $9,$8,.L69
addiu $13,$13,1
lw $12,0($4)
.L73:
bne $12,$9,.L74
daddiu $3,$3,4
bnel $5,$3,.L75
daddiu $7,$7,4
.L15:
bnel $10,$0,.L76
slt $3,$13,$14
.L17:
slt $3,$15,$2
.L72:
beq $3,$0,.L78
nop
jr $31
move $2,$15
.L7:
beql $10,$0,.L77
daddiu $3,$3,4
lw $8,0($6)
beql $11,$8,.L21
addiu $14,$14,1
beql $12,$8,.L21
addiu $14,$14,1
daddiu $3,$3,4
.L77:
addiu $14,$14,1
.L61:
beql $5,$3,.L76
slt $3,$13,$14
lw $8,4($4)
daddiu $7,$7,4
daddiu $4,$4,4
beq $8,$11,.L4
lw $9,0($7)
beq $9,$11,.L77
daddiu $3,$3,4
.L43:
jr $31
li $2,-1 # 0xffffffffffffffff
.L68:
beq $12,$8,.L70
move $10,$0
daddiu $3,$3,4
.L74:
bne $5,$3,.L59
addiu $15,$15,1
b .L15
nop
.L4:
beq $9,$11,.L61
daddiu $3,$3,4
addiu $13,$13,1
daddiu $7,$7,4
daddiu $4,$4,4
bne $3,$5,.L3
move $10,$0
slt $3,$13,$14
.L76:
bne $3,$0,.L71
move $2,$14
.L78:
jr $31
nop
.L67:
beq $12,$8,.L64
daddiu $3,$3,4
addiu $15,$15,1
.L64:
beql $5,$3,.L72
slt $3,$15,$2
daddiu $7,$7,4
b .L18
daddiu $4,$4,4
.L70:
daddiu $3,$3,4
daddiu $7,$7,4
bne $5,$3,.L16
daddiu $4,$4,4
b .L72
slt $3,$15,$2
.L71:
jr $31
move $2,$13
.L38:
jr $31
move $2,$0
|
13,967
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O3
|
mips64 gcc 15.2.0
|
minDominoRotations:
daddiu $sp,$sp,-16
blez $5,.L38
dsll $5,$5,32
lw $13,0($4)
dsrl $5,$5,32
move $7,$6
dsll $5,$5,2
move $3,$0
move $24,$0
move $2,$0
move $14,$0
move $15,$0
li $10,1 # 0x1
.L3:
lw $12,0($4)
beq $12,$13,.L66
lw $9,0($7)
.L29:
beq $9,$13,.L7
nop
beql $10,$0,.L54
li $2,-1 # 0xffffffffffffffff
lw $8,0($6)
beq $9,$8,.L67
nop
bnel $12,$8,.L54
li $2,-1 # 0xffffffffffffffff
daddiu $3,$3,4
beq $5,$3,.L17
addiu $2,$2,1
daddiu $7,$7,4
daddiu $4,$4,4
.L18:
move $9,$8
.L16:
lw $10,0($7)
beq $10,$9,.L68
lw $11,0($4)
bnel $11,$8,.L54
li $2,-1 # 0xffffffffffffffff
lw $9,0($7)
move $10,$0
.L21:
beql $11,$9,.L72
lw $11,0($4)
.L69:
daddiu $3,$3,4
beq $5,$3,.L15
addiu $2,$2,1
.L59:
daddiu $7,$7,4
.L74:
beq $10,$0,.L18
daddiu $4,$4,4
lw $12,0($4)
lw $9,0($7)
bne $12,$13,.L29
li $10,1 # 0x1
.L66:
beq $10,$0,.L4
nop
lw $8,0($6)
beq $8,$9,.L22
move $11,$8
bne $12,$8,.L4
nop
.L22:
beq $9,$13,.L21
nop
move $11,$8
bne $11,$9,.L69
addiu $14,$14,1
lw $11,0($4)
.L72:
bne $11,$9,.L73
daddiu $3,$3,4
bnel $5,$3,.L74
daddiu $7,$7,4
.L15:
bnel $10,$0,.L75
slt $3,$14,$15
.L17:
slt $3,$24,$2
.L71:
beq $3,$0,.L54
nop
move $2,$24
jr $31
daddiu $sp,$sp,16
.L7:
beql $10,$0,.L76
daddiu $3,$3,4
lw $8,0($6)
beq $13,$8,.L11
move $11,$8
beql $12,$8,.L21
addiu $15,$15,1
daddiu $3,$3,4
.L76:
addiu $15,$15,1
.L61:
beql $5,$3,.L75
slt $3,$14,$15
lw $12,4($4)
daddiu $7,$7,4
daddiu $4,$4,4
beq $12,$13,.L4
lw $9,0($7)
beql $9,$13,.L76
daddiu $3,$3,4
li $2,-1 # 0xffffffffffffffff
.L54:
jr $31
daddiu $sp,$sp,16
.L68:
beq $11,$8,.L70
move $10,$0
daddiu $3,$3,4
.L73:
bne $5,$3,.L59
addiu $24,$24,1
b .L15
nop
.L11:
b .L21
addiu $15,$15,1
.L4:
beq $9,$13,.L61
daddiu $3,$3,4
addiu $14,$14,1
daddiu $7,$7,4
daddiu $4,$4,4
bne $5,$3,.L3
move $10,$0
slt $3,$14,$15
.L75:
beq $3,$0,.L54
move $2,$15
move $2,$14
jr $31
daddiu $sp,$sp,16
.L67:
beq $12,$8,.L64
daddiu $3,$3,4
addiu $24,$24,1
.L64:
beql $5,$3,.L71
slt $3,$24,$2
daddiu $7,$7,4
b .L18
daddiu $4,$4,4
.L70:
daddiu $3,$3,4
daddiu $7,$7,4
bne $5,$3,.L16
daddiu $4,$4,4
b .L71
slt $3,$24,$2
.L38:
b .L54
move $2,$0
|
13,968
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O0
|
RISC-V 64 clang 21.1.0
|
minDominoRotations:
addi sp, sp, -96
sd ra, 88(sp)
sd s0, 80(sp)
addi s0, sp, 96
sd a0, -32(s0)
sw a1, -36(s0)
sd a2, -48(s0)
sw a3, -52(s0)
li a0, 1
sb a0, -54(s0)
sb a0, -53(s0)
li a0, 0
sw a0, -76(s0)
sw a0, -72(s0)
sw a0, -68(s0)
sw a0, -64(s0)
sw a0, -60(s0)
j .LBB0_1
.LBB0_1:
lw a0, -60(s0)
lw a1, -36(s0)
bge a0, a1, .LBB0_29
j .LBB0_2
.LBB0_2:
lbu a0, -53(s0)
andi a0, a0, 1
beqz a0, .LBB0_6
j .LBB0_3
.LBB0_3:
ld a1, -32(s0)
lw a0, -60(s0)
slli a0, a0, 2
add a0, a0, a1
lw a0, 0(a0)
lw a1, 0(a1)
beq a0, a1, .LBB0_6
j .LBB0_4
.LBB0_4:
ld a0, -48(s0)
lw a1, -60(s0)
slli a1, a1, 2
add a0, a0, a1
lw a0, 0(a0)
ld a1, -32(s0)
lw a1, 0(a1)
beq a0, a1, .LBB0_6
j .LBB0_5
.LBB0_5:
li a0, 0
sb a0, -53(s0)
j .LBB0_6
.LBB0_6:
lbu a0, -54(s0)
andi a0, a0, 1
beqz a0, .LBB0_10
j .LBB0_7
.LBB0_7:
ld a1, -48(s0)
lw a0, -60(s0)
slli a0, a0, 2
add a0, a0, a1
lw a0, 0(a0)
lw a1, 0(a1)
beq a0, a1, .LBB0_10
j .LBB0_8
.LBB0_8:
ld a0, -32(s0)
lw a1, -60(s0)
slli a1, a1, 2
add a0, a0, a1
lw a0, 0(a0)
ld a1, -48(s0)
lw a1, 0(a1)
beq a0, a1, .LBB0_10
j .LBB0_9
.LBB0_9:
li a0, 0
sb a0, -54(s0)
j .LBB0_10
.LBB0_10:
lbu a0, -53(s0)
andi a0, a0, 1
bnez a0, .LBB0_13
j .LBB0_11
.LBB0_11:
lbu a0, -54(s0)
andi a0, a0, 1
bnez a0, .LBB0_13
j .LBB0_12
.LBB0_12:
li a0, -1
sw a0, -20(s0)
j .LBB0_40
.LBB0_13:
lbu a0, -53(s0)
andi a0, a0, 1
beqz a0, .LBB0_20
j .LBB0_14
.LBB0_14:
ld a1, -32(s0)
lw a0, -60(s0)
slli a0, a0, 2
add a0, a0, a1
lw a0, 0(a0)
lw a1, 0(a1)
beq a0, a1, .LBB0_16
j .LBB0_15
.LBB0_15:
lw a0, -64(s0)
addiw a0, a0, 1
sw a0, -64(s0)
j .LBB0_19
.LBB0_16:
ld a0, -48(s0)
lw a1, -60(s0)
slli a1, a1, 2
add a0, a0, a1
lw a0, 0(a0)
ld a1, -32(s0)
lw a1, 0(a1)
beq a0, a1, .LBB0_18
j .LBB0_17
.LBB0_17:
lw a0, -68(s0)
addiw a0, a0, 1
sw a0, -68(s0)
j .LBB0_18
.LBB0_18:
j .LBB0_19
.LBB0_19:
j .LBB0_20
.LBB0_20:
lbu a0, -54(s0)
andi a0, a0, 1
beqz a0, .LBB0_27
j .LBB0_21
.LBB0_21:
ld a1, -48(s0)
lw a0, -60(s0)
slli a0, a0, 2
add a0, a0, a1
lw a0, 0(a0)
lw a1, 0(a1)
beq a0, a1, .LBB0_23
j .LBB0_22
.LBB0_22:
lw a0, -72(s0)
addiw a0, a0, 1
sw a0, -72(s0)
j .LBB0_26
.LBB0_23:
ld a0, -32(s0)
lw a1, -60(s0)
slli a1, a1, 2
add a0, a0, a1
lw a0, 0(a0)
ld a1, -48(s0)
lw a1, 0(a1)
beq a0, a1, .LBB0_25
j .LBB0_24
.LBB0_24:
lw a0, -76(s0)
addiw a0, a0, 1
sw a0, -76(s0)
j .LBB0_25
.LBB0_25:
j .LBB0_26
.LBB0_26:
j .LBB0_27
.LBB0_27:
j .LBB0_28
.LBB0_28:
lw a0, -60(s0)
addiw a0, a0, 1
sw a0, -60(s0)
j .LBB0_1
.LBB0_29:
lbu a0, -53(s0)
andi a0, a0, 1
beqz a0, .LBB0_34
j .LBB0_30
.LBB0_30:
lw a0, -64(s0)
lw a1, -68(s0)
bge a0, a1, .LBB0_32
j .LBB0_31
.LBB0_31:
lw a0, -64(s0)
sd a0, -88(s0)
j .LBB0_33
.LBB0_32:
lw a0, -68(s0)
sd a0, -88(s0)
j .LBB0_33
.LBB0_33:
ld a0, -88(s0)
sw a0, -20(s0)
j .LBB0_40
.LBB0_34:
lbu a0, -54(s0)
andi a0, a0, 1
beqz a0, .LBB0_39
j .LBB0_35
.LBB0_35:
lw a0, -76(s0)
lw a1, -72(s0)
bge a0, a1, .LBB0_37
j .LBB0_36
.LBB0_36:
lw a0, -76(s0)
sd a0, -96(s0)
j .LBB0_38
.LBB0_37:
lw a0, -72(s0)
sd a0, -96(s0)
j .LBB0_38
.LBB0_38:
ld a0, -96(s0)
sw a0, -20(s0)
j .LBB0_40
.LBB0_39:
li a0, -1
sw a0, -20(s0)
j .LBB0_40
.LBB0_40:
lw a0, -20(s0)
ld ra, 88(sp)
ld s0, 80(sp)
addi sp, sp, 96
ret
|
13,969
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O1
|
RISC-V 64 clang 21.1.0
|
minDominoRotations:
blez a1, .LBB0_20
mv t1, a0
li t0, 0
li a7, 0
li a6, 0
li a0, 0
li t2, 1
mv a3, t1
mv a4, a2
li t3, 1
j .LBB0_4
.LBB0_2:
lw a5, 0(a3)
xor a5, a5, t5
snez a5, a5
addw t0, t0, a5
.LBB0_3:
addi a4, a4, 4
addi a1, a1, -1
addi a3, a3, 4
beqz a1, .LBB0_21
.LBB0_4:
andi a5, t3, 1
beqz a5, .LBB0_7
lw t3, 0(a3)
lw t4, 0(t1)
bne t3, t4, .LBB0_10
li t3, 1
andi a5, t2, 1
bnez a5, .LBB0_8
j .LBB0_11
.LBB0_7:
li t3, 0
andi a5, t2, 1
beqz a5, .LBB0_11
.LBB0_8:
lw t2, 0(a4)
lw t4, 0(a2)
bne t2, t4, .LBB0_12
li t2, 1
or a5, t3, t2
bnez a5, .LBB0_13
j .LBB0_28
.LBB0_10:
lw a5, 0(a4)
xor a5, a5, t4
seqz t3, a5
andi a5, t2, 1
bnez a5, .LBB0_8
.LBB0_11:
li t2, 0
or a5, t3, t2
bnez a5, .LBB0_13
j .LBB0_28
.LBB0_12:
lw a5, 0(a3)
xor a5, a5, t4
seqz t2, a5
or a5, t3, t2
beqz a5, .LBB0_28
.LBB0_13:
beqz t3, .LBB0_16
lw t4, 0(a3)
lw t5, 0(t1)
bne t4, t5, .LBB0_19
lw a5, 0(a4)
xor a5, a5, t5
snez a5, a5
addw a6, a6, a5
.LBB0_16:
beqz t2, .LBB0_3
.LBB0_17:
lw t4, 0(a4)
lw t5, 0(a2)
beq t4, t5, .LBB0_2
addiw a7, a7, 1
j .LBB0_3
.LBB0_19:
addiw a0, a0, 1
beqz t2, .LBB0_3
j .LBB0_17
.LBB0_20:
li a0, 0
li a6, 0
li a7, 0
li t0, 0
li t3, 1
li t2, 1
.LBB0_21:
beqz t3, .LBB0_24
blt a0, a6, .LBB0_27
mv a0, a6
ret
.LBB0_24:
blt t0, a7, .LBB0_26
mv t0, a7
.LBB0_26:
addi t2, t2, -1
or a0, t2, t0
.LBB0_27:
ret
.LBB0_28:
li a0, -1
ret
|
13,970
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O2
|
RISC-V 64 clang 21.1.0
|
minDominoRotations:
blez a1, .LBB0_20
mv t1, a0
li a7, 0
li a6, 0
li t0, 0
li a0, 0
li t2, 1
mv a3, t1
mv a4, a2
li t3, 1
j .LBB0_4
.LBB0_2:
lw a5, 0(a3)
xor a5, a5, t4
snez a5, a5
addw a7, a7, a5
.LBB0_3:
addi a4, a4, 4
addi a1, a1, -1
addi a3, a3, 4
beqz a1, .LBB0_21
.LBB0_4:
andi a5, t3, 1
beqz a5, .LBB0_7
lw t3, 0(a3)
lw t4, 0(t1)
bne t3, t4, .LBB0_10
li t3, 1
andi a5, t2, 1
bnez a5, .LBB0_8
j .LBB0_11
.LBB0_7:
li t3, 0
andi a5, t2, 1
beqz a5, .LBB0_11
.LBB0_8:
lw t2, 0(a4)
lw t4, 0(a2)
bne t2, t4, .LBB0_12
li t2, 1
j .LBB0_13
.LBB0_10:
lw a5, 0(a4)
xor a5, a5, t4
seqz t3, a5
andi a5, t2, 1
bnez a5, .LBB0_8
.LBB0_11:
li t2, 0
bnez t3, .LBB0_13
j .LBB0_24
.LBB0_12:
lw a5, 0(a3)
xor a5, a5, t4
seqz t2, a5
or a5, t3, t2
beqz a5, .LBB0_24
.LBB0_13:
beqz t3, .LBB0_16
lw t4, 0(a3)
lw a5, 0(t1)
bne t4, a5, .LBB0_19
lw a5, 0(a4)
xor a5, a5, t4
snez a5, a5
addw t0, t0, a5
.LBB0_16:
beqz t2, .LBB0_3
.LBB0_17:
lw t4, 0(a4)
lw a5, 0(a2)
beq t4, a5, .LBB0_2
addiw a6, a6, 1
j .LBB0_3
.LBB0_19:
addiw a0, a0, 1
beqz t2, .LBB0_3
j .LBB0_17
.LBB0_20:
li t0, 0
li a0, 0
j .LBB0_22
.LBB0_21:
beqz t3, .LBB0_25
.LBB0_22:
blt a0, t0, .LBB0_28
mv a0, t0
ret
.LBB0_24:
li a0, -1
ret
.LBB0_25:
blt a7, a6, .LBB0_27
mv a7, a6
.LBB0_27:
addi t2, t2, -1
or a0, t2, a7
.LBB0_28:
ret
|
13,971
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O3
|
RISC-V 64 clang 21.1.0
|
minDominoRotations:
blez a1, .LBB0_20
mv t1, a0
li a7, 0
li a6, 0
li t0, 0
li a0, 0
li t2, 1
mv a3, t1
mv a4, a2
li t3, 1
j .LBB0_4
.LBB0_2:
lw a5, 0(a3)
xor a5, a5, t4
snez a5, a5
addw a7, a7, a5
.LBB0_3:
addi a4, a4, 4
addi a1, a1, -1
addi a3, a3, 4
beqz a1, .LBB0_21
.LBB0_4:
andi a5, t3, 1
beqz a5, .LBB0_7
lw t3, 0(a3)
lw t4, 0(t1)
bne t3, t4, .LBB0_10
li t3, 1
andi a5, t2, 1
bnez a5, .LBB0_8
j .LBB0_11
.LBB0_7:
li t3, 0
andi a5, t2, 1
beqz a5, .LBB0_11
.LBB0_8:
lw t2, 0(a4)
lw t4, 0(a2)
bne t2, t4, .LBB0_12
li t2, 1
j .LBB0_13
.LBB0_10:
lw a5, 0(a4)
xor a5, a5, t4
seqz t3, a5
andi a5, t2, 1
bnez a5, .LBB0_8
.LBB0_11:
li t2, 0
bnez t3, .LBB0_13
j .LBB0_24
.LBB0_12:
lw a5, 0(a3)
xor a5, a5, t4
seqz t2, a5
or a5, t3, t2
beqz a5, .LBB0_24
.LBB0_13:
bnez t3, .LBB0_17
beqz t2, .LBB0_3
.LBB0_15:
lw t4, 0(a4)
lw a5, 0(a2)
beq t4, a5, .LBB0_2
addiw a6, a6, 1
j .LBB0_3
.LBB0_17:
lw t4, 0(a3)
lw a5, 0(t1)
bne t4, a5, .LBB0_19
lw a5, 0(a4)
xor a5, a5, t4
snez a5, a5
addw t0, t0, a5
beqz t2, .LBB0_3
j .LBB0_15
.LBB0_19:
addiw a0, a0, 1
beqz t2, .LBB0_3
j .LBB0_15
.LBB0_20:
li t0, 0
li a0, 0
j .LBB0_22
.LBB0_21:
beqz t3, .LBB0_25
.LBB0_22:
blt a0, t0, .LBB0_28
mv a0, t0
ret
.LBB0_24:
li a0, -1
ret
.LBB0_25:
blt a7, a6, .LBB0_27
mv a7, a6
.LBB0_27:
addi t2, t2, -1
or a0, t2, a7
.LBB0_28:
ret
|
13,972
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O0
|
RISC-V 64 gcc 15.2.0
|
minDominoRotations:
addi sp,sp,-80
sd ra,72(sp)
sd s0,64(sp)
addi s0,sp,80
sd a0,-56(s0)
mv a5,a1
sd a2,-72(s0)
mv a4,a3
sw a5,-60(s0)
mv a5,a4
sw a5,-64(s0)
li a5,1
sb a5,-18(s0)
lbu a5,-18(s0)
sb a5,-17(s0)
sw zero,-40(s0)
lw a5,-40(s0)
sw a5,-36(s0)
lw a5,-36(s0)
sw a5,-32(s0)
lw a5,-32(s0)
sw a5,-28(s0)
sw zero,-24(s0)
j .L2
.L11:
lbu a5,-17(s0)
andi a5,a5,0xff
beq a5,zero,.L3
lw a5,-24(s0)
slli a5,a5,2
ld a4,-56(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-56(s0)
lw a5,0(a5)
beq a4,a5,.L3
lw a5,-24(s0)
slli a5,a5,2
ld a4,-72(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-56(s0)
lw a5,0(a5)
beq a4,a5,.L3
sb zero,-17(s0)
.L3:
lbu a5,-18(s0)
andi a5,a5,0xff
beq a5,zero,.L4
lw a5,-24(s0)
slli a5,a5,2
ld a4,-72(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-72(s0)
lw a5,0(a5)
beq a4,a5,.L4
lw a5,-24(s0)
slli a5,a5,2
ld a4,-56(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-72(s0)
lw a5,0(a5)
beq a4,a5,.L4
sb zero,-18(s0)
.L4:
lbu a5,-17(s0)
xori a5,a5,1
andi a5,a5,0xff
beq a5,zero,.L5
lbu a5,-18(s0)
xori a5,a5,1
andi a5,a5,0xff
beq a5,zero,.L5
li a5,-1
j .L6
.L5:
lbu a5,-17(s0)
andi a5,a5,0xff
beq a5,zero,.L7
lw a5,-24(s0)
slli a5,a5,2
ld a4,-56(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-56(s0)
lw a5,0(a5)
beq a4,a5,.L8
lw a5,-28(s0)
addiw a5,a5,1
sw a5,-28(s0)
j .L7
.L8:
lw a5,-24(s0)
slli a5,a5,2
ld a4,-72(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-56(s0)
lw a5,0(a5)
beq a4,a5,.L7
lw a5,-32(s0)
addiw a5,a5,1
sw a5,-32(s0)
.L7:
lbu a5,-18(s0)
andi a5,a5,0xff
beq a5,zero,.L9
lw a5,-24(s0)
slli a5,a5,2
ld a4,-72(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-72(s0)
lw a5,0(a5)
beq a4,a5,.L10
lw a5,-36(s0)
addiw a5,a5,1
sw a5,-36(s0)
j .L9
.L10:
lw a5,-24(s0)
slli a5,a5,2
ld a4,-56(s0)
add a5,a4,a5
lw a4,0(a5)
ld a5,-72(s0)
lw a5,0(a5)
beq a4,a5,.L9
lw a5,-40(s0)
addiw a5,a5,1
sw a5,-40(s0)
.L9:
lw a5,-24(s0)
addiw a5,a5,1
sw a5,-24(s0)
.L2:
lw a5,-24(s0)
mv a4,a5
lw a5,-60(s0)
sext.w a4,a4
sext.w a5,a5
blt a4,a5,.L11
lbu a5,-17(s0)
andi a5,a5,0xff
beq a5,zero,.L12
lw a5,-28(s0)
mv a2,a5
lw a5,-32(s0)
mv a3,a5
sext.w a4,a3
sext.w a5,a2
ble a4,a5,.L13
mv a3,a2
.L13:
sext.w a5,a3
j .L6
.L12:
lbu a5,-18(s0)
andi a5,a5,0xff
beq a5,zero,.L14
lw a5,-40(s0)
mv a2,a5
lw a5,-36(s0)
mv a3,a5
sext.w a4,a3
sext.w a5,a2
ble a4,a5,.L15
mv a3,a2
.L15:
sext.w a5,a3
j .L6
.L14:
li a5,-1
.L6:
mv a0,a5
ld ra,72(sp)
ld s0,64(sp)
addi sp,sp,80
jr ra
|
13,973
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O1
|
RISC-V 64 gcc 15.2.0
|
minDominoRotations:
ble a1,zero,.L21
mv a4,a0
mv a6,a2
slli a1,a1,2
add a1,a1,a0
li t6,0
li t1,0
li t0,0
li t3,0
li a3,1
mv a5,a3
mv t5,a3
j .L14
.L25:
mv a5,a3
j .L18
.L34:
mv a3,a5
.L19:
lw a5,0(a0)
lw a7,0(a4)
beq a7,a5,.L10
addiw t3,t3,1
.L11:
mv a5,t5
bne a3,zero,.L31
.L12:
addi a4,a4,4
addi a6,a6,4
beq a1,a4,.L32
.L14:
beq a5,zero,.L3
lw a7,0(a0)
lw a5,0(a4)
beq a5,a7,.L4
lw a5,0(a6)
sub a5,a5,a7
seqz a5,a5
bne a3,zero,.L18
.L5:
bne a3,zero,.L27
beq a5,zero,.L22
.L27:
bne a5,zero,.L19
.L9:
lw a7,0(a2)
lw t4,0(a6)
beq t4,a7,.L13
addiw t1,t1,1
j .L12
.L31:
mv a5,a3
j .L9
.L32:
bne a5,zero,.L2
beq a3,zero,.L24
mv a0,t1
ble t1,t6,.L17
mv a0,t6
.L17:
sext.w a0,a0
ret
.L21:
li t0,0
li t3,0
.L2:
mv a0,t3
ble t3,t0,.L16
mv a0,t0
.L16:
sext.w a0,a0
ret
.L22:
li a0,-1
ret
.L24:
li a0,-1
ret
.L3:
beq a3,zero,.L33
.L18:
lw a7,0(a2)
lw a3,0(a6)
beq a3,a7,.L6
lw a3,0(a4)
sub a3,a3,a7
seqz a3,a3
j .L5
.L33:
li a0,-1
ret
.L4:
bne a3,zero,.L25
lw a5,0(a0)
.L10:
lw a7,0(a6)
beq a7,a5,.L11
addiw t0,t0,1
j .L11
.L6:
bne a5,zero,.L34
lw a7,0(a2)
li a3,1
.L13:
lw t4,0(a4)
beq t4,a7,.L12
addiw t6,t6,1
j .L12
|
13,974
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O2
|
RISC-V 64 gcc 15.2.0
|
minDominoRotations:
ble a1,zero,.L41
lw a6,0(a0)
lw a4,0(a2)
slli a1,a1,2
li a5,0
li t6,0
li t1,0
li t5,0
li t4,0
.L3:
lw a7,0(a0)
beq a7,a6,.L59
lw a3,0(a2)
mv t3,a4
beq a3,a4,.L60
beq a7,a4,.L61
bne a6,a3,.L43
.L15:
addi a5,a5,4
addiw t1,t1,1
beq a1,a5,.L35
.L55:
lw a3,4(a0)
addi a0,a0,4
addi a2,a2,4
mv a4,a6
beq a3,a6,.L62
lw a3,0(a2)
beq a4,a3,.L15
.L43:
li a0,-1
ret
.L62:
lw a3,0(a2)
beq a3,a4,.L48
.L37:
addiw t5,t5,1
.L48:
addi a5,a5,4
bne a1,a5,.L55
.L35:
sext.w a0,t1
ble t1,t5,.L46
sext.w a0,t5
ret
.L59:
lw a7,0(a2)
mv a3,a4
beq a7,a4,.L31
beq a6,a4,.L33
bne a7,a6,.L37
j .L48
.L33:
lw a3,0(a2)
addiw t5,t5,1
mv a7,a4
li t3,1
.L34:
beq a7,a3,.L22
.L63:
addi a5,a5,4
addiw t4,t4,1
beq a1,a5,.L24
.L50:
addi a0,a0,4
addi a2,a2,4
bne t3,zero,.L3
lw a3,0(a2)
mv a7,a4
li t3,0
beq a3,a4,.L34
lw a7,0(a0)
bne a7,a4,.L43
.L10:
mv a7,a4
li t3,0
bne a7,a3,.L63
.L22:
lw a3,0(a0)
addi a5,a5,4
beq a3,a7,.L25
addiw t6,t6,1
bne a1,a5,.L50
.L24:
bne t3,zero,.L35
sext.w a0,t4
bgt t4,t6,.L64
.L46:
ret
.L60:
bne a6,a4,.L10
.L9:
mv a3,t3
addiw t1,t1,1
mv a7,a4
li t3,1
j .L34
.L25:
bne a1,a5,.L50
j .L24
.L61:
mv t3,a6
beq a6,a3,.L9
j .L10
.L64:
sext.w a0,t6
ret
.L41:
li a0,0
ret
.L31:
bne a6,a4,.L33
mv a7,a6
li t3,1
j .L34
|
13,975
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
riscv64
|
-O3
|
RISC-V 64 gcc 15.2.0
|
minDominoRotations:
ble a1,zero,.L41
lw a6,0(a0)
lw a4,0(a2)
slli a1,a1,2
li a5,0
li t6,0
li t1,0
li t5,0
li t4,0
.L3:
lw a7,0(a0)
beq a7,a6,.L59
lw a3,0(a2)
mv t3,a4
beq a3,a4,.L60
beq a7,a4,.L61
bne a6,a3,.L43
.L15:
addi a5,a5,4
addiw t1,t1,1
beq a1,a5,.L35
.L55:
lw a3,4(a0)
addi a0,a0,4
addi a2,a2,4
mv a4,a6
beq a3,a6,.L62
lw a3,0(a2)
beq a4,a3,.L15
.L43:
li a0,-1
ret
.L62:
lw a3,0(a2)
beq a3,a4,.L48
.L37:
addiw t5,t5,1
.L48:
addi a5,a5,4
bne a5,a1,.L55
.L35:
sext.w a0,t1
ble t1,t5,.L46
sext.w a0,t5
ret
.L59:
lw a7,0(a2)
mv a3,a4
beq a7,a4,.L31
beq a6,a4,.L33
bne a7,a6,.L37
j .L48
.L33:
lw a3,0(a2)
addiw t5,t5,1
mv a7,a4
li t3,1
.L34:
beq a7,a3,.L22
.L63:
addi a5,a5,4
addiw t4,t4,1
beq a1,a5,.L24
.L50:
addi a0,a0,4
addi a2,a2,4
bne t3,zero,.L3
lw a3,0(a2)
mv a7,a4
li t3,0
beq a3,a4,.L34
lw a7,0(a0)
bne a7,a4,.L43
.L10:
mv a7,a4
li t3,0
bne a7,a3,.L63
.L22:
lw a3,0(a0)
addi a5,a5,4
beq a3,a7,.L25
addiw t6,t6,1
bne a1,a5,.L50
.L24:
bne t3,zero,.L35
sext.w a0,t4
bgt t4,t6,.L64
.L46:
ret
.L60:
bne a6,a4,.L10
.L9:
mv a3,t3
addiw t1,t1,1
mv a7,a4
li t3,1
j .L34
.L25:
bne a1,a5,.L50
j .L24
.L61:
mv t3,a6
beq a6,a3,.L9
j .L10
.L64:
sext.w a0,t6
ret
.L41:
li a0,0
ret
.L31:
bne a6,a4,.L33
mv a7,a6
li t3,1
j .L34
|
13,976
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O0
|
x86-64 clang 21.1.0
|
minDominoRotations:
push rbp
mov rbp, rsp
mov qword ptr [rbp - 16], rdi
mov dword ptr [rbp - 20], esi
mov qword ptr [rbp - 32], rdx
mov dword ptr [rbp - 36], ecx
mov byte ptr [rbp - 38], 1
mov byte ptr [rbp - 37], 1
mov dword ptr [rbp - 60], 0
mov dword ptr [rbp - 56], 0
mov dword ptr [rbp - 52], 0
mov dword ptr [rbp - 48], 0
mov dword ptr [rbp - 44], 0
.LBB0_1:
mov eax, dword ptr [rbp - 44]
cmp eax, dword ptr [rbp - 20]
jge .LBB0_29
test byte ptr [rbp - 37], 1
je .LBB0_6
mov rax, qword ptr [rbp - 16]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 16]
cmp eax, dword ptr [rcx]
je .LBB0_6
mov rax, qword ptr [rbp - 32]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 16]
cmp eax, dword ptr [rcx]
je .LBB0_6
mov byte ptr [rbp - 37], 0
.LBB0_6:
test byte ptr [rbp - 38], 1
je .LBB0_10
mov rax, qword ptr [rbp - 32]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 32]
cmp eax, dword ptr [rcx]
je .LBB0_10
mov rax, qword ptr [rbp - 16]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 32]
cmp eax, dword ptr [rcx]
je .LBB0_10
mov byte ptr [rbp - 38], 0
.LBB0_10:
test byte ptr [rbp - 37], 1
jne .LBB0_13
test byte ptr [rbp - 38], 1
jne .LBB0_13
mov dword ptr [rbp - 4], -1
jmp .LBB0_40
.LBB0_13:
test byte ptr [rbp - 37], 1
je .LBB0_20
mov rax, qword ptr [rbp - 16]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 16]
cmp eax, dword ptr [rcx]
je .LBB0_16
mov eax, dword ptr [rbp - 48]
add eax, 1
mov dword ptr [rbp - 48], eax
jmp .LBB0_19
.LBB0_16:
mov rax, qword ptr [rbp - 32]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 16]
cmp eax, dword ptr [rcx]
je .LBB0_18
mov eax, dword ptr [rbp - 52]
add eax, 1
mov dword ptr [rbp - 52], eax
.LBB0_18:
jmp .LBB0_19
.LBB0_19:
jmp .LBB0_20
.LBB0_20:
test byte ptr [rbp - 38], 1
je .LBB0_27
mov rax, qword ptr [rbp - 32]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 32]
cmp eax, dword ptr [rcx]
je .LBB0_23
mov eax, dword ptr [rbp - 56]
add eax, 1
mov dword ptr [rbp - 56], eax
jmp .LBB0_26
.LBB0_23:
mov rax, qword ptr [rbp - 16]
movsxd rcx, dword ptr [rbp - 44]
mov eax, dword ptr [rax + 4*rcx]
mov rcx, qword ptr [rbp - 32]
cmp eax, dword ptr [rcx]
je .LBB0_25
mov eax, dword ptr [rbp - 60]
add eax, 1
mov dword ptr [rbp - 60], eax
.LBB0_25:
jmp .LBB0_26
.LBB0_26:
jmp .LBB0_27
.LBB0_27:
jmp .LBB0_28
.LBB0_28:
mov eax, dword ptr [rbp - 44]
add eax, 1
mov dword ptr [rbp - 44], eax
jmp .LBB0_1
.LBB0_29:
test byte ptr [rbp - 37], 1
je .LBB0_34
mov eax, dword ptr [rbp - 48]
cmp eax, dword ptr [rbp - 52]
jge .LBB0_32
mov eax, dword ptr [rbp - 48]
mov dword ptr [rbp - 64], eax
jmp .LBB0_33
.LBB0_32:
mov eax, dword ptr [rbp - 52]
mov dword ptr [rbp - 64], eax
.LBB0_33:
mov eax, dword ptr [rbp - 64]
mov dword ptr [rbp - 4], eax
jmp .LBB0_40
.LBB0_34:
test byte ptr [rbp - 38], 1
je .LBB0_39
mov eax, dword ptr [rbp - 60]
cmp eax, dword ptr [rbp - 56]
jge .LBB0_37
mov eax, dword ptr [rbp - 60]
mov dword ptr [rbp - 68], eax
jmp .LBB0_38
.LBB0_37:
mov eax, dword ptr [rbp - 56]
mov dword ptr [rbp - 68], eax
.LBB0_38:
mov eax, dword ptr [rbp - 68]
mov dword ptr [rbp - 4], eax
jmp .LBB0_40
.LBB0_39:
mov dword ptr [rbp - 4], -1
.LBB0_40:
mov eax, dword ptr [rbp - 4]
pop rbp
ret
|
13,977
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O1
|
x86-64 clang 21.1.0
|
minDominoRotations:
push rbp
push r15
push r14
push rbx
test esi, esi
jle .LBB0_1
mov r11d, esi
mov sil, 1
xor ebx, ebx
xor r14d, r14d
xor r9d, r9d
xor eax, eax
xor ecx, ecx
xor r8d, r8d
mov r10b, 1
jmp .LBB0_3
.LBB0_18:
xor r15d, r15d
cmp dword ptr [rdi + 4*r14], ebp
setne r15b
add r9d, r15d
.LBB0_19:
inc r14
cmp r11, r14
je .LBB0_20
.LBB0_3:
test r10b, 1
je .LBB0_6
mov ebp, dword ptr [rdi]
cmp dword ptr [rdi + 4*r14], ebp
je .LBB0_6
cmp dword ptr [rdx + 4*r14], ebp
movzx r10d, r10b
cmovne r10d, ebx
.LBB0_6:
test sil, 1
je .LBB0_9
mov ebp, dword ptr [rdx]
cmp dword ptr [rdx + 4*r14], ebp
je .LBB0_9
cmp dword ptr [rdi + 4*r14], ebp
movzx esi, sil
cmovne esi, ebx
.LBB0_9:
test r10b, 1
jne .LBB0_11
test sil, 1
je .LBB0_24
.LBB0_11:
test r10b, 1
je .LBB0_15
mov ebp, dword ptr [rdi]
cmp dword ptr [rdi + 4*r14], ebp
jne .LBB0_13
xor r15d, r15d
cmp dword ptr [rdx + 4*r14], ebp
setne r15b
add ecx, r15d
.LBB0_15:
test sil, 1
je .LBB0_19
.LBB0_16:
mov ebp, dword ptr [rdx]
cmp dword ptr [rdx + 4*r14], ebp
je .LBB0_18
inc eax
jmp .LBB0_19
.LBB0_13:
inc r8d
test sil, 1
je .LBB0_19
jmp .LBB0_16
.LBB0_1:
xor r8d, r8d
mov r10b, 1
mov sil, 1
xor ecx, ecx
xor eax, eax
xor r9d, r9d
.LBB0_20:
test r10b, 1
je .LBB0_22
cmp r8d, ecx
cmovl ecx, r8d
mov eax, ecx
jmp .LBB0_25
.LBB0_22:
test sil, 1
je .LBB0_24
cmp r9d, eax
cmovl eax, r9d
jmp .LBB0_25
.LBB0_24:
mov eax, -1
.LBB0_25:
pop rbx
pop r14
pop r15
pop rbp
ret
|
13,978
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O2
|
x86-64 clang 21.1.0
|
minDominoRotations:
push rbp
push r14
push rbx
test esi, esi
jle .LBB0_1
mov r9d, esi
mov r11b, 1
xor r10d, r10d
xor esi, esi
xor ecx, ecx
xor eax, eax
xor r8d, r8d
mov bl, 1
jmp .LBB0_3
.LBB0_27:
xor r14d, r14d
cmp dword ptr [rdi + 4*r10], ebp
setne r14b
add esi, r14d
.LBB0_28:
inc r10
cmp r9, r10
je .LBB0_29
.LBB0_3:
test bl, 1
je .LBB0_4
mov ebp, dword ptr [rdi]
mov bl, 1
cmp dword ptr [rdi + 4*r10], ebp
je .LBB0_7
cmp dword ptr [rdx + 4*r10], ebp
sete bl
.LBB0_7:
test r11b, 1
je .LBB0_8
.LBB0_9:
mov r11d, dword ptr [rdx]
cmp dword ptr [rdx + 4*r10], r11d
jne .LBB0_13
mov r11b, 1
test bl, bl
je .LBB0_25
mov ebp, dword ptr [rdi + 4*r10]
cmp ebp, dword ptr [rdi]
jne .LBB0_24
xor r14d, r14d
cmp dword ptr [rdx + 4*r10], ebp
setne r14b
add eax, r14d
jmp .LBB0_25
.LBB0_4:
xor ebx, ebx
test r11b, 1
jne .LBB0_9
.LBB0_8:
xor r11d, r11d
test bl, bl
je .LBB0_15
jmp .LBB0_16
.LBB0_13:
cmp dword ptr [rdi + 4*r10], r11d
sete r11b
test bl, bl
jne .LBB0_16
.LBB0_15:
test r11b, r11b
je .LBB0_33
.LBB0_16:
test bl, bl
je .LBB0_21
mov ebp, dword ptr [rdi + 4*r10]
cmp ebp, dword ptr [rdi]
jne .LBB0_18
xor r14d, r14d
cmp dword ptr [rdx + 4*r10], ebp
setne r14b
add eax, r14d
jmp .LBB0_19
.LBB0_21:
test r11b, r11b
je .LBB0_23
mov r11b, 1
jmp .LBB0_25
.LBB0_18:
inc r8d
.LBB0_19:
test r11b, r11b
je .LBB0_28
jmp .LBB0_25
.LBB0_23:
xor r11d, r11d
jmp .LBB0_28
.LBB0_24:
inc r8d
.LBB0_25:
mov ebp, dword ptr [rdx + 4*r10]
cmp ebp, dword ptr [rdx]
je .LBB0_27
inc ecx
jmp .LBB0_28
.LBB0_1:
xor eax, eax
xor r8d, r8d
jmp .LBB0_30
.LBB0_29:
test bl, bl
je .LBB0_31
.LBB0_30:
cmp r8d, eax
cmovl eax, r8d
jmp .LBB0_34
.LBB0_31:
test r11b, r11b
je .LBB0_33
cmp esi, ecx
cmovl ecx, esi
mov eax, ecx
jmp .LBB0_34
.LBB0_33:
mov eax, -1
.LBB0_34:
pop rbx
pop r14
pop rbp
ret
|
13,979
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O3
|
x86-64 clang 21.1.0
|
minDominoRotations:
push rbp
push r14
push rbx
test esi, esi
jle .LBB0_1
mov r9d, esi
mov r11b, 1
xor r10d, r10d
xor esi, esi
xor ecx, ecx
xor eax, eax
xor r8d, r8d
mov bl, 1
jmp .LBB0_3
.LBB0_27:
xor r14d, r14d
cmp dword ptr [rdi + 4*r10], ebp
setne r14b
add esi, r14d
.LBB0_28:
inc r10
cmp r9, r10
je .LBB0_29
.LBB0_3:
test bl, 1
je .LBB0_4
mov ebp, dword ptr [rdi]
mov bl, 1
cmp dword ptr [rdi + 4*r10], ebp
je .LBB0_7
cmp dword ptr [rdx + 4*r10], ebp
sete bl
.LBB0_7:
test r11b, 1
je .LBB0_8
.LBB0_9:
mov r11d, dword ptr [rdx]
cmp dword ptr [rdx + 4*r10], r11d
jne .LBB0_13
mov r11b, 1
test bl, bl
je .LBB0_25
mov ebp, dword ptr [rdi + 4*r10]
cmp ebp, dword ptr [rdi]
jne .LBB0_24
xor r14d, r14d
cmp dword ptr [rdx + 4*r10], ebp
setne r14b
add eax, r14d
mov ebp, dword ptr [rdx + 4*r10]
cmp ebp, dword ptr [rdx]
je .LBB0_27
jmp .LBB0_26
.LBB0_4:
xor ebx, ebx
test r11b, 1
jne .LBB0_9
.LBB0_8:
xor r11d, r11d
test bl, bl
je .LBB0_15
jmp .LBB0_16
.LBB0_13:
cmp dword ptr [rdi + 4*r10], r11d
sete r11b
test bl, bl
jne .LBB0_16
.LBB0_15:
test r11b, r11b
je .LBB0_33
.LBB0_16:
test bl, bl
je .LBB0_21
mov ebp, dword ptr [rdi + 4*r10]
cmp ebp, dword ptr [rdi]
jne .LBB0_18
xor r14d, r14d
cmp dword ptr [rdx + 4*r10], ebp
setne r14b
add eax, r14d
test r11b, r11b
je .LBB0_28
jmp .LBB0_25
.LBB0_21:
test r11b, r11b
je .LBB0_23
mov r11b, 1
mov ebp, dword ptr [rdx + 4*r10]
cmp ebp, dword ptr [rdx]
je .LBB0_27
jmp .LBB0_26
.LBB0_18:
inc r8d
test r11b, r11b
je .LBB0_28
.LBB0_25:
mov ebp, dword ptr [rdx + 4*r10]
cmp ebp, dword ptr [rdx]
je .LBB0_27
.LBB0_26:
inc ecx
jmp .LBB0_28
.LBB0_23:
xor r11d, r11d
jmp .LBB0_28
.LBB0_24:
inc r8d
mov ebp, dword ptr [rdx + 4*r10]
cmp ebp, dword ptr [rdx]
je .LBB0_27
jmp .LBB0_26
.LBB0_1:
xor eax, eax
xor r8d, r8d
jmp .LBB0_30
.LBB0_29:
test bl, bl
je .LBB0_31
.LBB0_30:
cmp r8d, eax
cmovl eax, r8d
pop rbx
pop r14
pop rbp
ret
.LBB0_31:
test r11b, r11b
je .LBB0_33
cmp esi, ecx
cmovl ecx, esi
mov eax, ecx
pop rbx
pop r14
pop rbp
ret
.LBB0_33:
mov eax, -1
pop rbx
pop r14
pop rbp
ret
|
13,980
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O0
|
x86-64 gcc 15.2
|
minDominoRotations:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-40], rdi
mov DWORD PTR [rbp-44], esi
mov QWORD PTR [rbp-56], rdx
mov DWORD PTR [rbp-48], ecx
mov BYTE PTR [rbp-2], 1
movzx eax, BYTE PTR [rbp-2]
mov BYTE PTR [rbp-1], al
mov DWORD PTR [rbp-24], 0
mov eax, DWORD PTR [rbp-24]
mov DWORD PTR [rbp-20], eax
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-16], eax
mov eax, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-12], eax
mov DWORD PTR [rbp-8], 0
jmp .L2
.L11:
cmp BYTE PTR [rbp-1], 0
je .L3
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-40]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-40]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L3
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-56]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-40]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L3
mov BYTE PTR [rbp-1], 0
.L3:
cmp BYTE PTR [rbp-2], 0
je .L4
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-56]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-56]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L4
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-40]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-56]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L4
mov BYTE PTR [rbp-2], 0
.L4:
movzx eax, BYTE PTR [rbp-1]
xor eax, 1
test al, al
je .L5
movzx eax, BYTE PTR [rbp-2]
xor eax, 1
test al, al
je .L5
mov eax, -1
jmp .L6
.L5:
cmp BYTE PTR [rbp-1], 0
je .L7
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-40]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-40]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L8
add DWORD PTR [rbp-12], 1
jmp .L7
.L8:
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-56]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-40]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L7
add DWORD PTR [rbp-16], 1
.L7:
cmp BYTE PTR [rbp-2], 0
je .L9
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-56]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-56]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L10
add DWORD PTR [rbp-20], 1
jmp .L9
.L10:
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-40]
add rax, rdx
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-56]
mov eax, DWORD PTR [rax]
cmp edx, eax
je .L9
add DWORD PTR [rbp-24], 1
.L9:
add DWORD PTR [rbp-8], 1
.L2:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-44]
jl .L11
cmp BYTE PTR [rbp-1], 0
je .L12
mov edx, DWORD PTR [rbp-16]
mov eax, DWORD PTR [rbp-12]
cmp edx, eax
cmovle eax, edx
jmp .L6
.L12:
cmp BYTE PTR [rbp-2], 0
je .L13
mov edx, DWORD PTR [rbp-20]
mov eax, DWORD PTR [rbp-24]
cmp edx, eax
cmovle eax, edx
jmp .L6
.L13:
mov eax, -1
.L6:
pop rbp
ret
|
13,981
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O1
|
x86-64 gcc 15.2
|
minDominoRotations:
push r12
push rbp
push rbx
test esi, esi
jle .L19
mov r8, rdx
mov rax, rdi
movsx rsi, esi
lea r10, [rdi+rsi*4]
mov ebx, 0
mov r9d, 0
mov ebp, 0
mov r11d, 0
mov esi, 1
mov ecx, 1
jmp .L14
.L23:
mov ecx, esi
jmp .L16
.L32:
mov esi, ecx
.L17:
mov ecx, DWORD PTR [rdi]
cmp DWORD PTR [rax], ecx
je .L10
add r11d, 1
.L11:
test sil, sil
jne .L29
mov ecx, 1
.L12:
add rax, 4
add rdx, 4
cmp r10, rax
je .L30
.L14:
test cl, cl
je .L3
mov ecx, DWORD PTR [rdi]
cmp DWORD PTR [rax], ecx
je .L4
cmp DWORD PTR [rdx], ecx
sete cl
test sil, sil
jne .L16
.L5:
test sil, sil
jne .L25
test cl, cl
je .L20
.L25:
test cl, cl
jne .L17
.L9:
mov r12d, DWORD PTR [r8]
cmp DWORD PTR [rdx], r12d
je .L13
add r9d, 1
jmp .L12
.L29:
mov ecx, esi
jmp .L9
.L30:
test cl, cl
jne .L2
cmp r9d, ebx
mov eax, ebx
cmovle eax, r9d
test sil, sil
mov edx, -1
cmove eax, edx
jmp .L1
.L19:
mov ebp, 0
mov r11d, 0
.L2:
cmp r11d, ebp
mov eax, ebp
cmovle eax, r11d
jmp .L1
.L20:
mov eax, -1
jmp .L1
.L3:
test sil, sil
je .L31
.L16:
mov esi, DWORD PTR [r8]
cmp DWORD PTR [rdx], esi
je .L6
cmp DWORD PTR [rax], esi
sete sil
jmp .L5
.L31:
mov eax, -1
.L1:
pop rbx
pop rbp
pop r12
ret
.L4:
test sil, sil
jne .L23
mov ecx, DWORD PTR [rdi]
.L10:
cmp ecx, DWORD PTR [rdx]
setne cl
movzx ecx, cl
add ebp, ecx
jmp .L11
.L6:
test cl, cl
jne .L32
mov r12d, DWORD PTR [r8]
mov esi, 1
.L13:
cmp r12d, DWORD PTR [rax]
setne r12b
movzx r12d, r12b
add ebx, r12d
jmp .L12
|
13,982
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O2
|
x86-64 gcc 15.2
|
minDominoRotations:
test esi, esi
jle .L39
push r13
mov rcx, rdx
movsx rsi, esi
xor edx, edx
push r12
xor r13d, r13d
xor r9d, r9d
xor r10d, r10d
push rbp
mov rbp, rdi
lea rdi, [0+rsi*4]
xor eax, eax
push rbx
mov r12d, DWORD PTR [rbp+0]
mov esi, DWORD PTR [rcx]
.L3:
mov r11d, DWORD PTR [rbp+0+rdx]
cmp r11d, r12d
je .L55
mov r8d, DWORD PTR [rcx]
mov ebx, esi
cmp r8d, esi
je .L56
cmp r11d, esi
je .L57
cmp r12d, r8d
jne .L41
add rdx, 4
add r9d, 1
cmp rdi, rdx
je .L33
.L53:
add rcx, 4
mov eax, r12d
cmp DWORD PTR [rbp+0+rdx], r12d
je .L17
.L21:
mov esi, DWORD PTR [rcx]
cmp eax, esi
jne .L41
add rdx, 4
add r9d, 1
cmp rdx, rdi
jne .L53
.L33:
cmp r10d, r9d
mov eax, r9d
pop rbx
pop rbp
cmovle eax, r10d
pop r12
pop r13
ret
.L41:
pop rbx
mov eax, -1
pop rbp
pop r12
pop r13
ret
.L58:
add rcx, 4
mov eax, r12d
cmp r12d, DWORD PTR [rbp+0+rdx]
jne .L21
.L17:
cmp DWORD PTR [rcx], eax
setne al
movzx eax, al
add r10d, eax
.L20:
add rdx, 4
cmp rdi, rdx
jne .L58
jmp .L33
.L55:
mov r8d, esi
cmp DWORD PTR [rcx], esi
je .L30
cmp r12d, esi
je .L32
cmp r12d, DWORD PTR [rcx]
je .L59
add r10d, 1
jmp .L20
.L32:
mov r8d, DWORD PTR [rcx]
add r10d, 1
mov r11d, esi
mov ebx, 1
.L12:
cmp r11d, r8d
je .L22
.L60:
add rdx, 4
add eax, 1
cmp rdi, rdx
je .L24
.L50:
add rcx, 4
test bl, bl
jne .L3
mov r8d, DWORD PTR [rcx]
mov r11d, esi
xor ebx, ebx
cmp r8d, esi
je .L22
cmp DWORD PTR [rbp+0+rdx], esi
jne .L41
.L10:
mov r11d, esi
xor ebx, ebx
cmp r11d, r8d
jne .L60
.L22:
cmp DWORD PTR [rbp+0+rdx], r11d
je .L25
add rdx, 4
add r13d, 1
cmp rdi, rdx
jne .L50
.L24:
test bl, bl
jne .L33
cmp eax, r13d
pop rbx
pop rbp
cmovg eax, r13d
pop r12
pop r13
ret
.L56:
cmp r12d, esi
jne .L10
.L9:
mov r8d, ebx
add r9d, 1
mov r11d, esi
mov ebx, 1
jmp .L12
.L25:
add rdx, 4
cmp rdi, rdx
jne .L50
jmp .L24
.L57:
cmp r12d, r8d
jne .L10
mov ebx, r12d
jmp .L9
.L39:
xor eax, eax
ret
.L30:
cmp r12d, esi
jne .L32
mov r11d, r12d
mov ebx, 1
jmp .L12
.L59:
add rdx, 4
cmp rdx, rdi
jne .L53
jmp .L33
|
13,983
| 1,007
|
Minimum Domino Rotations For Equal Row
|
Medium
|
/*
1007. Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the i-th domino, so that A[i] and B[i] swap values.
Return the minimum number of rotations so that all the values in A are the same, or all the values in B are the same.
If it cannot be done, return -1.
Example 1:
Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]
Output: 2
Explanation:
The first figure represents the dominoes as given by A and B: before we do any rotations.
If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.
Example 2:
Input: A = [3,5,1,2,3], B = [3,6,3,3,4]
Output: -1
Explanation:
In this case, it is not possible to rotate the dominoes to make one row of values equal.
Note:
1 <= A[i], B[i] <= 6
2 <= A.length == B.length <= 20000
*/
int minDominoRotations(int* A, int ASize, int* B, int BSize){
bool a_ok, b_ok;
int i, a_up, a_down, b_down, b_up;
a_ok = b_ok = true;
a_up = a_down = b_down = b_up = 0;
for (i = 0; i < ASize; i ++) {
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
if (!a_ok && !b_ok) return -1;
if (a_ok) {
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
else if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
}
if (b_ok) {
if (B[i] != B[0]) b_down ++;
else if (A[i] != B[0]) b_up ++;
}
}
if (a_ok) return a_up < a_down ? a_up : a_down;
if (b_ok) return b_up < b_down ? b_up : b_down;
return -1;
}
/*
Difficulty:Medium
*/
|
x86-64
|
-O3
|
x86-64 gcc 15.2
|
minDominoRotations:
test esi, esi
jle .L39
push r13
mov rcx, rdx
movsx rsi, esi
xor edx, edx
push r12
xor r13d, r13d
xor r9d, r9d
xor r10d, r10d
push rbp
mov rbp, rdi
lea rdi, [0+rsi*4]
xor eax, eax
push rbx
mov r12d, DWORD PTR [rbp+0]
mov esi, DWORD PTR [rcx]
.L3:
mov r11d, DWORD PTR [rbp+0+rdx]
cmp r11d, r12d
je .L55
mov r8d, DWORD PTR [rcx]
mov ebx, esi
cmp r8d, esi
je .L56
cmp r11d, esi
je .L57
cmp r12d, r8d
jne .L41
add rdx, 4
add r9d, 1
cmp rdi, rdx
je .L33
.L53:
add rcx, 4
mov eax, r12d
cmp DWORD PTR [rbp+0+rdx], r12d
je .L17
.L21:
mov esi, DWORD PTR [rcx]
cmp eax, esi
jne .L41
add rdx, 4
add r9d, 1
cmp rdx, rdi
jne .L53
.L33:
cmp r10d, r9d
mov eax, r9d
pop rbx
pop rbp
cmovle eax, r10d
pop r12
pop r13
ret
.L41:
pop rbx
mov eax, -1
pop rbp
pop r12
pop r13
ret
.L58:
add rcx, 4
mov eax, r12d
cmp r12d, DWORD PTR [rbp+0+rdx]
jne .L21
.L17:
cmp DWORD PTR [rcx], eax
setne al
movzx eax, al
add r10d, eax
.L20:
add rdx, 4
cmp rdi, rdx
jne .L58
jmp .L33
.L55:
mov r8d, esi
cmp DWORD PTR [rcx], esi
je .L30
cmp r12d, esi
je .L32
cmp r12d, DWORD PTR [rcx]
je .L59
add r10d, 1
jmp .L20
.L32:
mov r8d, DWORD PTR [rcx]
add r10d, 1
mov r11d, esi
mov ebx, 1
.L12:
cmp r11d, r8d
je .L22
.L60:
add rdx, 4
add eax, 1
cmp rdi, rdx
je .L24
.L50:
add rcx, 4
test bl, bl
jne .L3
mov r8d, DWORD PTR [rcx]
mov r11d, esi
xor ebx, ebx
cmp r8d, esi
je .L22
cmp DWORD PTR [rbp+0+rdx], esi
jne .L41
.L10:
mov r11d, esi
xor ebx, ebx
cmp r11d, r8d
jne .L60
.L22:
cmp DWORD PTR [rbp+0+rdx], r11d
je .L25
add rdx, 4
add r13d, 1
cmp rdi, rdx
jne .L50
.L24:
test bl, bl
jne .L33
cmp eax, r13d
pop rbx
pop rbp
cmovg eax, r13d
pop r12
pop r13
ret
.L56:
cmp r12d, esi
jne .L10
.L9:
mov r8d, ebx
add r9d, 1
mov r11d, esi
mov ebx, 1
jmp .L12
.L25:
add rdx, 4
cmp rdi, rdx
jne .L50
jmp .L24
.L57:
cmp r12d, r8d
jne .L10
mov ebx, r12d
jmp .L9
.L39:
xor eax, eax
ret
.L30:
cmp r12d, esi
jne .L32
mov r11d, r12d
mov ebx, 1
jmp .L12
.L59:
add rdx, 4
cmp rdx, rdi
jne .L53
jmp .L33
|
13,984
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O0
|
ARM64 gcc 15.2.0
|
bstFromPreorder:
stp x29, x30, [sp, -48]!
mov x29, sp
str x0, [sp, 24]
str w1, [sp, 20]
ldr w0, [sp, 20]
cmp w0, 0
bne .L2
mov x0, 0
b .L3
.L2:
mov x0, 24
bl malloc
str x0, [sp, 32]
ldr x0, [sp, 24]
ldr w1, [x0]
ldr x0, [sp, 32]
str w1, [x0]
mov w0, 1
str w0, [sp, 44]
b .L4
.L6:
ldr w0, [sp, 44]
add w0, w0, 1
str w0, [sp, 44]
.L4:
ldr w1, [sp, 44]
ldr w0, [sp, 20]
cmp w1, w0
bge .L5
ldrsw x0, [sp, 44]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x0, x1, x0
ldr w1, [x0]
ldr x0, [sp, 32]
ldr w0, [x0]
cmp w1, w0
blt .L6
.L5:
ldr x0, [sp, 24]
add x2, x0, 4
ldr w0, [sp, 44]
sub w0, w0, #1
mov w1, w0
mov x0, x2
bl bstFromPreorder
mov x1, x0
ldr x0, [sp, 32]
str x1, [x0, 8]
ldrsw x0, [sp, 44]
lsl x0, x0, 2
ldr x1, [sp, 24]
add x2, x1, x0
ldr w1, [sp, 20]
ldr w0, [sp, 44]
sub w0, w1, w0
mov w1, w0
mov x0, x2
bl bstFromPreorder
mov x1, x0
ldr x0, [sp, 32]
str x1, [x0, 16]
ldr x0, [sp, 32]
.L3:
ldp x29, x30, [sp], 48
ret
|
13,985
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O1
|
ARM64 gcc 15.2.0
|
bstFromPreorder:
stp x29, x30, [sp, -48]!
mov x29, sp
stp x21, x22, [sp, 32]
mov x22, 0
cbz w1, .L1
stp x19, x20, [sp, 16]
mov x20, x0
mov w21, w1
mov x0, 24
bl malloc
mov x22, x0
ldr w1, [x20]
str w1, [x0]
mov x2, 1
mov w19, 1
cmp w21, 1
ble .L4
.L3:
ldr w3, [x20, x2, lsl 2]
cmp w1, w3
ble .L11
add x3, x2, 1
cmp w21, w3
ble .L12
mov x2, x3
b .L3
.L12:
add w19, w2, 1
b .L4
.L11:
mov w19, w2
.L4:
sub w1, w19, #1
add x0, x20, 4
bl bstFromPreorder
str x0, [x22, 8]
sub w1, w21, w19
add x0, x20, w19, sxtw 2
bl bstFromPreorder
str x0, [x22, 16]
ldp x19, x20, [sp, 16]
.L1:
mov x0, x22
ldp x21, x22, [sp, 32]
ldp x29, x30, [sp], 48
ret
|
13,986
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O2
|
ARM64 gcc 15.2.0
|
bstFromPreorder:
stp x29, x30, [sp, -48]!
mov x29, sp
stp x19, x20, [sp, 16]
mov x20, 0
cbz w1, .L1
mov x5, x0
mov w19, w1
mov x0, 24
str x5, [sp, 32]
bl malloc
mov x20, x0
ldr x5, [sp, 32]
mov w4, 1
mov x0, x5
ldr w1, [x0], 4
str w1, [x20]
mov x2, x0
cmp w19, w4
bgt .L5
b .L12
.L6:
add w3, w4, 1
add x2, x2, 4
cmp w19, w3
beq .L13
mov w4, w3
.L5:
ldr w3, [x2]
cmp w1, w3
bgt .L6
sub w1, w4, #1
.L4:
str x2, [sp, 32]
str w4, [sp, 44]
bl bstFromPreorder
ldr w4, [sp, 44]
str x0, [x20, 8]
ldr x0, [sp, 32]
sub w1, w19, w4
bl bstFromPreorder
str x0, [x20, 16]
.L1:
mov x0, x20
ldp x19, x20, [sp, 16]
ldp x29, x30, [sp], 48
ret
.L13:
mov w1, w4
add x2, x5, w19, uxtw 2
mov w4, w19
b .L4
.L12:
mov w1, 0
b .L4
|
13,987
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O3
|
ARM64 gcc 15.2.0
|
bstFromPreorder:
stp x29, x30, [sp, -176]!
mov x29, sp
stp x21, x22, [sp, 32]
mov x21, 0
cbz w1, .L1
stp x25, x26, [sp, 64]
mov x26, x0
mov x25, x26
mov x0, 24
stp x19, x20, [sp, 16]
mov w20, w1
stp x23, x24, [sp, 48]
bl malloc
ldr w1, [x25], 4
str w1, [x0]
mov x21, x0
cmp w20, 1
ble .L3
neg x2, x25, lsr 2
mov w3, 5
and w19, w2, 3
stp x27, x28, [sp, 80]
add w0, w19, 4
cmp w0, w3
sub w27, w20, #2
csel w0, w0, w3, cs
cmp w27, w0
bcc .L634
cbz w19, .L345
ldr w0, [x26, 4]
cmp w1, w0
ble .L8
tbz x2, 1, .L346
ldr w0, [x26, 8]
cmp w1, w0
ble .L10
cmp w19, 3
bne .L347
ldr w0, [x26, 12]
cmp w1, w0
ble .L11
movi v26.2s, 0x4
.L7:
adrp x0, .LC0
sub w27, w20, #1
add w2, w19, 1
sub w19, w27, w19
ldr q31, [x0, #:lo12:.LC0]
ubfiz x2, x2, 2, 3
dup v30.4s, v26.s[0]
lsr w0, w19, 2
add x2, x26, x2
dup v27.4s, w1
movi v28.4s, 0x4
add x0, x2, w0, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L12
.L29:
cmp x2, x0
beq .L635
add v30.4s, v30.4s, v28.4s
.L12:
ldr q31, [x2]
add x2, x2, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x3, d31
cbz x3, .L29
fmov x0, d30
ubfiz x2, x0, 2, 32
ldr w3, [x26, x2]
cmp w1, w3
ble .L636
.L5:
add w22, w0, 1
cmp w20, w22
ble .L350
add x2, x26, x2
ldr w3, [x2, 4]
cmp w1, w3
ble .L350
add w19, w0, 2
cmp w20, w19
ble .L19
ldr w3, [x2, 8]
cmp w1, w3
ble .L20
add w22, w0, 3
cmp w20, w22
ble .L21
ldr w3, [x2, 12]
cmp w1, w3
ble .L26
add w19, w0, 4
cmp w20, w19
ble .L19
ldr w3, [x2, 16]
cmp w1, w3
ble .L20
add w22, w0, 5
mov w24, w22
cmp w20, w22
ble .L21
ldr w3, [x2, 20]
cmp w1, w3
ble .L26
add w28, w0, 6
cmp w20, w28
ble .L27
ldr w2, [x2, 24]
cmp w1, w2
ble .L28
add w22, w0, 7
mov x0, 24
bl malloc
mov x23, x0
ldr w3, [x26, 4]
str w3, [x0]
.L16:
add x27, x26, 8
mov w2, 5
sub w24, w28, #2
neg x1, x27, lsr 2
and w19, w1, 3
add w0, w19, 4
cmp w0, w2
csel w0, w0, w2, cs
cmp w24, w0
bcc .L637
cbz w19, .L352
ldr w0, [x26, 8]
cmp w3, w0
ble .L36
tbz x1, 1, .L353
ldr w0, [x26, 12]
cmp w3, w0
ble .L39
cmp w19, 3
bne .L354
ldr w0, [x26, 16]
cmp w0, w3
bge .L40
movi v26.2s, 0x4
.L37:
adrp x0, .LC0
sub w1, w28, w19
dup v30.4s, v26.s[0]
add w19, w19, 2
ldr q31, [x0, #:lo12:.LC0]
sub w1, w1, #1
ubfiz x2, x19, 2, 3
dup v27.4s, w3
lsr w0, w1, 2
add x2, x26, x2
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x0, x2, w0, uxtw 4
b .L41
.L57:
cmp x0, x2
beq .L638
add v30.4s, v30.4s, v28.4s
.L41:
ldr q31, [x2]
add x2, x2, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x4, d31
cbz x4, .L57
fmov x0, d30
ubfiz x1, x0, 2, 32
ldr w2, [x25, x1]
cmp w3, w2
ble .L639
.L35:
add w19, w0, 1
cmp w28, w19
ble .L357
add x1, x25, x1
ldr w2, [x1, 4]
cmp w3, w2
ble .L357
add w2, w0, 2
cmp w28, w2
ble .L47
ldr w4, [x1, 8]
cmp w3, w4
ble .L48
add w19, w0, 3
cmp w28, w19
ble .L49
ldr w4, [x1, 12]
cmp w3, w4
ble .L54
add w2, w0, 4
cmp w28, w2
ble .L47
ldr w4, [x1, 16]
cmp w3, w4
ble .L48
add w19, w0, 5
mov w7, w19
cmp w28, w19
ble .L49
ldr w4, [x1, 20]
cmp w3, w4
ble .L54
add w24, w0, 6
cmp w28, w24
ble .L55
ldr w1, [x1, 24]
cmp w1, w3
bge .L56
add w19, w0, 7
mov x0, 24
bl malloc
str x0, [sp, 104]
ldr w6, [x26, 8]
str w6, [x0]
.L44:
add x3, x26, 12
mov w7, 5
sub w4, w24, #2
neg x2, x3, lsr 2
and w1, w2, 3
add w0, w1, 4
cmp w0, w7
csel w0, w0, w7, cs
cmp w4, w0
bcc .L640
cbz w1, .L359
ldr w0, [x26, 12]
cmp w6, w0
ble .L63
tbz x2, 1, .L360
ldr w0, [x26, 16]
cmp w6, w0
ble .L66
cmp w1, 3
bne .L361
ldr w0, [x26, 20]
cmp w0, w6
bge .L67
movi v26.2s, 0x4
.L64:
adrp x0, .LC0
sub w2, w24, w1
dup v30.4s, v26.s[0]
add w1, w1, 3
ldr q31, [x0, #:lo12:.LC0]
sub w2, w2, #1
ubfiz x1, x1, 2, 3
dup v27.4s, w6
lsr w0, w2, 2
add x1, x26, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x0, x1, w0, uxtw 4
b .L68
.L84:
cmp x0, x1
beq .L641
add v30.4s, v30.4s, v28.4s
.L68:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x4, d31
cbz x4, .L84
fmov x0, d30
ubfiz x1, x0, 2, 32
ldr w2, [x27, x1]
cmp w6, w2
ble .L642
.L62:
add w4, w0, 1
cmp w24, w4
ble .L364
add x1, x27, x1
ldr w2, [x1, 4]
cmp w6, w2
ble .L364
add w2, w0, 2
cmp w24, w2
ble .L74
ldr w7, [x1, 8]
cmp w6, w7
ble .L75
add w4, w0, 3
cmp w24, w4
ble .L76
ldr w7, [x1, 12]
cmp w6, w7
ble .L81
add w2, w0, 4
cmp w24, w2
ble .L74
ldr w7, [x1, 16]
cmp w6, w7
ble .L75
add w4, w0, 5
mov w8, w4
cmp w24, w4
ble .L76
ldr w7, [x1, 20]
cmp w6, w7
ble .L81
add w9, w0, 6
cmp w24, w9
ble .L82
ldr w1, [x1, 24]
cmp w1, w6
bge .L83
add w4, w0, 7
mov x0, 24
str w4, [sp, 112]
str x3, [sp, 120]
str w9, [sp, 128]
bl malloc
ldr x3, [sp, 120]
mov x6, x0
ldr w4, [sp, 112]
ldr w9, [sp, 128]
ldr w11, [x26, 12]
str w11, [x0]
.L71:
add x7, x26, 16
mov w0, 5
sub w8, w9, #2
neg x10, x7, lsr 2
and w2, w10, 3
add w1, w2, 4
cmp w1, w0
csel w0, w1, w0, cs
cmp w8, w0
bcc .L643
cbz w2, .L366
ldr w0, [x26, 16]
cmp w11, w0
ble .L90
tbz x10, 1, .L367
ldr w0, [x26, 20]
cmp w11, w0
ble .L93
cmp w2, 3
bne .L368
ldr w0, [x26, 24]
cmp w11, w0
ble .L94
movi v26.2s, 0x4
.L91:
adrp x0, .LC0
sub w2, w9, w2
dup v30.4s, v26.s[0]
sub w2, w2, #1
ldr q31, [x0, #:lo12:.LC0]
ubfiz x1, x1, 2, 4
lsr w0, w2, 2
add x1, x26, x1
dup v27.4s, w11
add v30.4s, v30.4s, v31.4s
add x0, x1, w0, uxtw 4
movi v28.4s, 0x4
b .L95
.L111:
cmp x0, x1
beq .L644
add v30.4s, v30.4s, v28.4s
.L95:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L111
fmov x0, d30
ubfiz x1, x0, 2, 32
ldr w2, [x3, x1]
cmp w11, w2
ble .L645
.L89:
add w8, w0, 1
cmp w9, w8
ble .L371
add x1, x3, x1
ldr w2, [x1, 4]
cmp w11, w2
ble .L371
add w2, w0, 2
cmp w9, w2
ble .L101
ldr w10, [x1, 8]
cmp w11, w10
ble .L102
add w8, w0, 3
cmp w9, w8
ble .L103
ldr w10, [x1, 12]
cmp w11, w10
ble .L108
add w2, w0, 4
cmp w9, w2
ble .L101
ldr w10, [x1, 16]
cmp w11, w10
ble .L102
add w8, w0, 5
mov w14, w8
cmp w9, w8
ble .L103
ldr w10, [x1, 20]
cmp w11, w10
ble .L108
add w10, w0, 6
cmp w9, w10
ble .L109
ldr w1, [x1, 24]
cmp w11, w1
ble .L110
add w8, w0, 7
add x12, x26, 20
mov x0, 24
str x12, [sp, 112]
str w8, [sp, 120]
stp x3, x7, [sp, 128]
str w4, [sp, 144]
str x6, [sp, 152]
stp w9, w10, [sp, 164]
bl malloc
ldr x12, [sp, 112]
mov x11, x0
ldr x6, [sp, 152]
ldr w8, [sp, 120]
ldr w4, [sp, 144]
ldr w13, [x26, 16]
ldp x3, x7, [sp, 128]
ldp w9, w10, [sp, 164]
str w13, [x0]
.L98:
neg x14, x12, lsr 2
mov w15, 6
and w2, w14, 3
sub w1, w10, #2
add w0, w2, 4
cmp w0, w15
csel w0, w0, w15, cs
cmp w1, w0
bcc .L381
cbz w2, .L382
ldr w0, [x12]
cmp w13, w0
ble .L383
tbz x14, 1, .L384
ldr w0, [x26, 24]
cmp w13, w0
ble .L646
cmp w2, 3
bne .L385
ldr w0, [x26, 28]
movi v26.2s, 0x4
add x14, x26, 28
cmp w13, w0
ble .L118
.L119:
sub w0, w10, w2
add w1, w2, 5
sub w2, w0, #1
adrp x0, .LC0
dup v30.4s, v26.s[0]
ubfiz x1, x1, 2, 4
ldr q31, [x0, #:lo12:.LC0]
lsr w0, w2, 2
add x1, x26, x1
dup v27.4s, w13
movi v28.4s, 0x4
add x0, x1, w0, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L115
.L122:
cmp x0, x1
beq .L647
add v30.4s, v30.4s, v28.4s
.L115:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L122
fmov w15, s30
.L114:
ubfiz x0, x15, 2, 32
add x14, x7, x0
ldr w1, [x7, x0]
cmp w1, w13
bge .L373
add w2, w15, 1
cmp w2, w10
bge .L374
add x1, x0, 4
add x14, x7, x1
ldr w1, [x7, x1]
cmp w1, w13
bge .L118
add w1, w15, 2
cmp w1, w10
bge .L379
add x2, x0, 8
add x14, x7, x2
ldr w2, [x7, x2]
cmp w2, w13
bge .L380
add w2, w15, 3
cmp w2, w10
bge .L117
add x1, x0, 12
add x14, x7, x1
ldr w1, [x7, x1]
cmp w1, w13
bge .L118
add w1, w15, 4
cmp w1, w10
bge .L379
add x2, x0, 16
add x14, x7, x2
ldr w2, [x7, x2]
cmp w2, w13
bge .L380
add w2, w15, 5
cmp w2, w10
bge .L117
add x1, x0, 20
add x14, x7, x1
ldr w1, [x7, x1]
cmp w1, w13
bge .L118
add w1, w15, 6
cmp w1, w10
bge .L379
add x0, x0, 24
add x14, x7, x0
ldr w0, [x7, x0]
cmp w0, w13
bge .L380
add w2, w15, 7
.L117:
add x14, x7, w2, uxtw 2
.L113:
mov x0, x12
stp x11, x3, [sp, 112]
str w2, [sp, 128]
str x14, [sp, 136]
str w4, [sp, 144]
str x6, [sp, 152]
stp w9, w8, [sp, 164]
str w10, [sp, 172]
bl bstFromPreorder
ldr x11, [sp, 112]
ldr w2, [sp, 128]
ldr w10, [sp, 172]
str x0, [x11, 8]
ldr x0, [sp, 136]
sub w1, w10, w2
bl bstFromPreorder
ldr x6, [sp, 152]
ldp x11, x3, [sp, 112]
ldp w9, w8, [sp, 164]
str x11, [x6, 8]
str x0, [x11, 16]
ldr w4, [sp, 144]
add x7, x3, w8, uxtw 2
subs w8, w9, w8
beq .L96
.L342:
mov x0, 24
str x7, [sp, 112]
str w8, [sp, 120]
str w4, [sp, 128]
str x6, [sp, 136]
bl malloc
ldr x7, [sp, 112]
mov x9, x0
ldr w8, [sp, 120]
mov w1, 0
mov x0, x7
ldr w4, [sp, 128]
ldr x6, [sp, 136]
cmp w8, 1
ldr w3, [x0], 4
mov w2, 1
str w3, [x9]
mov x12, x0
ble .L127
neg x11, x0, lsr 2
mov w12, 6
and w2, w11, 3
sub w10, w8, #2
add w1, w2, 4
cmp w1, w12
csel w1, w1, w12, cs
cmp w10, w1
bcc .L396
cbz w2, .L397
ldr w1, [x7, 4]
cmp w3, w1
ble .L398
tbz x11, 1, .L399
ldr w1, [x7, 8]
cmp w3, w1
ble .L648
cmp w2, 3
bne .L400
ldr w1, [x7, 12]
movi v26.2s, 0x4
add x12, x7, 12
cmp w3, w1
ble .L131
.L133:
sub w10, w8, #1
add w1, w2, 1
sub w10, w10, w2
adrp x2, .LC0
dup v30.4s, v26.s[0]
ubfiz x1, x1, 2, 3
ldr q31, [x2, #:lo12:.LC0]
lsr w2, w10, 2
add x1, x7, x1
dup v27.4s, w3
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L128
.L136:
cmp x2, x1
beq .L649
add v30.4s, v30.4s, v28.4s
.L128:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L136
fmov w11, s30
.L132:
ubfiz x10, x11, 2, 32
add x12, x7, x10
ldr w1, [x7, x10]
cmp w3, w1
ble .L388
add w2, w11, 1
cmp w8, w2
ble .L389
add x1, x10, 4
add x12, x7, x1
ldr w1, [x7, x1]
cmp w3, w1
ble .L131
add w1, w11, 2
cmp w8, w1
ble .L394
add x2, x10, 8
add x12, x7, x2
ldr w2, [x7, x2]
cmp w3, w2
ble .L395
add w2, w11, 3
cmp w8, w2
ble .L130
add x1, x10, 12
add x12, x7, x1
ldr w1, [x7, x1]
cmp w3, w1
ble .L131
add w1, w11, 4
cmp w8, w1
ble .L394
add x2, x10, 16
add x12, x7, x2
ldr w2, [x7, x2]
cmp w3, w2
ble .L395
add w2, w11, 5
cmp w8, w2
ble .L130
add x1, x10, 20
add x12, x7, x1
ldr w1, [x7, x1]
cmp w3, w1
ble .L131
add w1, w11, 6
cmp w8, w1
ble .L394
add x10, x10, 24
add x12, x7, x10
ldr w2, [x7, x10]
cmp w3, w2
ble .L395
add w2, w11, 7
.L130:
add x12, x7, w2, uxtw 2
.L127:
str x9, [sp, 112]
str w2, [sp, 120]
str w8, [sp, 128]
str x12, [sp, 136]
str w4, [sp, 144]
str x6, [sp, 152]
bl bstFromPreorder
ldr x9, [sp, 112]
ldr w2, [sp, 120]
ldr w8, [sp, 128]
str x0, [x9, 8]
ldr x0, [sp, 136]
sub w1, w8, w2
bl bstFromPreorder
ldr x9, [sp, 112]
ldr x6, [sp, 152]
ldr w4, [sp, 144]
str x0, [x9, 16]
.L125:
ldr x0, [sp, 104]
str x9, [x6, 16]
subs w24, w24, w4
str x6, [x0, 8]
beq .L69
.L86:
add x3, x27, w4, uxtw 2
.L341:
mov x0, 24
str x3, [sp, 112]
bl malloc
mov x27, x0
ldr x3, [sp, 112]
mov w1, 0
mov w6, 1
mov x0, x3
ldr w7, [x0], 4
str w7, [x27]
mov x4, x0
cmp w24, 1
ble .L140
neg x6, x0, lsr 2
mov w8, 6
and w2, w6, 3
sub w4, w24, #2
add w1, w2, 4
cmp w1, w8
csel w1, w1, w8, cs
cmp w4, w1
bcc .L415
cbz w2, .L416
ldr w1, [x3, 4]
cmp w7, w1
ble .L417
tbz x6, 1, .L418
ldr w1, [x3, 8]
add x4, x3, 8
mov w6, 2
cmp w7, w1
ble .L144
cmp w2, 3
bne .L419
ldr w1, [x3, 12]
movi v26.2s, 0x4
add x4, x3, 12
mov w6, w2
cmp w7, w1
ble .L144
.L146:
sub w4, w24, #1
add w1, w2, 1
sub w4, w4, w2
adrp x2, .LC0
dup v30.4s, v26.s[0]
ubfiz x1, x1, 2, 3
ldr q31, [x2, #:lo12:.LC0]
lsr w2, w4, 2
add x1, x3, x1
dup v27.4s, w7
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L141
.L149:
cmp x1, x2
beq .L650
add v30.4s, v30.4s, v28.4s
.L141:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L149
fmov w6, s30
.L145:
ubfiz x2, x6, 2, 32
add x4, x3, x2
ldr w1, [x3, x2]
cmp w7, w1
ble .L144
add w1, w6, 1
cmp w24, w1
ble .L403
add x8, x2, 4
add x4, x3, x8
ldr w8, [x3, x8]
cmp w7, w8
ble .L414
add w8, w6, 2
cmp w24, w8
ble .L409
add x1, x2, 8
add x4, x3, x1
ldr w1, [x3, x1]
cmp w7, w1
ble .L410
add w1, w6, 3
cmp w24, w1
ble .L407
add x8, x2, 12
add x4, x3, x8
ldr w8, [x3, x8]
cmp w7, w8
ble .L414
add w8, w6, 4
cmp w24, w8
ble .L409
add x1, x2, 16
add x4, x3, x1
ldr w1, [x3, x1]
cmp w7, w1
ble .L410
add w9, w6, 5
cmp w24, w9
ble .L411
add x1, x2, 20
add x4, x3, x1
ldr w1, [x3, x1]
cmp w7, w1
ble .L412
add w1, w6, 6
cmp w24, w1
ble .L413
add x2, x2, 24
add x4, x3, x2
ldr w2, [x3, x2]
cmp w7, w2
ble .L414
add w6, w6, 7
.L143:
add x4, x3, w6, uxtw 2
.L140:
str w6, [sp, 112]
str x4, [sp, 120]
bl bstFromPreorder
ldr w6, [sp, 112]
str x0, [x27, 8]
ldr x0, [sp, 120]
sub w1, w24, w6
bl bstFromPreorder
str x0, [x27, 16]
.L138:
ldr x0, [sp, 104]
str x0, [x23, 8]
subs w2, w28, w19
str x27, [x0, 16]
beq .L42
.L59:
add x27, x25, w19, uxtw 2
.L340:
mov x0, 24
str w2, [sp, 104]
bl malloc
mov x28, x0
ldr w5, [x27]
ldr w2, [sp, 104]
str w5, [x0]
cmp w2, 1
ble .L152
add x25, x27, 4
mov w4, 5
sub w1, w2, #2
neg x3, x25, lsr 2
and w19, w3, 3
add w0, w19, 4
cmp w0, w4
csel w0, w0, w4, cs
cmp w1, w0
bcc .L651
cbz w19, .L422
ldr w0, [x27, 4]
cmp w5, w0
ble .L629
tbz x3, 1, .L423
ldr w0, [x27, 8]
cmp w5, w0
ble .L158
cmp w19, 3
bne .L424
ldr w0, [x27, 12]
cmp w5, w0
ble .L159
movi v26.2s, 0x4
.L156:
adrp x0, .LC0
sub w3, w2, #1
add w1, w19, 1
sub w19, w3, w19
ldr q31, [x0, #:lo12:.LC0]
ubfiz x1, x1, 2, 3
dup v30.4s, v26.s[0]
lsr w0, w19, 2
add x1, x27, x1
dup v27.4s, w5
movi v28.4s, 0x4
add x0, x1, w0, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L160
.L177:
cmp x1, x0
beq .L652
add v30.4s, v30.4s, v28.4s
.L160:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x4, d31
cbz x4, .L177
fmov x0, d30
fmov w1, s30
ubfiz x0, x0, 2, 32
ldr w4, [x27, x0]
cmp w5, w4
ble .L653
.L154:
add w24, w1, 1
cmp w2, w24
ble .L427
add x0, x27, x0
ldr w3, [x0, 4]
cmp w5, w3
ble .L427
add w19, w1, 2
cmp w2, w19
ble .L167
ldr w3, [x0, 8]
cmp w5, w3
ble .L168
add w24, w1, 3
cmp w2, w24
ble .L169
ldr w3, [x0, 12]
cmp w5, w3
ble .L174
add w19, w1, 4
cmp w2, w19
ble .L167
ldr w3, [x0, 16]
cmp w5, w3
ble .L168
add w24, w1, 5
mov w8, w24
cmp w2, w24
ble .L169
ldr w3, [x0, 20]
cmp w5, w3
ble .L174
add w4, w1, 6
cmp w2, w4
ble .L175
ldr w0, [x0, 24]
cmp w5, w0
ble .L176
add x6, x27, 8
add w24, w1, 7
mov x0, 24
str x6, [sp, 104]
str w2, [sp, 112]
str w4, [sp, 120]
bl malloc
ldr x6, [sp, 104]
mov x5, x0
ldr w2, [sp, 112]
ldr w4, [sp, 120]
ldr w7, [x27, 4]
str w7, [x0]
.L164:
neg x3, x6, lsr 2
mov w8, 6
and w19, w3, 3
sub w1, w4, #2
add w0, w19, 4
cmp w0, w8
csel w0, w0, w8, cs
cmp w1, w0
bcc .L441
cbz w19, .L442
ldr w0, [x6]
cmp w7, w0
ble .L443
tbz x3, 1, .L444
ldr w0, [x27, 12]
cmp w7, w0
ble .L654
cmp w19, 3
bne .L445
ldr w0, [x27, 16]
movi v26.2s, 0x4
add x8, x27, 16
cmp w7, w0
ble .L184
.L185:
adrp x3, .LC0
sub w0, w4, w19
dup v30.4s, v26.s[0]
add w1, w19, 2
ldr q31, [x3, #:lo12:.LC0]
sub w0, w0, #1
ubfiz x1, x1, 2, 3
dup v27.4s, w7
lsr w3, w0, 2
add x1, x27, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x3, x1, w3, uxtw 4
b .L181
.L188:
cmp x3, x1
beq .L655
add v30.4s, v30.4s, v28.4s
.L181:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x8, d31
cbz x8, .L188
fmov w19, s30
.L180:
ubfiz x3, x19, 2, 32
add x8, x25, x3
ldr w0, [x25, x3]
cmp w0, w7
bge .L184
add w1, w19, 1
cmp w1, w4
bge .L429
add x0, x3, 4
add x8, x25, x0
ldr w0, [x25, x0]
cmp w0, w7
bge .L440
add w9, w19, 2
cmp w9, w4
bge .L435
add x0, x3, 8
add x8, x25, x0
ldr w0, [x25, x0]
cmp w0, w7
bge .L436
add w1, w19, 3
cmp w1, w4
bge .L433
add x0, x3, 12
add x8, x25, x0
ldr w0, [x25, x0]
cmp w0, w7
bge .L440
add w9, w19, 4
cmp w9, w4
bge .L435
add x0, x3, 16
add x8, x25, x0
ldr w0, [x25, x0]
cmp w0, w7
bge .L436
add w10, w19, 5
cmp w10, w4
bge .L437
add x0, x3, 20
add x8, x25, x0
ldr w0, [x25, x0]
cmp w0, w7
bge .L438
add w1, w19, 6
cmp w1, w4
bge .L439
add x3, x3, 24
add x8, x25, x3
ldr w0, [x25, x3]
cmp w0, w7
bge .L440
add w19, w19, 7
.L183:
add x8, x25, w19, uxtw 2
.L179:
mov x0, x6
str x5, [sp, 104]
str w2, [sp, 112]
str x8, [sp, 120]
str w4, [sp, 128]
bl bstFromPreorder
ldr x5, [sp, 104]
ldr w4, [sp, 128]
str x0, [x5, 8]
sub w1, w4, w19
ldr x0, [sp, 120]
bl bstFromPreorder
ldr x5, [sp, 104]
str x5, [x28, 8]
ldr w2, [sp, 112]
str x0, [x5, 16]
subs w19, w2, w24
beq .L190
add x25, x27, w24, uxtw 2
.L339:
mov x0, 24
bl malloc
mov x24, x0
mov x0, x25
ldr w4, [x0], 4
str w4, [x24]
cmp w19, 1
ble .L656
neg x5, x0, lsr 2
mov w6, 6
and w2, w5, 3
sub w3, w19, #2
add w1, w2, 4
cmp w1, w6
csel w1, w1, w6, cs
cmp w3, w1
bcc .L460
cbz w2, .L461
ldr w1, [x25, 4]
cmp w4, w1
ble .L462
tbz x5, 1, .L463
ldr w1, [x25, 8]
add x3, x25, 8
mov w27, 2
cmp w4, w1
ble .L196
cmp w2, 3
bne .L464
ldr w1, [x25, 12]
movi v26.2s, 0x4
add x3, x25, 12
mov w27, w2
cmp w4, w1
ble .L196
.L198:
sub w3, w19, #1
add w1, w2, 1
sub w3, w3, w2
adrp x2, .LC0
dup v30.4s, v26.s[0]
ubfiz x1, x1, 2, 3
ldr q31, [x2, #:lo12:.LC0]
lsr w2, w3, 2
add x1, x25, x1
dup v27.4s, w4
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L193
.L201:
cmp x2, x1
beq .L657
add v30.4s, v30.4s, v28.4s
.L193:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L201
fmov w27, s30
.L197:
ubfiz x2, x27, 2, 32
add x3, x25, x2
ldr w1, [x25, x2]
cmp w4, w1
ble .L196
add w1, w27, 1
cmp w19, w1
ble .L448
add x5, x2, 4
add x3, x25, x5
ldr w5, [x25, x5]
cmp w4, w5
ble .L459
add w5, w27, 2
cmp w19, w5
ble .L454
add x1, x2, 8
add x3, x25, x1
ldr w1, [x25, x1]
cmp w4, w1
ble .L455
add w1, w27, 3
cmp w19, w1
ble .L452
add x5, x2, 12
add x3, x25, x5
ldr w5, [x25, x5]
cmp w4, w5
ble .L459
add w5, w27, 4
cmp w19, w5
ble .L454
add x1, x2, 16
add x3, x25, x1
ldr w1, [x25, x1]
cmp w4, w1
ble .L455
add w6, w27, 5
cmp w19, w6
ble .L456
add x1, x2, 20
add x3, x25, x1
ldr w1, [x25, x1]
cmp w4, w1
ble .L457
add w1, w27, 6
cmp w19, w1
ble .L458
add x2, x2, 24
add x3, x25, x2
ldr w2, [x25, x2]
cmp w4, w2
ble .L459
add w27, w27, 7
.L195:
add x3, x25, w27, uxtw 2
.L192:
str x3, [sp, 104]
bl bstFromPreorder
str x0, [x24, 8]
sub w1, w19, w27
ldr x0, [sp, 104]
bl bstFromPreorder
str x0, [x24, 16]
.L162:
str x24, [x28, 16]
.L151:
str x23, [x21, 8]
subs w27, w20, w22
str x28, [x23, 16]
beq .L622
.L31:
add x25, x26, w22, uxtw 2
.L338:
mov x0, 24
bl malloc
ldr w4, [x25]
mov x22, x0
str w4, [x0]
cmp w27, 1
ble .L204
.L32:
add x23, x25, 4
mov w2, 5
sub w20, w27, #2
neg x1, x23, lsr 2
and w19, w1, 3
add w0, w19, 4
cmp w0, w2
csel w0, w0, w2, cs
cmp w20, w0
bcc .L658
cbz w19, .L467
ldr w0, [x25, 4]
cmp w0, w4
bge .L209
tbz x1, 1, .L468
ldr w0, [x25, 8]
cmp w0, w4
bge .L211
cmp w19, 3
bne .L469
ldr w0, [x25, 12]
cmp w0, w4
bge .L212
movi v26.2s, 0x4
.L208:
adrp x0, .LC0
sub w2, w27, #1
add w1, w19, 1
sub w19, w2, w19
ldr q31, [x0, #:lo12:.LC0]
ubfiz x1, x1, 2, 3
dup v30.4s, v26.s[0]
lsr w0, w19, 2
add x1, x25, x1
dup v27.4s, w4
movi v28.4s, 0x4
add x0, x1, w0, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L213
.L230:
cmp x0, x1
beq .L659
add v30.4s, v30.4s, v28.4s
.L213:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x3, d31
cbz x3, .L230
fmov x0, d30
ubfiz x1, x0, 2, 32
ldr w3, [x25, x1]
cmp w3, w4
bge .L660
.L206:
add w20, w0, 1
cmp w20, w27
bge .L473
add x1, x25, x1
ldr w2, [x1, 4]
cmp w2, w4
bge .L473
add w19, w0, 2
cmp w19, w27
bge .L220
ldr w2, [x1, 8]
cmp w2, w4
bge .L221
add w20, w0, 3
cmp w20, w27
bge .L222
ldr w2, [x1, 12]
cmp w2, w4
bge .L227
add w19, w0, 4
cmp w19, w27
bge .L220
ldr w2, [x1, 16]
cmp w2, w4
bge .L221
add w20, w0, 5
mov w24, w20
cmp w20, w27
bge .L222
ldr w2, [x1, 20]
cmp w2, w4
bge .L227
add w3, w0, 6
cmp w3, w27
bge .L228
ldr w1, [x1, 24]
cmp w1, w4
bge .L229
add w20, w0, 7
mov x0, 24
str w3, [sp, 104]
bl malloc
ldr w3, [sp, 104]
mov x28, x0
ldr w5, [x25, 4]
str w5, [x0]
.L217:
add x26, x25, 8
mov w4, 5
sub w1, w3, #2
neg x2, x26, lsr 2
and w24, w2, 3
add w0, w24, 4
cmp w0, w4
csel w0, w0, w4, cs
cmp w1, w0
bcc .L661
cbz w24, .L475
ldr w0, [x25, 8]
cmp w0, w5
bge .L237
tbz x2, 1, .L476
ldr w0, [x25, 12]
cmp w0, w5
bge .L240
cmp w24, 3
bne .L477
ldr w0, [x25, 16]
cmp w0, w5
bge .L241
movi v26.2s, 0x4
.L238:
adrp x2, .LC0
sub w0, w3, w24
dup v30.4s, v26.s[0]
add w1, w24, 2
ldr q31, [x2, #:lo12:.LC0]
sub w0, w0, #1
ubfiz x1, x1, 2, 3
dup v27.4s, w5
lsr w2, w0, 2
add x1, x25, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
b .L242
.L258:
cmp x2, x1
beq .L662
add v30.4s, v30.4s, v28.4s
.L242:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x4, d31
cbz x4, .L258
fmov x0, d30
fmov w1, s30
ubfiz x0, x0, 2, 32
ldr w2, [x23, x0]
cmp w5, w2
ble .L663
.L236:
add w24, w1, 1
cmp w3, w24
ble .L480
add x0, x23, x0
ldr w2, [x0, 4]
cmp w5, w2
ble .L480
add w19, w1, 2
cmp w3, w19
ble .L248
ldr w2, [x0, 8]
cmp w5, w2
ble .L249
add w24, w1, 3
cmp w3, w24
ble .L250
ldr w2, [x0, 12]
cmp w5, w2
ble .L255
add w19, w1, 4
cmp w3, w19
ble .L248
ldr w2, [x0, 16]
cmp w5, w2
ble .L249
add w24, w1, 5
mov w8, w24
cmp w3, w24
ble .L250
ldr w2, [x0, 20]
cmp w2, w5
bge .L255
add w4, w1, 6
cmp w4, w3
bge .L256
ldr w0, [x0, 24]
cmp w0, w5
bge .L257
add x6, x25, 12
add w24, w1, 7
mov x0, 24
str x6, [sp, 104]
str w3, [sp, 112]
str w4, [sp, 120]
bl malloc
ldr x6, [sp, 104]
mov x5, x0
ldr w3, [sp, 112]
ldr w4, [sp, 120]
ldr w7, [x25, 8]
str w7, [x0]
.L245:
neg x2, x6, lsr 2
mov w8, 6
and w19, w2, 3
sub w1, w4, #2
add w0, w19, 4
cmp w0, w8
csel w0, w0, w8, cs
cmp w1, w0
bcc .L494
cbz w19, .L495
ldr w0, [x6]
cmp w7, w0
ble .L496
tbz x2, 1, .L497
ldr w0, [x25, 16]
cmp w7, w0
ble .L664
cmp w19, 3
bne .L498
ldr w0, [x25, 20]
movi v26.2s, 0x4
add x8, x25, 20
cmp w0, w7
bge .L265
.L266:
adrp x2, .LC0
sub w0, w4, w19
dup v30.4s, v26.s[0]
add w1, w19, 3
ldr q31, [x2, #:lo12:.LC0]
sub w0, w0, #1
ubfiz x1, x1, 2, 3
dup v27.4s, w7
lsr w2, w0, 2
add x1, x25, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
b .L262
.L269:
cmp x2, x1
beq .L665
add v30.4s, v30.4s, v28.4s
.L262:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x8, d31
cbz x8, .L269
fmov w19, s30
.L261:
ubfiz x2, x19, 2, 32
add x8, x26, x2
ldr w0, [x26, x2]
cmp w0, w7
bge .L265
add w1, w19, 1
cmp w1, w4
bge .L482
add x0, x2, 4
add x8, x26, x0
ldr w0, [x26, x0]
cmp w0, w7
bge .L493
add w9, w19, 2
cmp w9, w4
bge .L488
add x0, x2, 8
add x8, x26, x0
ldr w0, [x26, x0]
cmp w0, w7
bge .L489
add w1, w19, 3
cmp w1, w4
bge .L486
add x0, x2, 12
add x8, x26, x0
ldr w0, [x26, x0]
cmp w0, w7
bge .L493
add w9, w19, 4
cmp w9, w4
bge .L488
add x0, x2, 16
add x8, x26, x0
ldr w0, [x26, x0]
cmp w0, w7
bge .L489
add w10, w19, 5
cmp w10, w4
bge .L490
add x0, x2, 20
add x8, x26, x0
ldr w0, [x26, x0]
cmp w0, w7
bge .L491
add w1, w19, 6
cmp w1, w4
bge .L492
add x2, x2, 24
add x8, x26, x2
ldr w0, [x26, x2]
cmp w0, w7
bge .L493
add w19, w19, 7
.L264:
add x8, x26, w19, uxtw 2
.L260:
mov x0, x6
stp x5, x8, [sp, 104]
add x26, x23, w24, uxtw 2
str w3, [sp, 120]
str w4, [sp, 128]
bl bstFromPreorder
ldr x5, [sp, 104]
ldr w4, [sp, 128]
str x0, [x5, 8]
sub w1, w4, w19
ldr x0, [sp, 112]
bl bstFromPreorder
ldr x5, [sp, 104]
str x5, [x28, 8]
ldr w3, [sp, 120]
str x0, [x5, 16]
subs w24, w3, w24
beq .L243
.L337:
mov x0, 24
bl malloc
mov x23, x0
mov x0, x26
mov w1, 0
mov w19, 1
ldr w4, [x0], 4
str w4, [x23]
mov x3, x0
cmp w24, 1
ble .L274
neg x5, x0, lsr 2
mov w6, 6
and w2, w5, 3
sub w3, w24, #2
add w1, w2, 4
cmp w1, w6
csel w1, w1, w6, cs
cmp w3, w1
bcc .L513
cbz w2, .L514
ldr w1, [x26, 4]
cmp w4, w1
ble .L515
tbz x5, 1, .L516
ldr w1, [x26, 8]
add x3, x26, 8
mov w19, 2
cmp w4, w1
ble .L278
cmp w2, 3
bne .L517
ldr w1, [x26, 12]
movi v26.2s, 0x4
add x3, x26, 12
mov w19, w2
cmp w4, w1
ble .L278
.L280:
sub w3, w24, #1
add w1, w2, 1
sub w3, w3, w2
adrp x2, .LC0
dup v30.4s, v26.s[0]
ubfiz x1, x1, 2, 3
ldr q31, [x2, #:lo12:.LC0]
lsr w2, w3, 2
add x1, x26, x1
dup v27.4s, w4
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L275
.L283:
cmp x2, x1
beq .L666
add v30.4s, v30.4s, v28.4s
.L275:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L283
fmov w19, s30
.L279:
ubfiz x2, x19, 2, 32
add x3, x26, x2
ldr w1, [x26, x2]
cmp w1, w4
bge .L278
add w1, w19, 1
cmp w1, w24
bge .L501
add x5, x2, 4
add x3, x26, x5
ldr w5, [x26, x5]
cmp w4, w5
ble .L512
add w5, w19, 2
cmp w24, w5
ble .L507
add x1, x2, 8
add x3, x26, x1
ldr w1, [x26, x1]
cmp w1, w4
bge .L508
add w1, w19, 3
cmp w1, w24
bge .L505
add x5, x2, 12
add x3, x26, x5
ldr w5, [x26, x5]
cmp w5, w4
bge .L512
add w5, w19, 4
cmp w5, w24
bge .L507
add x1, x2, 16
add x3, x26, x1
ldr w1, [x26, x1]
cmp w4, w1
ble .L508
add w6, w19, 5
cmp w6, w24
bge .L509
add x1, x2, 20
add x3, x26, x1
ldr w1, [x26, x1]
cmp w4, w1
ble .L510
add w1, w19, 6
cmp w24, w1
ble .L511
add x2, x2, 24
add x3, x26, x2
ldr w2, [x26, x2]
cmp w4, w2
ble .L512
add w19, w19, 7
.L277:
add x3, x26, w19, uxtw 2
.L274:
str x3, [sp, 104]
bl bstFromPreorder
str x0, [x23, 8]
sub w1, w24, w19
ldr x0, [sp, 104]
bl bstFromPreorder
str x0, [x23, 16]
.L272:
str x28, [x22, 8]
subs w27, w27, w20
str x23, [x28, 16]
mov x26, 0
beq .L624
.L232:
add x23, x25, w20, uxtw 2
.L336:
mov x0, 24
bl malloc
ldr w3, [x23]
mov x26, x0
str w3, [x0]
cmp w27, 1
ble .L285
.L233:
add x24, x23, 4
mov w4, 5
sub w1, w27, #2
neg x2, x24, lsr 2
and w20, w2, 3
add w0, w20, 4
cmp w0, w4
csel w0, w0, w4, cs
cmp w0, w1
bhi .L667
cbz w20, .L521
ldr w0, [x23, 4]
cmp w0, w3
bge .L628
tbz x2, 1, .L522
ldr w0, [x23, 8]
cmp w0, w3
bge .L291
cmp w20, 3
bne .L523
ldr w0, [x23, 12]
cmp w0, w3
bge .L292
movi v26.2s, 0x4
.L289:
adrp x0, .LC0
sub w19, w27, #1
add w1, w20, 1
sub w20, w19, w20
ldr q31, [x0, #:lo12:.LC0]
ubfiz x1, x1, 2, 3
dup v30.4s, v26.s[0]
lsr w0, w20, 2
add x1, x23, x1
dup v27.4s, w3
movi v28.4s, 0x4
add x0, x1, w0, uxtw 4
add v30.4s, v30.4s, v31.4s
b .L293
.L310:
cmp x0, x1
beq .L668
add v30.4s, v30.4s, v28.4s
.L293:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x2, d31
cbz x2, .L310
fmov x0, d30
fmov w1, s30
ubfiz x0, x0, 2, 32
ldr w2, [x23, x0]
cmp w2, w3
bge .L669
.L287:
add w20, w1, 1
cmp w20, w27
bge .L527
add x0, x23, x0
ldr w2, [x0, 4]
cmp w2, w3
bge .L527
add w19, w1, 2
cmp w19, w27
bge .L300
ldr w2, [x0, 8]
cmp w2, w3
bge .L301
add w20, w1, 3
cmp w20, w27
bge .L302
ldr w2, [x0, 12]
cmp w2, w3
bge .L307
add w19, w1, 4
cmp w19, w27
bge .L300
ldr w2, [x0, 16]
cmp w2, w3
bge .L301
add w20, w1, 5
mov w5, w20
cmp w20, w27
bge .L302
ldr w2, [x0, 20]
cmp w2, w3
bge .L307
add w25, w1, 6
cmp w25, w27
bge .L308
ldr w0, [x0, 24]
cmp w0, w3
bge .L309
add x3, x23, 8
add w20, w1, 7
mov x0, 24
str x3, [sp, 104]
bl malloc
mov x28, x0
ldr w4, [x23, 4]
ldr x3, [sp, 104]
str w4, [x0]
.L297:
neg x2, x3, lsr 2
mov w5, 6
and w19, w2, 3
sub w1, w25, #2
add w0, w19, 4
cmp w0, w5
csel w0, w0, w5, cs
cmp w1, w0
bcc .L541
cbz w19, .L542
ldr w0, [x3]
cmp w0, w4
bge .L543
tbz x2, 1, .L544
ldr w0, [x23, 12]
cmp w4, w0
ble .L670
cmp w19, 3
bne .L545
ldr w0, [x23, 16]
movi v26.2s, 0x4
add x5, x23, 16
cmp w0, w4
bge .L317
.L318:
adrp x2, .LC0
sub w0, w25, w19
dup v30.4s, v26.s[0]
add w1, w19, 2
ldr q31, [x2, #:lo12:.LC0]
sub w0, w0, #1
ubfiz x1, x1, 2, 3
dup v27.4s, w4
lsr w2, w0, 2
add x1, x23, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
b .L314
.L321:
cmp x2, x1
beq .L671
add v30.4s, v30.4s, v28.4s
.L314:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L321
fmov w19, s30
.L313:
ubfiz x2, x19, 2, 32
add x5, x24, x2
ldr w0, [x24, x2]
cmp w0, w4
bge .L317
add w1, w19, 1
cmp w1, w25
bge .L529
add x0, x2, 4
add x5, x24, x0
ldr w0, [x24, x0]
cmp w0, w4
bge .L540
add w6, w19, 2
cmp w6, w25
bge .L535
add x0, x2, 8
add x5, x24, x0
ldr w0, [x24, x0]
cmp w0, w4
bge .L536
add w1, w19, 3
cmp w1, w25
bge .L533
add x0, x2, 12
add x5, x24, x0
ldr w0, [x24, x0]
cmp w0, w4
bge .L540
add w6, w19, 4
cmp w6, w25
bge .L535
add x0, x2, 16
add x5, x24, x0
ldr w0, [x24, x0]
cmp w0, w4
bge .L536
add w7, w19, 5
cmp w7, w25
bge .L537
add x0, x2, 20
add x5, x24, x0
ldr w0, [x24, x0]
cmp w0, w4
bge .L538
add w1, w19, 6
cmp w1, w25
bge .L539
add x2, x2, 24
add x5, x24, x2
ldr w0, [x24, x2]
cmp w0, w4
bge .L540
add w19, w19, 7
.L316:
add x5, x24, w19, uxtw 2
.L312:
mov x0, x3
str x5, [sp, 104]
bl bstFromPreorder
str x0, [x28, 8]
ldr x0, [sp, 104]
sub w1, w25, w19
mov x25, 0
bl bstFromPreorder
str x28, [x26, 8]
str x0, [x28, 16]
subs w19, w27, w20
beq .L626
add x24, x23, w20, uxtw 2
.L335:
mov x0, 24
bl malloc
mov x25, x0
mov x0, x24
ldr w4, [x0], 4
str w4, [x25]
cmp w19, 1
ble .L672
neg x3, x0, lsr 2
mov w5, 6
and w20, w3, 3
sub w2, w19, #2
add w1, w20, 4
cmp w1, w5
csel w1, w1, w5, cs
cmp w1, w2
bhi .L561
cbz w20, .L562
ldr w1, [x24, 4]
cmp w1, w4
bge .L563
tbz x3, 1, .L564
ldr w1, [x24, 8]
cmp w4, w1
ble .L673
cmp w20, 3
bne .L565
ldr w1, [x24, 12]
movi v26.2s, 0x4
add x23, x24, 12
cmp w4, w1
ble .L328
.L330:
adrp x2, .LC0
sub w3, w19, #1
dup v30.4s, v26.s[0]
add w1, w20, 1
ldr q31, [x2, #:lo12:.LC0]
sub w3, w3, w20
ubfiz x1, x1, 2, 3
dup v27.4s, w4
lsr w2, w3, 2
add x1, x24, x1
add v30.4s, v30.4s, v31.4s
movi v28.4s, 0x4
add x2, x1, w2, uxtw 4
b .L325
.L333:
cmp x2, x1
beq .L674
add v30.4s, v30.4s, v28.4s
.L325:
ldr q31, [x1]
add x1, x1, 16
cmge v31.4s, v31.4s, v27.4s
umaxp v31.4s, v31.4s, v31.4s
fmov x5, d31
cbz x5, .L333
fmov w20, s30
.L329:
ubfiz x2, x20, 2, 32
add x23, x24, x2
ldr w1, [x24, x2]
cmp w1, w4
bge .L328
add w1, w20, 1
cmp w1, w19
bge .L549
add x3, x2, 4
add x23, x24, x3
ldr w3, [x24, x3]
cmp w3, w4
bge .L560
add w3, w20, 2
cmp w3, w19
bge .L555
add x1, x2, 8
add x23, x24, x1
ldr w1, [x24, x1]
cmp w1, w4
bge .L556
add w1, w20, 3
cmp w1, w19
bge .L553
add x3, x2, 12
add x23, x24, x3
ldr w3, [x24, x3]
cmp w3, w4
bge .L560
add w3, w20, 4
cmp w3, w19
bge .L555
add x1, x2, 16
add x23, x24, x1
ldr w1, [x24, x1]
cmp w1, w4
bge .L556
add w5, w20, 5
cmp w5, w19
bge .L557
add x1, x2, 20
add x23, x24, x1
ldr w1, [x24, x1]
cmp w1, w4
bge .L558
add w1, w20, 6
cmp w1, w19
bge .L559
add x2, x2, 24
add x23, x24, x2
ldr w2, [x24, x2]
cmp w4, w2
ble .L560
add w20, w20, 7
.L327:
ldp x27, x28, [sp, 80]
add x23, x24, w20, uxtw 2
.L324:
bl bstFromPreorder
str x0, [x25, 8]
sub w1, w19, w20
mov x0, x23
bl bstFromPreorder
str x25, [x26, 16]
str x0, [x25, 16]
.L214:
str x26, [x22, 16]
.L677:
str x22, [x21, 16]
ldp x19, x20, [sp, 16]
ldp x23, x24, [sp, 48]
ldp x25, x26, [sp, 64]
.L1:
mov x0, x21
ldp x21, x22, [sp, 32]
ldp x29, x30, [sp], 176
ret
.L635:
tst x19, 3
beq .L675
fmov w0, s26
and w19, w19, -4
add w2, w19, w0
add w0, w19, w0
sub w28, w0, #1
mov w22, w0
lsl x2, x2, 2
ldr w3, [x26, x2]
cmp w1, w3
bgt .L5
.L18:
mov x0, 24
bl malloc
ldr w3, [x26, 4]
mov x23, x0
str w3, [x0]
cmp w28, 1
bne .L16
str xzr, [x0, 8]
.L42:
mov x28, 0
b .L151
.L638:
tst x1, 3
beq .L676
and w0, w1, -4
fmov w1, s26
fmov w2, s26
add w1, w0, w1
add w0, w0, w2
lsl x1, x1, 2
sub w24, w0, #1
mov w19, w0
ldr w2, [x25, x1]
cmp w3, w2
bgt .L35
b .L46
.L345:
movi v26.2s, 0x1
b .L7
.L622:
ldp x27, x28, [sp, 80]
.L203:
mov x22, 0
str x22, [x21, 16]
mov x0, x21
ldp x19, x20, [sp, 16]
ldp x23, x24, [sp, 48]
ldp x25, x26, [sp, 64]
ldp x21, x22, [sp, 32]
ldp x29, x30, [sp], 176
ret
.L624:
ldp x27, x28, [sp, 80]
str x26, [x22, 16]
b .L677
.L676:
movi v31.4s, 0x1
umov w24, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w19, v30.s[3]
.L46:
mov x0, 24
bl malloc
ldr w6, [x26, 8]
str w6, [x0]
str x0, [sp, 104]
cmp w24, 1
bne .L44
str xzr, [x0, 8]
.L69:
mov x27, 0
b .L138
.L659:
tst x19, 3
beq .L678
fmov w0, s26
and w19, w19, -4
add w1, w19, w0
add w0, w19, w0
sub w3, w0, #1
mov w20, w0
lsl x1, x1, 2
ldr w2, [x25, x1]
cmp w2, w4
blt .L206
.L219:
mov x0, 24
str w3, [sp, 104]
bl malloc
mov x28, x0
ldr w5, [x25, 4]
ldr w3, [sp, 104]
str w5, [x0]
cmp w3, 1
bne .L217
str xzr, [x0, 8]
.L243:
mov x23, 0
b .L272
.L636:
fmov w22, s30
subs w28, w0, #1
bne .L18
str xzr, [x21, 8]
b .L338
.L641:
tst x2, 3
beq .L679
fmov w1, s26
and w0, w2, -4
fmov w2, s26
add w1, w0, w1
add w0, w0, w2
lsl x1, x1, 2
sub w9, w0, #1
mov w4, w0
ldr w2, [x27, x1]
cmp w6, w2
bgt .L62
.L73:
mov x0, 24
str x3, [sp, 112]
str w4, [sp, 120]
str w9, [sp, 128]
bl malloc
ldr w11, [x26, 12]
mov x6, x0
ldr w9, [sp, 128]
str w11, [x0]
ldr x3, [sp, 112]
cmp w9, 1
ldr w4, [sp, 120]
bne .L71
str xzr, [x0, 8]
.L96:
mov x9, 0
b .L125
.L662:
tst x0, 3
beq .L680
fmov w1, s26
and w0, w0, -4
add w2, w0, w1
add w1, w0, w1
sub w4, w1, #1
mov w24, w1
lsl x0, x2, 2
ldr w2, [x23, x0]
cmp w5, w2
bgt .L236
.L247:
add x6, x25, 12
mov x0, 24
str x6, [sp, 104]
str w3, [sp, 112]
str w4, [sp, 120]
bl malloc
ldr w7, [x25, 8]
mov x5, x0
ldr w4, [sp, 120]
str w7, [x0]
ldr x6, [sp, 104]
cmp w4, 1
ldr w3, [sp, 112]
bne .L245
mov x8, x6
mov w19, w4
mov w1, 0
b .L260
.L652:
tst x19, 3
beq .L681
fmov w0, s26
and w19, w19, -4
fmov w1, s26
add w0, w19, w0
add w1, w19, w1
lsl x0, x0, 2
sub w4, w1, #1
mov w24, w1
ldr w3, [x27, x0]
cmp w5, w3
bgt .L154
.L166:
add x6, x27, 8
mov x0, 24
str x6, [sp, 104]
str w2, [sp, 112]
str w4, [sp, 120]
bl malloc
ldr w7, [x27, 4]
mov x5, x0
ldr w4, [sp, 120]
str w7, [x0]
ldr x6, [sp, 104]
cmp w4, 1
ldr w2, [sp, 112]
bne .L164
mov x8, x6
mov w19, w4
mov w1, 0
b .L179
.L668:
tst x20, 3
beq .L682
fmov w0, s26
and w20, w20, -4
fmov w1, s26
add w0, w20, w0
add w1, w20, w1
lsl x0, x0, 2
sub w25, w1, #1
mov w20, w1
ldr w2, [x23, x0]
cmp w2, w3
blt .L287
.L299:
add x3, x23, 8
mov x0, 24
str x3, [sp, 104]
bl malloc
mov x28, x0
ldr w4, [x23, 4]
cmp w25, 1
str w4, [x0]
ldr x3, [sp, 104]
bne .L297
mov x5, x3
mov w19, w25
mov w1, 0
b .L312
.L639:
fmov w19, s30
subs w24, w0, #1
bne .L46
.L36:
sub w2, w22, #2
str xzr, [x23, 8]
b .L340
.L512:
mov w19, w1
.L278:
sub w1, w19, #1
b .L274
.L540:
mov w19, w1
.L317:
sub w1, w19, #1
b .L312
.L560:
mov w20, w1
.L328:
ldp x27, x28, [sp, 80]
sub w1, w20, #1
b .L324
.L414:
mov w6, w1
.L144:
sub w1, w6, #1
b .L140
.L440:
mov w19, w1
.L184:
sub w1, w19, #1
b .L179
.L493:
mov w19, w1
.L265:
sub w1, w19, #1
b .L260
.L459:
mov w27, w1
.L196:
sub w1, w27, #1
b .L192
.L467:
movi v26.2s, 0x1
b .L208
.L352:
movi v26.2s, 0x1
b .L37
.L190:
mov x24, 0
b .L162
.L660:
fmov w20, s30
subs w3, w0, #1
bne .L219
.L207:
mov w27, w2
str xzr, [x22, 8]
b .L336
.L665:
fmov w1, s26
and w19, w0, -4
add w19, w19, w1
tst x0, 3
bne .L261
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w19, v30.s[3]
b .L264
.L666:
fmov w1, s26
and w2, w3, -4
add w19, w2, w1
tst x3, 3
bne .L279
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w19, v30.s[3]
b .L277
.L650:
fmov w1, s26
and w2, w4, -4
add w6, w2, w1
tst x4, 3
bne .L145
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w6, v30.s[3]
b .L143
.L644:
tst x2, 3
beq .L683
fmov w1, s26
and w0, w2, -4
fmov w2, s26
add w1, w0, w1
add w0, w0, w2
lsl x1, x1, 2
sub w10, w0, #1
mov w8, w0
ldr w2, [x3, x1]
cmp w11, w2
bgt .L89
.L100:
add x12, x26, 20
mov x0, 24
stp x12, x3, [sp, 112]
str x7, [sp, 128]
str w4, [sp, 136]
str x6, [sp, 144]
str w9, [sp, 152]
stp w8, w10, [sp, 164]
bl malloc
ldp w8, w10, [sp, 164]
mov x11, x0
ldr w13, [x26, 16]
ldp x12, x3, [sp, 112]
str w13, [x0]
ldr x7, [sp, 128]
cmp w10, 1
ldr x6, [sp, 144]
ldr w4, [sp, 136]
ldr w9, [sp, 152]
bne .L98
mov x14, x12
mov w2, w10
mov w1, 0
b .L113
.L657:
fmov w1, s26
and w2, w3, -4
add w27, w2, w1
tst x3, 3
bne .L197
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w27, v30.s[3]
b .L195
.L655:
fmov w1, s26
and w19, w0, -4
add w19, w19, w1
tst x0, 3
bne .L180
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w19, v30.s[3]
b .L183
.L671:
fmov w1, s26
and w19, w0, -4
add w19, w19, w1
tst x0, 3
bne .L313
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w19, v30.s[3]
b .L316
.L674:
fmov w1, s26
and w20, w3, -4
add w20, w20, w1
tst x3, 3
bne .L329
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w20, v30.s[3]
b .L327
.L626:
ldp x27, x28, [sp, 80]
str x25, [x26, 16]
b .L214
.L642:
fmov w4, s30
subs w9, w0, #1
bne .L73
.L63:
ldr x0, [sp, 104]
sub w24, w19, #2
str xzr, [x0, 8]
b .L341
.L663:
fmov w24, s30
subs w4, w1, #1
bne .L247
.L237:
sub w24, w20, #2
str xzr, [x28, 8]
b .L337
.L395:
mov w2, w1
.L131:
sub w1, w2, #1
b .L127
.L380:
mov w2, w1
.L118:
sub w1, w2, #1
b .L113
.L359:
movi v26.2s, 0x1
b .L64
.L521:
movi v26.2s, 0x1
b .L289
.L422:
movi v26.2s, 0x1
b .L156
.L475:
movi v26.2s, 0x1
b .L238
.L675:
movi v31.4s, 0x1
umov w28, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w22, v30.s[3]
b .L18
.L649:
fmov w1, s26
and w11, w10, -4
add w11, w11, w1
tst x10, 3
bne .L132
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w2, v30.s[3]
b .L130
.L669:
fmov w20, s30
subs w25, w1, #1
bne .L299
str xzr, [x26, 8]
b .L335
.L653:
fmov w24, s30
subs w4, w1, #1
bne .L166
.L155:
mov w19, w3
str xzr, [x28, 8]
b .L339
.L647:
fmov w0, s26
and w15, w2, -4
add w15, w15, w0
tst x2, 3
bne .L114
movi v31.4s, 0x1
umov w1, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w2, v30.s[3]
b .L117
.L634:
ldr w3, [x26, 4]
sub w27, w20, #1
mov x2, 4
mov w0, 1
cmp w1, w3
bgt .L5
str xzr, [x21, 8]
b .L338
.L645:
fmov w8, s30
subs w10, w0, #1
bne .L100
.L90:
sub w8, w4, #2
str xzr, [x6, 8]
b .L342
.L350:
mov w28, w0
b .L18
.L366:
movi v26.2s, 0x1
b .L91
.L542:
movi v26.2s, 0x1
b .L318
.L442:
movi v26.2s, 0x1
b .L185
.L495:
movi v26.2s, 0x1
b .L266
.L461:
movi v26.2s, 0x1
b .L198
.L416:
movi v26.2s, 0x1
b .L146
.L562:
movi v26.2s, 0x1
b .L330
.L514:
movi v26.2s, 0x1
b .L280
.L678:
movi v31.4s, 0x1
umov w3, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w20, v30.s[3]
b .L219
.L54:
mov w24, w2
b .L46
.L637:
ldr w2, [x26, 8]
mov x1, 4
mov w0, 1
cmp w2, w3
blt .L35
b .L36
.L658:
ldr w2, [x25, 4]
mov x1, 4
mov w0, 1
cmp w2, w4
blt .L206
sub w2, w27, #1
b .L207
.L19:
mov x0, 24
bl malloc
ldr w3, [x26, 4]
mov w28, w22
mov x23, x0
mov w22, w19
str w3, [x0]
b .L16
.L20:
mov w28, w22
mov w22, w19
b .L18
.L3:
str xzr, [x0, 8]
beq .L203
mov x0, 24
bl malloc
ldr w1, [x26, 4]
mov x22, x0
sub w19, w20, #2
str w1, [x0]
str xzr, [x0, 8]
.L215:
mov x0, 24
bl malloc
mov x26, x0
add x23, x25, 4
ldr w0, [x25, 4]
sub w19, w19, #1
str w0, [x26]
str xzr, [x26, 8]
.L295:
mov x0, 24
bl malloc
mov x25, x0
ldr w2, [x23, 4]
add x23, x23, 8
mov w1, 0
mov x0, x23
mov w20, 1
str w2, [x25]
b .L324
.L21:
mov x0, 24
bl malloc
ldr w3, [x26, 4]
mov x23, x0
mov w28, w19
str w3, [x0]
b .L16
.L357:
mov w24, w0
b .L46
.L26:
mov w28, w19
b .L18
.L382:
movi v26.2s, 0x1
b .L119
.L473:
mov w3, w0
b .L219
.L397:
movi v26.2s, 0x1
b .L133
.L682:
movi v31.4s, 0x1
umov w25, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w20, v30.s[3]
b .L299
.L680:
movi v31.4s, 0x1
umov w4, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w24, v30.s[3]
b .L247
.L679:
movi v31.4s, 0x1
umov w9, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w4, v30.s[3]
b .L73
.L681:
movi v31.4s, 0x1
umov w4, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w24, v30.s[3]
b .L166
.L640:
ldr w2, [x26, 12]
mov x1, 4
mov w0, 1
cmp w2, w6
blt .L62
b .L63
.L651:
ldr w3, [x27, 4]
mov x0, 4
mov w1, 1
cmp w5, w3
bgt .L154
.L629:
sub w3, w2, #1
b .L155
.L667:
ldr w2, [x23, 4]
mov x0, 4
mov w1, 1
cmp w2, w3
blt .L287
.L628:
sub w19, w27, #1
str xzr, [x26, 8]
b .L335
.L661:
ldr w2, [x25, 8]
mov x0, 4
mov w1, 1
cmp w5, w2
bgt .L236
b .L237
.L47:
mov x0, 24
str w2, [sp, 112]
bl malloc
str x0, [sp, 104]
ldr w6, [x26, 8]
mov w24, w19
ldr w19, [sp, 112]
str w6, [x0]
b .L44
.L220:
mov x0, 24
bl malloc
ldr w5, [x25, 4]
mov w3, w20
mov x28, x0
mov w20, w19
str w5, [x0]
b .L217
.L221:
mov w3, w20
mov w20, w19
b .L219
.L48:
mov w24, w19
mov w19, w2
b .L46
.L222:
mov x0, 24
bl malloc
ldr w5, [x25, 4]
mov x28, x0
mov w3, w19
str w5, [x0]
b .L217
.L49:
mov x0, 24
str w2, [sp, 112]
bl malloc
str x0, [sp, 104]
ldr w6, [x26, 8]
ldr w24, [sp, 112]
str w6, [x0]
b .L44
.L427:
mov w4, w1
b .L166
.L364:
mov w9, w0
b .L73
.L527:
mov w25, w1
b .L299
.L227:
mov w3, w19
b .L219
.L480:
mov w4, w1
b .L247
.L8:
str xzr, [x21, 8]
mov x0, 24
sub w27, w20, #1
bl malloc
mov x22, x0
ldr w4, [x26, 4]
str w4, [x0]
b .L32
.L683:
movi v31.4s, 0x1
umov w10, v30.s[3]
add v30.4s, v30.4s, v31.4s
umov w8, v30.s[3]
b .L100
.L643:
ldr w2, [x26, 16]
mov x1, 4
mov w0, 1
cmp w2, w11
blt .L89
b .L90
.L346:
movi v26.2s, 0x2
b .L7
.L513:
mov w19, 1
b .L279
.L460:
mov w27, 1
b .L197
.L415:
mov w6, 1
b .L145
.L561:
mov w20, 1
b .L329
.L10:
mov x0, 24
bl malloc
ldr w1, [x26, 4]
mov w22, 2
str x0, [x21, 8]
str w1, [x0]
stp xzr, xzr, [x0, 8]
b .L31
.L167:
add x6, x27, 8
mov x0, 24
str x6, [sp, 104]
str w2, [sp, 112]
bl malloc
mov x5, x0
ldr w7, [x27, 4]
mov w4, w24
ldr x6, [sp, 104]
mov w24, w19
ldr w2, [sp, 112]
str w7, [x0]
b .L164
.L347:
movi v26.2s, 0x3
b .L7
.L248:
add x6, x25, 12
mov x0, 24
str x6, [sp, 104]
str w3, [sp, 112]
bl malloc
mov x5, x0
ldr w7, [x25, 8]
mov w4, w24
ldr x6, [sp, 104]
mov w24, w19
ldr w3, [sp, 112]
str w7, [x0]
b .L245
.L74:
mov x0, 24
str x3, [sp, 112]
str w4, [sp, 120]
str w2, [sp, 128]
bl malloc
ldr w11, [x26, 12]
mov x6, x0
ldr x3, [sp, 112]
ldr w9, [sp, 120]
ldr w4, [sp, 128]
str w11, [x0]
b .L71
.L300:
add x3, x23, 8
mov x0, 24
str x3, [sp, 104]
mov w25, w20
mov w20, w19
bl malloc
mov x28, x0
ldr w4, [x23, 4]
ldr x3, [sp, 104]
str w4, [x0]
b .L297
.L11:
mov x0, 24
bl malloc
ldr w3, [x26, 4]
mov x23, x0
mov w22, w19
mov w28, 2
str w3, [x0]
b .L16
.L249:
mov w4, w24
mov w24, w19
b .L247
.L168:
mov w4, w24
mov w24, w19
b .L166
.L75:
mov w9, w4
mov w4, w2
b .L73
.L301:
mov w25, w20
mov w20, w19
b .L299
.L302:
add x3, x23, 8
mov x0, 24
str x3, [sp, 104]
mov w25, w19
bl malloc
mov x28, x0
ldr w4, [x23, 4]
ldr x3, [sp, 104]
str w4, [x0]
b .L297
.L76:
mov x0, 24
str x3, [sp, 112]
str w4, [sp, 120]
str w2, [sp, 128]
bl malloc
ldr w11, [x26, 12]
mov x6, x0
ldr x3, [sp, 112]
ldr w9, [sp, 128]
ldr w4, [sp, 120]
str w11, [x0]
b .L71
.L152:
str xzr, [x0, 8]
subs w19, w2, #1
beq .L190
mov x0, 24
bl malloc
mov x24, x0
ldr w2, [x27, 4]
add x3, x27, 8
mov w1, 0
mov x0, x3
mov w27, 1
str w2, [x24]
b .L192
.L250:
add x6, x25, 12
mov x0, 24
str x6, [sp, 104]
str w3, [sp, 112]
bl malloc
mov x5, x0
ldr w7, [x25, 8]
mov w4, w19
ldr x6, [sp, 104]
ldr w3, [sp, 112]
str w7, [x0]
b .L245
.L169:
add x6, x27, 8
mov x0, 24
str x6, [sp, 104]
str w2, [sp, 112]
bl malloc
mov x5, x0
ldr w7, [x27, 4]
mov w4, w19
ldr x6, [sp, 104]
ldr w2, [sp, 112]
str w7, [x0]
b .L164
.L174:
mov w4, w19
b .L166
.L307:
mov w25, w19
b .L299
.L81:
mov w9, w2
b .L73
.L255:
mov w4, w19
b .L247
.L371:
mov w10, w0
b .L100
.L209:
str xzr, [x22, 8]
mov x0, 24
sub w27, w27, #1
bl malloc
mov x26, x0
ldr w3, [x25, 4]
str w3, [x0]
b .L233
.L468:
movi v26.2s, 0x2
b .L208
.L353:
movi v26.2s, 0x2
b .L37
.L396:
mov w11, 1
b .L132
.L39:
mov x0, 24
bl malloc
ldr w1, [x26, 8]
mov w2, w24
str x0, [x23, 8]
mov w19, 2
str w1, [x0]
stp xzr, xzr, [x0, 8]
b .L59
.L27:
mov x0, 24
bl malloc
ldr w3, [x26, 4]
mov w22, w28
mov x23, x0
mov w28, w24
str w3, [x0]
b .L16
.L211:
mov x0, 24
bl malloc
ldr w1, [x25, 4]
mov w27, w20
str x0, [x22, 8]
mov w20, 2
str w1, [x0]
stp xzr, xzr, [x0, 8]
b .L232
.L101:
add x12, x26, 20
mov x0, 24
stp x12, x3, [sp, 112]
str x7, [sp, 128]
str w4, [sp, 136]
str x6, [sp, 144]
str w9, [sp, 152]
stp w8, w2, [sp, 164]
bl malloc
ldr w13, [x26, 16]
mov x11, x0
ldp w10, w8, [sp, 164]
.L627:
ldr x7, [sp, 128]
ldr x6, [sp, 144]
ldp x12, x3, [sp, 112]
ldr w4, [sp, 136]
ldr w9, [sp, 152]
str w13, [x11]
b .L98
.L469:
movi v26.2s, 0x3
b .L208
.L488:
mov w19, w9
b .L264
.L435:
mov w19, w9
b .L183
.L454:
mov w27, w5
b .L195
.L28:
mov w22, w28
mov w28, w24
b .L18
.L354:
movi v26.2s, 0x3
b .L37
.L535:
mov w19, w6
b .L316
.L507:
mov w19, w5
b .L277
.L555:
mov w20, w3
b .L327
.L409:
mov w6, w8
b .L143
.L410:
mov w6, w8
sub w1, w6, #1
b .L140
.L536:
mov w19, w6
sub w1, w19, #1
b .L312
.L556:
mov w20, w3
b .L328
.L508:
mov w19, w5
sub w1, w19, #1
b .L274
.L40:
mov x0, 24
bl malloc
ldr w6, [x26, 8]
mov w24, 2
str x0, [sp, 104]
str w6, [x0]
b .L44
.L394:
mov w3, w1
mov w1, w2
mov w2, w3
b .L130
.L436:
mov w19, w9
sub w1, w19, #1
b .L179
.L212:
mov x0, 24
bl malloc
ldr w5, [x25, 4]
mov x28, x0
mov w20, w19
mov w3, 2
str w5, [x0]
b .L217
.L489:
mov w19, w9
sub w1, w19, #1
b .L260
.L102:
mov w10, w8
mov w8, w2
b .L100
.L455:
mov w27, w5
sub w1, w27, #1
b .L192
.L379:
mov w0, w1
mov w1, w2
mov w2, w0
b .L117
.L494:
mov w19, 1
b .L261
.L441:
mov w19, 1
b .L180
.L541:
mov w19, 1
b .L313
.L103:
add x12, x26, 20
mov x0, 24
stp x12, x3, [sp, 112]
str x7, [sp, 128]
str w4, [sp, 136]
str x6, [sp, 144]
str w9, [sp, 152]
stp w8, w2, [sp, 164]
bl malloc
ldr w13, [x26, 16]
mov x11, x0
ldr x7, [sp, 128]
ldr x6, [sp, 144]
ldr w10, [sp, 168]
ldp x12, x3, [sp, 112]
ldr w4, [sp, 136]
ldr w9, [sp, 152]
ldr w8, [sp, 164]
str w13, [x0]
b .L98
.L108:
mov w10, w2
b .L100
.L360:
movi v26.2s, 0x2
b .L64
.L423:
movi v26.2s, 0x2
b .L156
.L522:
movi v26.2s, 0x2
b .L289
.L476:
movi v26.2s, 0x2
b .L238
.L240:
add x8, x25, 12
mov x0, 24
str x8, [sp, 104]
mov w24, 2
str w3, [sp, 112]
bl malloc
mov x5, x0
ldr x8, [sp, 104]
mov w4, 1
ldr w0, [x25, 8]
mov w19, w4
ldr w3, [sp, 112]
mov x6, x8
mov w1, 0
str w0, [x5]
b .L260
.L477:
movi v26.2s, 0x3
b .L238
.L55:
mov x0, 24
str w7, [sp, 112]
bl malloc
str x0, [sp, 104]
ldr w6, [x26, 8]
mov w19, w24
ldr w24, [sp, 112]
str w6, [x0]
b .L44
.L361:
movi v26.2s, 0x3
b .L64
.L66:
mov x0, 24
str w4, [sp, 112]
bl malloc
ldr w24, [sp, 112]
ldr x2, [sp, 104]
mov w4, 2
ldr w1, [x26, 12]
str w1, [x0]
str x0, [x2, 8]
stp xzr, xzr, [x0, 8]
b .L86
.L228:
mov x0, 24
str w3, [sp, 104]
bl malloc
ldr w20, [sp, 104]
ldr w5, [x25, 4]
mov x28, x0
mov w3, w24
str w5, [x0]
b .L217
.L158:
add x8, x27, 8
mov x0, 24
str x8, [sp, 104]
mov w24, 2
str w2, [sp, 112]
bl malloc
mov x5, x0
ldr x8, [sp, 104]
mov w4, 1
ldr w0, [x27, 4]
mov w19, w4
ldr w2, [sp, 112]
mov x6, x8
mov w1, 0
str w0, [x5]
b .L179
.L424:
movi v26.2s, 0x3
b .L156
.L204:
str xzr, [x0, 8]
subs w19, w27, #1
mov x26, 0
ldp x27, x28, [sp, 80]
bne .L215
str x26, [x22, 16]
b .L677
.L523:
movi v26.2s, 0x3
b .L289
.L291:
add x5, x23, 8
mov x0, 24
str x5, [sp, 104]
mov w25, 1
mov w20, 2
mov w19, w25
bl malloc
mov x28, x0
ldr x5, [sp, 104]
mov w1, 0
ldr w0, [x23, 4]
mov x3, x5
str w0, [x28]
b .L312
.L229:
mov w20, w3
mov w3, w24
b .L219
.L67:
mov x0, 24
str x3, [sp, 112]
str w1, [sp, 120]
bl malloc
ldr w11, [x26, 12]
mov x6, x0
ldr x3, [sp, 112]
mov w9, 2
ldr w4, [sp, 120]
str w11, [x0]
b .L71
.L292:
add x3, x23, 8
mov x0, 24
str x3, [sp, 104]
mov w25, 2
mov w19, 1
bl malloc
mov x28, x0
ldr w4, [x23, 4]
ldr x3, [sp, 104]
str w4, [x0]
b .L313
.L159:
add x6, x27, 8
mov x0, 24
str x6, [sp, 104]
mov w24, w19
str w2, [sp, 112]
mov w19, 1
bl malloc
mov x5, x0
ldr w7, [x27, 4]
mov w4, 2
ldr x6, [sp, 104]
str w7, [x0]
ldr w2, [sp, 112]
b .L180
.L241:
add x6, x25, 12
mov x0, 24
str x6, [sp, 104]
mov w19, 1
str w3, [sp, 112]
bl malloc
mov x5, x0
ldr w7, [x25, 8]
mov w4, 2
ldr x6, [sp, 104]
str w7, [x0]
ldr w3, [sp, 112]
b .L261
.L56:
mov w19, w24
mov w24, w7
b .L46
.L403:
mov w2, w1
mov w1, w6
mov w6, w2
b .L143
.L501:
mov w2, w19
mov w19, w1
mov w1, w2
b .L277
.L381:
mov w15, 1
b .L114
.L529:
mov w0, w19
mov w19, w1
mov w1, w0
b .L316
.L429:
mov w0, w19
mov w19, w1
mov w1, w0
b .L183
.L482:
mov w0, w19
mov w19, w1
mov w1, w0
b .L264
.L448:
mov w2, w27
mov w27, w1
mov w1, w2
b .L195
.L549:
mov w2, w20
mov w20, w1
mov w1, w2
b .L327
.L515:
mov w19, 1
mov x3, x0
sub w1, w19, #1
b .L274
.L462:
mov w27, 1
mov x3, x0
sub w1, w27, #1
b .L192
.L543:
mov w19, 1
mov x5, x3
sub w1, w19, #1
b .L312
.L563:
mov x23, x0
mov w20, 1
b .L328
.L443:
mov w19, 1
mov x8, x6
sub w1, w19, #1
b .L179
.L417:
mov w6, 1
mov x4, x0
sub w1, w6, #1
b .L140
.L496:
mov w19, 1
mov x8, x6
sub w1, w19, #1
b .L260
.L497:
movi v26.2s, 0x2
b .L266
.L664:
mov w19, 2
add x8, x25, 16
sub w1, w19, #1
b .L260
.L463:
movi v26.2s, 0x2
b .L198
.L93:
add x14, x26, 20
mov x0, 24
stp x14, x3, [sp, 112]
str w4, [sp, 128]
str x6, [sp, 136]
str w9, [sp, 144]
bl malloc
ldp x14, x3, [sp, 112]
mov x11, x0
ldr w0, [x26, 16]
mov w10, 1
ldr x6, [sp, 136]
mov w2, w10
ldr w4, [sp, 128]
mov w8, 2
ldr w9, [sp, 144]
mov x12, x14
mov w1, 0
str w0, [x11]
b .L113
.L444:
movi v26.2s, 0x2
b .L185
.L418:
movi v26.2s, 0x2
b .L146
.L670:
mov w19, 2
add x5, x23, 12
sub w1, w19, #1
b .L312
.L544:
movi v26.2s, 0x2
b .L318
.L367:
movi v26.2s, 0x2
b .L91
.L516:
movi v26.2s, 0x2
b .L280
.L673:
add x23, x24, 8
mov w20, 2
b .L328
.L564:
movi v26.2s, 0x2
b .L330
.L654:
mov w19, 2
add x8, x27, 12
sub w1, w19, #1
b .L179
.L309:
mov w20, w25
mov w25, w5
b .L299
.L308:
add x3, x23, 8
mov x0, 24
str x3, [sp, 104]
mov w20, w25
str w5, [sp, 112]
bl malloc
ldr w25, [sp, 112]
ldr w4, [x23, 4]
mov x28, x0
ldr x3, [sp, 104]
str w4, [x0]
b .L297
.L517:
movi v26.2s, 0x3
b .L280
.L445:
movi v26.2s, 0x3
b .L185
.L176:
mov w24, w4
mov w4, w8
b .L166
.L285:
str xzr, [x0, 8]
subs w19, w27, #1
mov x25, 0
ldp x27, x28, [sp, 80]
bne .L295
str x25, [x26, 16]
b .L214
.L256:
add x6, x25, 12
mov x0, 24
str x6, [sp, 104]
str w3, [sp, 112]
str w4, [sp, 120]
str w8, [sp, 128]
bl malloc
ldr w7, [x25, 8]
mov x5, x0
ldr x6, [sp, 104]
ldr w24, [sp, 120]
ldr w4, [sp, 128]
ldr w3, [sp, 112]
str w7, [x0]
b .L245
.L419:
movi v26.2s, 0x3
b .L146
.L553:
mov w20, w1
mov w1, w3
b .L327
.L505:
mov w19, w1
mov w1, w5
b .L277
.L257:
mov w24, w4
mov w4, w8
b .L247
.L175:
add x6, x27, 8
mov x0, 24
str x6, [sp, 104]
str w2, [sp, 112]
str w4, [sp, 120]
str w8, [sp, 128]
bl malloc
ldr w7, [x27, 4]
mov x5, x0
ldr x6, [sp, 104]
ldr w24, [sp, 120]
ldr w4, [sp, 128]
ldr w2, [sp, 112]
str w7, [x0]
b .L164
.L545:
movi v26.2s, 0x3
b .L318
.L83:
mov w4, w9
mov w9, w8
b .L73
.L82:
mov x0, 24
str x3, [sp, 112]
str w9, [sp, 120]
str w8, [sp, 128]
bl malloc
ldr w11, [x26, 12]
mov x6, x0
ldr x3, [sp, 112]
ldr w4, [sp, 120]
ldr w9, [sp, 128]
str w11, [x0]
b .L71
.L486:
mov w19, w1
mov w1, w9
b .L264
.L368:
movi v26.2s, 0x3
b .L91
.L464:
movi v26.2s, 0x3
b .L198
.L565:
movi v26.2s, 0x3
b .L330
.L407:
mov w6, w1
mov w1, w8
b .L143
.L533:
mov w19, w1
mov w1, w6
b .L316
.L498:
movi v26.2s, 0x3
b .L266
.L433:
mov w19, w1
mov w1, w9
b .L183
.L452:
mov w27, w1
mov w1, w5
b .L195
.L94:
add x12, x26, 20
mov x0, 24
stp x12, x3, [sp, 112]
str x7, [sp, 128]
str w4, [sp, 136]
str x6, [sp, 144]
str w2, [sp, 152]
str w9, [sp, 164]
bl malloc
ldr w13, [x26, 16]
mov x11, x0
ldr x7, [sp, 128]
mov w10, 2
ldr x6, [sp, 144]
mov w15, 1
ldr w8, [sp, 152]
ldp x12, x3, [sp, 112]
str w13, [x0]
ldr w4, [sp, 136]
ldr w9, [sp, 164]
b .L114
.L374:
mov w1, w15
b .L117
.L373:
mov w2, w15
sub w1, w2, #1
b .L113
.L389:
mov w1, w11
b .L130
.L388:
mov w2, w11
sub w1, w2, #1
b .L127
.L437:
mov w1, w9
mov w19, w10
b .L183
.L399:
movi v26.2s, 0x2
b .L133
.L537:
mov w1, w6
mov w19, w7
b .L316
.L509:
mov w1, w5
mov w19, w6
b .L277
.L411:
mov w6, w9
mov w1, w8
b .L143
.L557:
mov w1, w3
mov w20, w5
b .L327
.L384:
movi v26.2s, 0x2
b .L119
.L490:
mov w1, w9
mov w19, w10
b .L264
.L398:
mov w2, 1
mov x12, x0
sub w1, w2, #1
b .L127
.L383:
mov w2, 1
mov x14, x12
sub w1, w2, #1
b .L113
.L456:
mov w1, w5
mov w27, w6
b .L195
.L458:
mov w27, w1
mov w1, w6
b .L195
.L457:
mov w27, w6
sub w1, w27, #1
b .L192
.L110:
mov w8, w10
mov w10, w14
b .L100
.L439:
mov w19, w1
mov w1, w10
b .L183
.L438:
mov w19, w10
sub w1, w19, #1
b .L179
.L648:
mov w2, 2
add x12, x7, 8
sub w1, w2, #1
b .L127
.L538:
mov w19, w7
sub w1, w19, #1
b .L312
.L539:
mov w19, w1
mov w1, w7
b .L316
.L400:
movi v26.2s, 0x3
b .L133
.L109:
add x12, x26, 20
mov x0, 24
stp x12, x3, [sp, 112]
str x7, [sp, 128]
str w4, [sp, 136]
str x6, [sp, 144]
str w9, [sp, 152]
stp w10, w14, [sp, 164]
bl malloc
ldr w13, [x26, 16]
mov x11, x0
ldp w8, w10, [sp, 164]
b .L627
.L511:
mov w19, w1
mov w1, w6
b .L277
.L510:
mov w19, w6
sub w1, w19, #1
b .L274
.L559:
mov w20, w1
mov w1, w5
b .L327
.L412:
mov w6, w9
sub w1, w6, #1
b .L140
.L492:
mov w19, w1
mov w1, w10
b .L264
.L491:
mov w19, w10
sub w1, w19, #1
b .L260
.L558:
mov w20, w5
b .L328
.L646:
mov w2, 2
add x14, x26, 24
sub w1, w2, #1
b .L113
.L385:
movi v26.2s, 0x3
b .L119
.L413:
mov w6, w1
mov w1, w9
b .L143
.L656:
mov x3, x0
mov w1, 0
mov w27, 1
b .L192
.L672:
ldp x27, x28, [sp, 80]
mov x23, x0
mov w1, 0
mov w20, 1
b .L324
.LC0:
.word 0
.word 1
.word 2
.word 3
|
13,988
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O0
|
armv8-a clang 21.1.0
|
bstFromPreorder:
sub sp, sp, #64
stp x29, x30, [sp, #48]
add x29, sp, #48
stur x0, [x29, #-16]
stur w1, [x29, #-20]
ldur w8, [x29, #-20]
cbnz w8, .LBB0_2
b .LBB0_1
.LBB0_1:
stur xzr, [x29, #-8]
b .LBB0_8
.LBB0_2:
mov x0, #24
bl malloc
str x0, [sp, #16]
ldur x8, [x29, #-16]
ldr w8, [x8]
ldr x9, [sp, #16]
str w8, [x9]
mov w8, #1
str w8, [sp, #12]
b .LBB0_3
.LBB0_3:
ldr w9, [sp, #12]
ldur w10, [x29, #-20]
mov w8, #0
subs w9, w9, w10
str w8, [sp, #8]
b.ge .LBB0_5
b .LBB0_4
.LBB0_4:
ldur x8, [x29, #-16]
ldrsw x9, [sp, #12]
ldr w8, [x8, x9, lsl #2]
ldr x9, [sp, #16]
ldr w9, [x9]
subs w8, w8, w9
cset w8, lt
str w8, [sp, #8]
b .LBB0_5
.LBB0_5:
ldr w8, [sp, #8]
tbz w8, #0, .LBB0_7
b .LBB0_6
.LBB0_6:
ldr w8, [sp, #12]
add w8, w8, #1
str w8, [sp, #12]
b .LBB0_3
.LBB0_7:
ldur x8, [x29, #-16]
add x0, x8, #4
ldr w8, [sp, #12]
subs w1, w8, #1
bl bstFromPreorder
ldr x8, [sp, #16]
str x0, [x8, #8]
ldur x8, [x29, #-16]
ldrsw x9, [sp, #12]
add x0, x8, x9, lsl #2
ldur w8, [x29, #-20]
ldr w9, [sp, #12]
subs w1, w8, w9
bl bstFromPreorder
ldr x8, [sp, #16]
str x0, [x8, #16]
ldr x8, [sp, #16]
stur x8, [x29, #-8]
b .LBB0_8
.LBB0_8:
ldur x0, [x29, #-8]
ldp x29, x30, [sp, #48]
add sp, sp, #64
ret
|
13,989
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O1
|
armv8-a clang 21.1.0
|
bstFromPreorder:
stp x29, x30, [sp, #-48]!
stp x22, x21, [sp, #16]
stp x20, x19, [sp, #32]
mov x29, sp
cbz w1, .LBB0_6
mov x21, x0
mov w0, #24
mov w20, w1
bl malloc
ldr w8, [x21]
mov x19, x0
cmp w20, #2
str w8, [x0]
b.lt .LBB0_7
mov w9, w20
mov w22, #1
.LBB0_3:
ldr w10, [x21, x22, lsl #2]
cmp w10, w8
b.ge .LBB0_8
add x22, x22, #1
cmp x9, x22
b.ne .LBB0_3
mov w22, w9
b .LBB0_8
.LBB0_6:
mov x19, xzr
b .LBB0_9
.LBB0_7:
mov w22, #1
.LBB0_8:
sub w1, w22, #1
add x0, x21, #4
bl bstFromPreorder
add x8, x21, w22, uxtw #2
str x0, [x19, #8]
sub w1, w20, w22
mov x0, x8
bl bstFromPreorder
str x0, [x19, #16]
.LBB0_9:
mov x0, x19
ldp x20, x19, [sp, #32]
ldp x22, x21, [sp, #16]
ldp x29, x30, [sp], #48
ret
|
13,990
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O2
|
armv8-a clang 21.1.0
|
bstFromPreorder:
stp x29, x30, [sp, #-48]!
stp x22, x21, [sp, #16]
stp x20, x19, [sp, #32]
mov x29, sp
cbz w1, .LBB0_6
mov x21, x0
mov w0, #24
mov w20, w1
bl malloc
ldr w8, [x21]
mov x19, x0
cmp w20, #2
str w8, [x0]
b.lt .LBB0_7
mov w9, w20
mov w22, #1
.LBB0_3:
ldr w10, [x21, x22, lsl #2]
cmp w10, w8
b.ge .LBB0_8
add x22, x22, #1
cmp x9, x22
b.ne .LBB0_3
mov w22, w9
b .LBB0_8
.LBB0_6:
mov x19, xzr
b .LBB0_9
.LBB0_7:
mov w22, #1
.LBB0_8:
sub w1, w22, #1
add x0, x21, #4
bl bstFromPreorder
add x8, x21, w22, uxtw #2
str x0, [x19, #8]
sub w1, w20, w22
mov x0, x8
bl bstFromPreorder
str x0, [x19, #16]
.LBB0_9:
mov x0, x19
ldp x20, x19, [sp, #32]
ldp x22, x21, [sp, #16]
ldp x29, x30, [sp], #48
ret
|
13,991
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
aarch64
|
-O3
|
armv8-a clang 21.1.0
|
bstFromPreorder:
stp x29, x30, [sp, #-48]!
stp x22, x21, [sp, #16]
stp x20, x19, [sp, #32]
mov x29, sp
cbz w1, .LBB0_6
mov x21, x0
mov w0, #24
mov w20, w1
bl malloc
ldr w8, [x21]
mov x19, x0
cmp w20, #2
str w8, [x0]
b.lt .LBB0_7
mov w9, w20
mov w22, #1
.LBB0_3:
ldr w10, [x21, x22, lsl #2]
cmp w10, w8
b.ge .LBB0_8
add x22, x22, #1
cmp x9, x22
b.ne .LBB0_3
mov w22, w9
b .LBB0_8
.LBB0_6:
mov x19, xzr
mov x0, x19
ldp x20, x19, [sp, #32]
ldp x22, x21, [sp, #16]
ldp x29, x30, [sp], #48
ret
.LBB0_7:
mov w22, #1
.LBB0_8:
sub w1, w22, #1
add x0, x21, #4
bl bstFromPreorder
add x8, x21, w22, uxtw #2
str x0, [x19, #8]
sub w1, w20, w22
mov x0, x8
bl bstFromPreorder
str x0, [x19, #16]
mov x0, x19
ldp x20, x19, [sp, #32]
ldp x22, x21, [sp, #16]
ldp x29, x30, [sp], #48
ret
|
13,992
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O0
|
mips64 clang 21.1.0
|
bstFromPreorder:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -80
sd $ra, 72($sp)
sd $fp, 64($sp)
sd $gp, 56($sp)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(bstFromPreorder)))
daddu $1, $1, $25
daddiu $1, $1, %lo(%neg(%gp_rel(bstFromPreorder)))
sd $1, 8($fp)
move $1, $5
sd $4, 40($fp)
sw $1, 36($fp)
lw $1, 36($fp)
bnez $1, .LBB0_3
nop
b .LBB0_2
nop
.LBB0_2:
daddiu $1, $zero, 0
sd $zero, 48($fp)
b .LBB0_11
nop
.LBB0_3:
ld $gp, 8($fp)
ld $25, %call16(malloc)($gp)
daddiu $4, $zero, 24
jalr $25
nop
sd $2, 24($fp)
ld $1, 40($fp)
lw $1, 0($1)
ld $2, 24($fp)
sw $1, 0($2)
addiu $1, $zero, 1
sw $1, 20($fp)
b .LBB0_4
nop
.LBB0_4:
lw $1, 20($fp)
lw $3, 36($fp)
addiu $2, $zero, 0
slt $1, $1, $3
sw $2, 4($fp)
beqz $1, .LBB0_7
nop
b .LBB0_6
nop
.LBB0_6:
ld $1, 40($fp)
lw $2, 20($fp)
dsll $2, $2, 2
daddu $1, $1, $2
lw $1, 0($1)
ld $2, 24($fp)
lw $2, 0($2)
slt $1, $1, $2
sw $1, 4($fp)
b .LBB0_7
nop
.LBB0_7:
lw $1, 4($fp)
andi $1, $1, 1
beqz $1, .LBB0_10
nop
b .LBB0_9
nop
.LBB0_9:
lw $1, 20($fp)
addiu $1, $1, 1
sw $1, 20($fp)
b .LBB0_4
nop
.LBB0_10:
ld $gp, 8($fp)
ld $1, 40($fp)
daddiu $4, $1, 4
lw $1, 20($fp)
addiu $1, $1, -1
move $5, $1
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
nop
ld $gp, 8($fp)
ld $1, 24($fp)
sd $2, 8($1)
ld $1, 40($fp)
lw $2, 20($fp)
sll $3, $2, 0
dsll $3, $3, 2
daddu $4, $1, $3
lw $1, 36($fp)
subu $1, $1, $2
move $5, $1
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
nop
ld $1, 24($fp)
sd $2, 16($1)
ld $1, 24($fp)
sd $1, 48($fp)
b .LBB0_11
nop
.LBB0_11:
ld $2, 48($fp)
move $sp, $fp
ld $gp, 56($sp)
ld $fp, 64($sp)
ld $ra, 72($sp)
daddiu $sp, $sp, 80
jr $ra
nop
|
13,993
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O1
|
mips64 clang 21.1.0
|
bstFromPreorder:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -64
sd $ra, 56($sp)
sd $fp, 48($sp)
sd $gp, 40($sp)
sd $19, 32($sp)
sd $18, 24($sp)
sd $17, 16($sp)
sd $16, 8($sp)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(bstFromPreorder)))
move $18, $5
beqz $18, .LBB0_7
daddu $2, $1, $25
move $17, $4
daddiu $gp, $2, %lo(%neg(%gp_rel(bstFromPreorder)))
ld $25, %call16(malloc)($gp)
jalr $25
daddiu $4, $zero, 24
move $16, $2
lw $2, 0($17)
sw $2, 0($16)
slti $1, $18, 2
addiu $19, $zero, 1
bnez $1, .LBB0_6
daddiu $4, $17, 4
sll $1, $18, 0
daddiu $3, $1, -1
addiu $19, $zero, 1
move $5, $4
.LBB0_3:
lw $1, 0($5)
slt $1, $1, $2
beqz $1, .LBB0_6
nop
daddiu $3, $3, -1
daddiu $5, $5, 4
bnez $3, .LBB0_3
addiu $19, $19, 1
move $19, $18
.LBB0_6:
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
addiu $5, $19, -1
sd $2, 8($16)
subu $5, $18, $19
sll $1, $19, 0
dsll $1, $1, 2
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
daddu $4, $17, $1
b .LBB0_8
sd $2, 16($16)
.LBB0_7:
daddiu $16, $zero, 0
.LBB0_8:
move $2, $16
move $sp, $fp
ld $16, 8($sp)
ld $17, 16($sp)
ld $18, 24($sp)
ld $19, 32($sp)
ld $gp, 40($sp)
ld $fp, 48($sp)
ld $ra, 56($sp)
jr $ra
daddiu $sp, $sp, 64
|
13,994
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O2
|
mips64 clang 21.1.0
|
bstFromPreorder:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -64
sd $ra, 56($sp)
sd $fp, 48($sp)
sd $gp, 40($sp)
sd $19, 32($sp)
sd $18, 24($sp)
sd $17, 16($sp)
sd $16, 8($sp)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(bstFromPreorder)))
move $18, $5
beqz $18, .LBB0_7
daddu $2, $1, $25
move $17, $4
daddiu $gp, $2, %lo(%neg(%gp_rel(bstFromPreorder)))
ld $25, %call16(malloc)($gp)
jalr $25
daddiu $4, $zero, 24
move $16, $2
lw $2, 0($17)
sw $2, 0($16)
slti $1, $18, 2
addiu $19, $zero, 1
bnez $1, .LBB0_6
daddiu $4, $17, 4
sll $1, $18, 0
daddiu $3, $1, -1
addiu $19, $zero, 1
move $5, $4
.LBB0_3:
lw $1, 0($5)
slt $1, $1, $2
beqz $1, .LBB0_6
nop
daddiu $3, $3, -1
daddiu $5, $5, 4
bnez $3, .LBB0_3
addiu $19, $19, 1
move $19, $18
.LBB0_6:
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
addiu $5, $19, -1
sd $2, 8($16)
subu $5, $18, $19
sll $1, $19, 0
dsll $1, $1, 2
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
daddu $4, $17, $1
b .LBB0_8
sd $2, 16($16)
.LBB0_7:
daddiu $16, $zero, 0
.LBB0_8:
move $2, $16
move $sp, $fp
ld $16, 8($sp)
ld $17, 16($sp)
ld $18, 24($sp)
ld $19, 32($sp)
ld $gp, 40($sp)
ld $fp, 48($sp)
ld $ra, 56($sp)
jr $ra
daddiu $sp, $sp, 64
|
13,995
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O3
|
mips64 clang 21.1.0
|
bstFromPreorder:
.Lfunc_begin0 = .Ltmp0
daddiu $sp, $sp, -64
sd $ra, 56($sp)
sd $fp, 48($sp)
sd $gp, 40($sp)
sd $19, 32($sp)
sd $18, 24($sp)
sd $17, 16($sp)
sd $16, 8($sp)
move $fp, $sp
lui $1, %hi(%neg(%gp_rel(bstFromPreorder)))
move $18, $5
beqz $18, .LBB0_7
daddu $2, $1, $25
daddiu $gp, $2, %lo(%neg(%gp_rel(bstFromPreorder)))
move $17, $4
ld $25, %call16(malloc)($gp)
jalr $25
daddiu $4, $zero, 24
move $16, $2
lw $2, 0($17)
slti $1, $18, 2
addiu $19, $zero, 1
daddiu $4, $17, 4
bnez $1, .LBB0_6
sw $2, 0($16)
sll $1, $18, 0
addiu $19, $zero, 1
move $5, $4
daddiu $3, $1, -1
.LBB0_3:
lw $1, 0($5)
slt $1, $1, $2
beqz $1, .LBB0_6
nop
daddiu $3, $3, -1
daddiu $5, $5, 4
bnez $3, .LBB0_3
addiu $19, $19, 1
move $19, $18
.LBB0_6:
ld $25, %call16(bstFromPreorder)($gp)
jalr $25
addiu $5, $19, -1
sll $1, $19, 0
ld $25, %call16(bstFromPreorder)($gp)
subu $5, $18, $19
sd $2, 8($16)
dsll $1, $1, 2
jalr $25
daddu $4, $17, $1
b .LBB0_8
sd $2, 16($16)
.LBB0_7:
daddiu $16, $zero, 0
.LBB0_8:
move $2, $16
move $sp, $fp
ld $16, 8($sp)
ld $17, 16($sp)
ld $18, 24($sp)
ld $19, 32($sp)
ld $gp, 40($sp)
ld $fp, 48($sp)
ld $ra, 56($sp)
jr $ra
daddiu $sp, $sp, 64
|
13,996
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O0
|
mips64 gcc 15.2.0
|
bstFromPreorder:
daddiu $sp,$sp,-64
sd $31,56($sp)
sd $fp,48($sp)
sd $28,40($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(bstFromPreorder)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(bstFromPreorder)))
sd $4,16($fp)
move $2,$5
sll $2,$2,0
sw $2,24($fp)
lw $2,24($fp)
bne $2,$0,.L2
nop
move $2,$0
b .L3
nop
.L2:
li $4,24 # 0x18
ld $2,%call16(malloc)($28)
mtlo $2
mflo $25
jalr $25
nop
sd $2,8($fp)
ld $2,16($fp)
lw $3,0($2)
ld $2,8($fp)
sw $3,0($2)
li $2,1 # 0x1
sw $2,0($fp)
b .L4
nop
.L6:
lw $2,0($fp)
addiu $2,$2,1
sw $2,0($fp)
.L4:
lw $3,0($fp)
lw $2,24($fp)
slt $2,$3,$2
beq $2,$0,.L5
nop
lw $2,0($fp)
dsll $2,$2,2
ld $3,16($fp)
daddu $2,$3,$2
lw $3,0($2)
ld $2,8($fp)
lw $2,0($2)
slt $2,$3,$2
bne $2,$0,.L6
nop
.L5:
ld $2,16($fp)
daddiu $3,$2,4
lw $2,0($fp)
addiu $2,$2,-1
move $5,$2
move $4,$3
ld $2,%got_disp(bstFromPreorder)($28)
mtlo $2
mflo $25
jalr $25
nop
move $3,$2
ld $2,8($fp)
sd $3,8($2)
lw $2,0($fp)
dsll $2,$2,2
ld $3,16($fp)
daddu $4,$3,$2
lw $3,24($fp)
lw $2,0($fp)
subu $2,$3,$2
move $5,$2
ld $2,%got_disp(bstFromPreorder)($28)
mtlo $2
mflo $25
jalr $25
nop
move $3,$2
ld $2,8($fp)
sd $3,16($2)
ld $2,8($fp)
.L3:
move $sp,$fp
ld $31,56($sp)
ld $fp,48($sp)
ld $28,40($sp)
daddiu $sp,$sp,64
jr $31
nop
|
13,997
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O1
|
mips64 gcc 15.2.0
|
bstFromPreorder:
daddiu $sp,$sp,-64
sd $31,56($sp)
sd $28,48($sp)
sd $19,40($sp)
sd $18,32($sp)
sd $17,24($sp)
sd $16,16($sp)
lui $28,%hi(%neg(%gp_rel(bstFromPreorder)))
daddu $28,$28,$25
beq $5,$0,.L6
daddiu $28,$28,%lo(%neg(%gp_rel(bstFromPreorder)))
move $18,$4
move $17,$5
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
move $19,$2
lw $5,0($18)
sw $5,0($2)
slt $2,$17,2
bne $2,$0,.L7
daddiu $6,$18,4
li $16,1 # 0x1
.L4:
lw $3,0($6)
slt $3,$3,$5
beql $3,$0,.L10
addiu $5,$16,-1
addiu $16,$16,1
bne $17,$16,.L4
daddiu $6,$6,4
move $16,$17
.L3:
addiu $5,$16,-1
.L10:
daddiu $4,$18,4
ld $25,%got_disp(bstFromPreorder)($28)
1: jalr $25
sd $25,0($sp)
sd $2,8($19)
dsll $4,$16,2
subu $5,$17,$16
ld $25,0($sp)
jalr $25
daddu $4,$18,$4
sd $2,16($19)
.L1:
move $2,$19
ld $31,56($sp)
ld $28,48($sp)
ld $19,40($sp)
ld $18,32($sp)
ld $17,24($sp)
ld $16,16($sp)
jr $31
daddiu $sp,$sp,64
.L7:
b .L3
li $16,1 # 0x1
.L6:
b .L1
move $19,$0
|
13,998
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O2
|
mips64 gcc 15.2.0
|
bstFromPreorder:
daddiu $sp,$sp,-64
sd $28,48($sp)
lui $28,%hi(%neg(%gp_rel(bstFromPreorder)))
daddu $28,$28,$25
sd $31,56($sp)
sd $19,40($sp)
sd $18,32($sp)
sd $17,24($sp)
sd $16,16($sp)
beq $5,$0,.L7
daddiu $28,$28,%lo(%neg(%gp_rel(bstFromPreorder)))
ld $25,%call16(malloc)($28)
move $18,$4
li $4,24 # 0x18
1: jalr $25
move $19,$5
lw $5,0($18)
move $17,$2
daddiu $4,$18,4
slt $2,$19,2
sw $5,0($17)
move $3,$4
beq $2,$0,.L5
li $16,1 # 0x1
b .L12
move $5,$0
.L6:
beq $19,$7,.L13
daddiu $3,$3,4
addiu $16,$16,1
.L5:
lw $6,0($3)
slt $6,$6,$5
bne $6,$0,.L6
addiu $7,$16,1
addiu $5,$16,-1
.L4:
ld $25,%got_disp(bstFromPreorder)($28)
.L14:
1: jalr $25
sd $3,0($sp)
ld $4,0($sp)
ld $25,%got_disp(bstFromPreorder)($28)
subu $5,$19,$16
1: jalr $25
sd $2,8($17)
ld $31,56($sp)
sd $2,16($17)
ld $28,48($sp)
ld $19,40($sp)
ld $18,32($sp)
ld $16,16($sp)
move $2,$17
ld $17,24($sp)
jr $31
daddiu $sp,$sp,64
.L13:
dsll $7,$7,32
dsrl $7,$7,32
dsll $7,$7,2
move $5,$16
daddu $3,$18,$7
b .L4
addiu $16,$16,1
.L7:
ld $31,56($sp)
move $17,$0
ld $28,48($sp)
ld $19,40($sp)
ld $18,32($sp)
ld $16,16($sp)
move $2,$17
ld $17,24($sp)
jr $31
daddiu $sp,$sp,64
.L12:
b .L14
ld $25,%got_disp(bstFromPreorder)($28)
|
13,999
| 1,008
|
Construct Binary Search Tree from Preorder Traversal
|
Medium
|
/*
1008. Construct Binary Search Tree from Preorder Traversal
Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Example 1:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Note:
1 <= preorder.length <= 100
The values of preorder are distinct.
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
struct TreeNode *node;
int mid;
if (preorderSize == 0) return NULL;
node = malloc(sizeof(struct TreeNode));
//assert(node);
node->val = preorder[0];
mid = 1;
while (mid < preorderSize && preorder[mid] < node->val) {
mid ++;
}
node->left = bstFromPreorder(&preorder[1], mid - 1);
node->right = bstFromPreorder(&preorder[mid], preorderSize - mid);
return node;
}
/*
Difficulty:Medium
*/
|
mips64
|
-O3
|
mips64 gcc 15.2.0
|
bstFromPreorder:
daddiu $sp,$sp,-208
sd $28,184($sp)
lui $28,%hi(%neg(%gp_rel(bstFromPreorder)))
daddu $28,$28,$25
sd $31,200($sp)
sd $fp,192($sp)
sd $23,176($sp)
sd $22,168($sp)
sd $21,160($sp)
sd $20,152($sp)
sd $19,144($sp)
sd $18,136($sp)
sd $17,128($sp)
sd $16,120($sp)
beq $5,$0,.L119
daddiu $28,$28,%lo(%neg(%gp_rel(bstFromPreorder)))
ld $25,%call16(malloc)($28)
move $17,$4
li $4,24 # 0x18
1: jalr $25
move $16,$5
lw $5,0($17)
move $18,$2
slt $2,$16,2
sw $5,0($18)
bne $2,$0,.L3
daddiu $20,$17,4
move $3,$20
b .L4
li $fp,1 # 0x1
.L8:
beql $16,$4,.L120
sd $16,16($sp)
addiu $fp,$fp,1
.L4:
lw $2,0($3)
addiu $4,$fp,1
slt $2,$2,$5
bne $2,$0,.L8
daddiu $3,$3,4
addiu $2,$fp,-1
bne $2,$0,.L154
addiu $21,$16,-1
sd $0,8($18)
.L108:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $5,0($20)
move $17,$2
slt $2,$21,2
bne $2,$0,.L63
sw $5,0($17)
daddiu $2,$20,4
sd $2,8($sp)
move $3,$2
li $fp,1 # 0x1
b .L64
move $6,$21
.L68:
beq $6,$4,.L67
move $16,$fp
addiu $fp,$fp,1
.L64:
lw $2,0($3)
addiu $4,$fp,1
slt $2,$2,$5
bne $2,$0,.L68
daddiu $3,$3,4
addiu $16,$fp,-1
bne $16,$0,.L115
ld $22,8($sp)
sd $0,8($17)
addiu $23,$21,-1
.L106:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $5,0($22)
move $16,$2
slt $2,$23,2
bne $2,$0,.L88
sw $5,0($16)
daddiu $19,$22,4
move $3,$19
li $20,1 # 0x1
b .L89
move $7,$23
.L93:
beq $7,$4,.L92
move $21,$20
addiu $20,$20,1
.L89:
lw $2,0($3)
addiu $4,$20,1
slt $2,$2,$5
bne $2,$0,.L93
daddiu $3,$3,4
addiu $21,$20,-1
bne $21,$0,.L113
move $fp,$19
ld $19,%got_disp(bstFromPreorder)($28)
sd $0,8($16)
addiu $21,$23,-1
.L105:
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
li $23,1 # 0x1
lw $5,0($fp)
move $20,$2
daddiu $4,$fp,4
slt $2,$21,2
sw $5,0($20)
move $22,$4
beq $2,$0,.L103
move $6,$21
b .L155
move $5,$0
.L104:
beq $6,$3,.L156
daddiu $22,$22,4
addiu $23,$23,1
.L103:
lw $2,0($22)
slt $2,$2,$5
bne $2,$0,.L104
addiu $3,$23,1
addiu $5,$23,-1
.L102:
move $25,$19
.L175:
1: jalr $25
nop
sd $2,8($20)
subu $5,$21,$23
move $25,$19
1: jalr $25
move $4,$22
sd $2,16($20)
sd $20,16($16)
.L87:
sd $16,16($17)
.L6:
sd $17,16($18)
.L168:
ld $31,200($sp)
ld $fp,192($sp)
ld $28,184($sp)
ld $23,176($sp)
ld $22,168($sp)
ld $21,160($sp)
ld $20,152($sp)
ld $19,144($sp)
ld $17,128($sp)
ld $16,120($sp)
move $2,$18
ld $18,136($sp)
jr $31
daddiu $sp,$sp,208
.L120:
.L7:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $6,4($17)
move $21,$2
li $2,1 # 0x1
beq $fp,$2,.L10
sw $6,0($21)
daddiu $2,$17,8
sd $2,24($sp)
move $4,$2
li $22,1 # 0x1
b .L11
move $7,$fp
.L14:
beql $7,$5,.L13
sd $22,0($sp)
addiu $22,$22,1
.L11:
lw $2,0($4)
addiu $5,$22,1
slt $2,$2,$6
bne $2,$0,.L14
daddiu $4,$4,4
ld $3,24($sp)
addiu $2,$22,-1
sd $2,0($sp)
bne $2,$0,.L118
sd $3,8($sp)
ld $2,16($sp)
sd $0,8($21)
addiu $23,$2,-2
.L110:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
ld $3,8($sp)
move $20,$2
slt $2,$23,2
lw $6,0($3)
bne $2,$0,.L46
sw $6,0($20)
daddiu $2,$3,4
sd $2,0($sp)
move $4,$2
li $22,1 # 0x1
b .L47
move $7,$23
.L51:
beql $7,$5,.L50
sd $23,40($sp)
addiu $22,$22,1
.L47:
lw $2,0($4)
addiu $5,$22,1
slt $2,$2,$6
bne $2,$0,.L51
daddiu $4,$4,4
addiu $2,$22,-1
beql $2,$0,.L52
addiu $2,$23,-1
sd $22,40($sp)
move $22,$2
.L50:
ld $19,8($sp)
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
daddiu $fp,$19,8
1: jalr $25
sd $fp,32($sp)
lw $7,4($19)
move $3,$2
sd $2,24($sp)
li $2,1 # 0x1
sw $7,0($3)
li $6,1 # 0x1
bne $22,$2,.L55
move $8,$22
b .L157
ld $fp,32($sp)
.L56:
beq $8,$5,.L158
daddiu $fp,$fp,4
addiu $6,$6,1
.L55:
lw $2,0($fp)
slt $2,$2,$7
bne $2,$0,.L56
addiu $5,$6,1
addiu $5,$6,-1
.L54:
ld $19,%got_disp(bstFromPreorder)($28)
ld $4,32($sp)
move $25,$19
1: jalr $25
sd $6,0($sp)
ld $3,24($sp)
ld $6,0($sp)
move $4,$fp
sd $2,8($3)
move $25,$19
1: jalr $25
subu $5,$22,$6
ld $3,24($sp)
sd $2,16($3)
ld $2,40($sp)
sd $3,8($20)
subu $3,$23,$2
beq $23,$2,.L57
sd $3,24($sp)
ld $3,8($sp)
dsll $2,$2,32
dsrl $2,$2,32
dsll $2,$2,2
daddu $2,$3,$2
sd $2,0($sp)
.L109:
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
li $22,1 # 0x1
ld $3,0($sp)
move $23,$2
ld $2,24($sp)
lw $7,0($3)
daddiu $4,$3,4
slt $3,$2,2
sw $7,0($23)
move $fp,$4
move $8,$2
beq $3,$0,.L60
move $5,$0
b .L171
move $25,$19
.L61:
beq $8,$5,.L159
daddiu $fp,$fp,4
addiu $22,$22,1
.L60:
lw $3,0($fp)
slt $3,$3,$7
bne $3,$0,.L61
addiu $5,$22,1
addiu $5,$22,-1
.L59:
move $25,$19
.L171:
1: jalr $25
nop
sd $2,8($23)
ld $2,24($sp)
move $4,$fp
move $25,$19
1: jalr $25
subu $5,$2,$22
sd $2,16($23)
.L49:
sd $23,16($20)
.L45:
ld $2,16($sp)
sd $20,16($21)
sd $21,8($18)
beq $16,$2,.L62
subu $21,$16,$2
dsll $20,$2,32
dsrl $20,$20,32
dsll $20,$20,2
b .L108
daddu $20,$17,$20
.L13:
move $22,$fp
.L118:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $7,8($17)
move $3,$2
sd $2,8($sp)
sw $7,0($3)
ld $3,0($sp)
li $2,1 # 0x1
beq $3,$2,.L16
daddiu $2,$17,12
sd $2,56($sp)
move $4,$2
li $23,1 # 0x1
b .L17
move $8,$3
.L20:
beql $8,$5,.L19
sd $23,32($sp)
addiu $23,$23,1
.L17:
lw $2,0($4)
addiu $5,$23,1
slt $2,$2,$7
bne $2,$0,.L20
daddiu $4,$4,4
addiu $2,$23,-1
ld $19,56($sp)
bne $2,$0,.L117
sd $2,32($sp)
ld $2,8($sp)
sd $0,8($2)
addiu $2,$22,-2
sd $2,0($sp)
.L111:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
move $23,$2
ld $2,0($sp)
lw $9,0($19)
daddiu $4,$19,4
slt $5,$2,2
sw $9,0($23)
move $6,$4
li $7,1 # 0x1
beq $5,$0,.L42
move $10,$2
b .L160
move $5,$0
.L43:
beq $10,$8,.L161
daddiu $6,$6,4
addiu $7,$7,1
.L42:
lw $5,0($6)
slt $5,$5,$9
bne $5,$0,.L43
addiu $8,$7,1
addiu $5,$7,-1
.L41:
ld $25,%got_disp(bstFromPreorder)($28)
.L174:
sd $6,32($sp)
1: jalr $25
sd $7,24($sp)
sd $2,8($23)
ld $7,24($sp)
ld $2,0($sp)
ld $4,32($sp)
ld $25,%got_disp(bstFromPreorder)($28)
1: jalr $25
subu $5,$2,$7
sd $2,16($23)
.L39:
ld $2,8($sp)
sd $23,16($2)
sd $2,8($21)
beq $fp,$22,.L12
subu $23,$fp,$22
sll $3,$22,0
dsll $3,$3,32
dsrl $3,$3,32
dsll $3,$3,2
daddu $2,$20,$3
b .L110
sd $2,8($sp)
.L119:
ld $31,200($sp)
move $18,$0
ld $fp,192($sp)
ld $28,184($sp)
ld $23,176($sp)
ld $22,168($sp)
ld $21,160($sp)
ld $20,152($sp)
ld $19,144($sp)
ld $17,128($sp)
ld $16,120($sp)
move $2,$18
ld $18,136($sp)
jr $31
daddiu $sp,$sp,208
.L154:
sd $fp,16($sp)
b .L7
move $fp,$2
.L67:
move $fp,$21
.L115:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $5,4($20)
move $3,$2
sd $2,0($sp)
li $2,1 # 0x1
beq $16,$2,.L70
sw $5,0($3)
daddiu $19,$20,8
move $3,$19
li $22,1 # 0x1
b .L71
move $7,$16
.L74:
beq $7,$4,.L73
move $23,$22
addiu $22,$22,1
.L71:
lw $2,0($3)
addiu $4,$22,1
slt $2,$2,$5
bne $2,$0,.L74
daddiu $3,$3,4
addiu $23,$22,-1
bne $23,$0,.L114
sd $19,16($sp)
ld $2,0($sp)
ld $19,%got_disp(bstFromPreorder)($28)
addiu $23,$fp,-2
sd $0,8($2)
.L107:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
ld $3,16($sp)
move $16,$2
li $6,1 # 0x1
lw $8,0($3)
daddiu $4,$3,4
slt $3,$23,2
sw $8,0($2)
move $22,$4
move $9,$23
beq $3,$0,.L84
move $5,$0
b .L172
move $25,$19
.L85:
beq $9,$7,.L162
daddiu $22,$22,4
addiu $6,$6,1
.L84:
lw $5,0($22)
slt $5,$5,$8
bne $5,$0,.L85
addiu $7,$6,1
addiu $5,$6,-1
.L83:
move $25,$19
.L172:
1: jalr $25
sd $6,8($sp)
ld $6,8($sp)
sd $2,8($16)
move $4,$22
move $25,$19
1: jalr $25
subu $5,$23,$6
sd $2,16($16)
.L81:
ld $2,0($sp)
subu $23,$21,$fp
sd $16,16($2)
beq $21,$fp,.L65
sd $2,8($17)
sll $fp,$fp,0
dsll $fp,$fp,32
dsrl $fp,$fp,32
dsll $fp,$fp,2
b .L106
daddu $22,$20,$fp
.L73:
move $22,$16
.L114:
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
daddiu $2,$20,12
1: jalr $25
sd $2,24($sp)
lw $8,8($20)
move $4,$2
sd $2,16($sp)
li $2,1 # 0x1
sw $8,0($4)
daddiu $3,$20,12
li $7,1 # 0x1
bne $23,$2,.L78
move $9,$23
b .L163
move $7,$23
.L79:
beq $9,$5,.L164
daddiu $3,$3,4
addiu $7,$7,1
.L78:
lw $2,0($3)
slt $2,$2,$8
bne $2,$0,.L79
addiu $5,$7,1
addiu $5,$7,-1
.L77:
ld $19,%got_disp(bstFromPreorder)($28)
ld $4,24($sp)
sd $7,40($sp)
move $25,$19
1: jalr $25
sd $3,32($sp)
ld $3,16($sp)
ld $7,40($sp)
ld $4,32($sp)
sd $2,8($3)
move $25,$19
1: jalr $25
subu $5,$23,$7
ld $3,16($sp)
subu $23,$16,$22
sd $2,16($3)
ld $2,0($sp)
beq $16,$22,.L72
sd $3,8($2)
sll $6,$22,0
ld $2,8($sp)
dsll $6,$6,32
dsrl $6,$6,32
dsll $6,$6,2
daddu $2,$2,$6
b .L107
sd $2,16($sp)
.L19:
ld $23,0($sp)
.L117:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
lw $7,12($17)
move $3,$2
sd $2,40($sp)
sw $7,0($3)
ld $3,32($sp)
li $2,1 # 0x1
beq $3,$2,.L22
daddiu $19,$17,16
move $4,$19
li $8,1 # 0x1
b .L23
move $9,$3
.L26:
beql $9,$5,.L25
sd $8,48($sp)
addiu $8,$8,1
.L23:
lw $2,0($4)
addiu $5,$8,1
slt $2,$2,$7
bne $2,$0,.L26
daddiu $4,$4,4
addiu $2,$8,-1
sd $2,48($sp)
bne $2,$0,.L116
sd $19,64($sp)
ld $2,40($sp)
ld $19,%got_disp(bstFromPreorder)($28)
sd $0,8($2)
addiu $2,$23,-2
sd $2,48($sp)
.L112:
ld $25,%call16(malloc)($28)
1: jalr $25
li $4,24 # 0x18
ld $3,64($sp)
move $5,$2
sd $2,32($sp)
lw $9,0($3)
daddiu $4,$3,4
ld $3,48($sp)
sw $9,0($5)
move $11,$4
slt $2,$3,2
li $7,1 # 0x1
move $10,$3
beq $2,$0,.L36
move $5,$0
b .L173
move $25,$19
.L37:
beq $10,$8,.L165
daddiu $11,$11,4
addiu $7,$7,1
.L36:
lw $2,0($11)
slt $2,$2,$9
bne $2,$0,.L37
addiu $8,$7,1
addiu $5,$7,-1
.L35:
move $25,$19
.L173:
sd $11,64($sp)
1: jalr $25
sd $7,56($sp)
ld $3,32($sp)
ld $7,56($sp)
ld $4,64($sp)
sd $2,8($3)
ld $2,48($sp)
move $25,$19
1: jalr $25
subu $5,$2,$7
ld $3,32($sp)
sd $2,16($3)
.L33:
ld $2,40($sp)
sd $3,16($2)
ld $3,8($sp)
sd $2,8($3)
ld $2,0($sp)
subu $3,$2,$23
beq $2,$23,.L18
sd $3,0($sp)
sll $6,$23,0
ld $2,24($sp)
dsll $6,$6,32
dsrl $6,$6,32
dsll $6,$6,2
b .L111
daddu $19,$2,$6
.L92:
move $20,$23
.L113:
ld $25,%call16(malloc)($28)
daddiu $2,$22,8
li $4,24 # 0x18
1: jalr $25
sd $2,0($sp)
lw $8,4($22)
move $fp,$2
li $2,1 # 0x1
sw $8,0($fp)
daddiu $3,$22,8
li $7,1 # 0x1
bne $21,$2,.L97
move $9,$21
b .L166
move $7,$21
.L98:
beq $9,$5,.L167
daddiu $3,$3,4
addiu $7,$7,1
.L97:
lw $2,0($3)
slt $2,$2,$8
bne $2,$0,.L98
addiu $5,$7,1
addiu $5,$7,-1
.L96:
ld $19,%got_disp(bstFromPreorder)($28)
ld $4,0($sp)
sd $7,16($sp)
move $25,$19
1: jalr $25
sd $3,8($sp)
ld $7,16($sp)
ld $4,8($sp)
sd $2,8($fp)
move $25,$19
1: jalr $25
subu $5,$21,$7
sd $2,16($fp)
sd $fp,8($16)
beq $23,$20,.L90
subu $21,$23,$20
sll $2,$20,0
dsll $2,$2,32
dsrl $2,$2,32
dsll $2,$2,2
b .L105
daddu $fp,$22,$2
.L62:
move $17,$0
b .L168
sd $17,16($18)
.L25:
ld $8,32($sp)
.L116:
ld $25,%call16(malloc)($28)
daddiu $2,$17,20
li $4,24 # 0x18
sd $8,80($sp)
1: jalr $25
sd $2,72($sp)
lw $10,16($17)
move $3,$2
sd $2,64($sp)
sw $10,0($3)
ld $3,48($sp)
li $2,1 # 0x1
ld $8,80($sp)
daddiu $7,$17,20
li $9,1 # 0x1
bne $3,$2,.L30
move $11,$3
b .L169
move $9,$3
.L31:
beq $11,$5,.L170
daddiu $7,$7,4
addiu $9,$9,1
.L30:
lw $2,0($7)
slt $2,$2,$10
bne $2,$0,.L31
addiu $5,$9,1
addiu $5,$9,-1
.L29:
ld $19,%got_disp(bstFromPreorder)($28)
ld $4,72($sp)
sd $8,88($sp)
move $25,$19
sd $7,96($sp)
1: jalr $25
sd $9,80($sp)
ld $3,64($sp)
ld $9,80($sp)
ld $4,96($sp)
sd $2,8($3)
ld $2,48($sp)
move $25,$19
1: jalr $25
subu $5,$2,$9
ld $3,64($sp)
ld $8,88($sp)
sd $2,16($3)
ld $2,40($sp)
sd $3,8($2)
ld $2,32($sp)
subu $3,$2,$8
beq $2,$8,.L24
sd $3,48($sp)
sll $2,$8,0
ld $3,56($sp)
dsll $2,$2,32
dsrl $2,$2,32
dsll $2,$2,2
daddu $2,$3,$2
b .L112
sd $2,64($sp)
.L158:
ld $2,0($sp)
dsll $4,$22,32
dsrl $4,$4,32
dsll $4,$4,2
move $5,$6
daddu $fp,$2,$4
b .L54
move $6,$22
.L164:
sll $4,$23,0
dsll $4,$4,32
dsrl $4,$4,32
dsll $4,$4,2
move $5,$7
daddu $3,$19,$4
b .L77
move $7,$23
.L162:
ld $3,16($sp)
dsll $2,$23,32
dsrl $2,$2,32
dsll $2,$2,2
move $5,$6
daddu $22,$3,$2
b .L83
move $6,$23
.L161:
ld $2,0($sp)
move $5,$7
mtlo $2
dsll $2,$2,32
dsrl $2,$2,32
dsll $2,$2,2
mflo $7
b .L41
daddu $6,$19,$2
.L167:
sll $4,$21,0
dsll $4,$4,32
dsrl $4,$4,32
dsll $4,$4,2
move $5,$7
daddu $3,$19,$4
b .L96
move $7,$21
.L159:
ld $2,24($sp)
ld $3,0($sp)
move $5,$22
mtlo $2
dsll $2,$2,32
dsrl $2,$2,32
dsll $2,$2,2
mflo $22
b .L59
daddu $fp,$3,$2
.L156:
dsll $22,$21,32
dsrl $22,$22,32
dsll $22,$22,2
move $5,$23
daddu $22,$fp,$22
b .L102
move $23,$21
.L57:
b .L49
move $23,$0
.L52:
ld $19,%got_disp(bstFromPreorder)($28)
sd $0,8($20)
b .L109
sd $2,24($sp)
.L165:
ld $2,48($sp)
move $5,$7
dsll $11,$2,32
move $7,$2
ld $2,64($sp)
dsrl $11,$11,32
dsll $11,$11,2
b .L35
daddu $11,$2,$11
.L170:
lwu $4,52($sp)
move $5,$9
ld $9,48($sp)
dsll $4,$4,2
b .L29
daddu $7,$19,$4
.L3:
addiu $2,$16,-1
beq $2,$0,.L62
sd $0,8($18)
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
addiu $21,$16,-2
lw $3,4($17)
sd $0,8($2)
move $17,$2
sw $3,0($2)
.L66:
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
daddiu $22,$20,4
lw $3,4($20)
move $16,$2
sd $0,8($2)
sw $3,0($2)
addiu $21,$21,-1
.L91:
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
daddiu $22,$22,8
lw $3,-4($22)
ld $19,%got_disp(bstFromPreorder)($28)
move $20,$2
sw $3,0($2)
move $4,$22
move $5,$0
b .L102
li $23,1 # 0x1
.L10:
sd $0,8($21)
.L12:
b .L45
move $20,$0
.L16:
ld $2,8($sp)
sd $0,8($2)
.L18:
b .L39
move $23,$0
.L70:
sd $0,8($3)
.L72:
b .L81
move $16,$0
.L46:
addiu $2,$23,-1
sd $2,24($sp)
beq $2,$0,.L57
sd $0,8($20)
ld $25,%call16(malloc)($28)
li $4,24 # 0x18
1: jalr $25
ld $19,%got_disp(bstFromPreorder)($28)
ld $4,8($sp)
move $23,$2
move $5,$0
lw $3,4($4)
daddiu $fp,$4,8
move $4,$fp
sw $3,0($2)
b .L59
li $22,1 # 0x1
.L22:
ld $2,40($sp)
sd $0,8($2)
.L24:
sd $0,32($sp)
b .L33
ld $3,32($sp)
.L163:
b .L77
move $5,$0
.L157:
move $6,$22
b .L54
move $5,$0
.L166:
b .L96
move $5,$0
.L160:
b .L174
ld $25,%got_disp(bstFromPreorder)($28)
.L63:
addiu $21,$21,-1
bne $21,$0,.L66
sd $0,8($17)
.L65:
move $16,$0
b .L6
sd $16,16($17)
.L169:
b .L29
move $5,$0
.L88:
addiu $21,$23,-1
bne $21,$0,.L91
sd $0,8($16)
.L90:
move $20,$0
b .L87
sd $20,16($16)
.L155:
b .L175
move $25,$19
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.