CSES - Datatähti 2022 alku - Results
Submission details
Task:Karkit
Sender:EmilCoder
Submission time:2021-10-13 19:23:51 +0300
Language:Assembly
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails

Code

; Imports:

; Exports:
global _start

section .code code
_start:
; Align stack:
    ;push rax
; Get numbers:
;mov ecx, 3
;mov rdi, value1
;.loop1:
    ;push rcx
    ;push rdi
    mov r15, char_buffer ; Save a bit of space.
    xor eax, eax
    xor edi, edi
    mov rsi, r15
    mov rdi, 12
    syscall
    ; Convert the string to u32:
        ; Find the string's length:
        ;    xor eax, eax
        ;    xor r14d, r14d
        ;    mov rsi, r15
        ; Loop body:
        ;.loop1_1:
        ;    inc r14d
        ;    lodsb
        ;    test eax, eax
        ;    jz .loop1_1
        ;    dec r14d
        ; Go through the characters to convert them to an integer:
        ;    mov ecx, r14d
        ;    mov rsi, r15
        ;    add rsi, r14
        ;    dec rsi
        ;    mov r13d, 1
        ;    xor ebx, ebx
        ;    std
        ;.loop1_2:
        ;    dec r14d
        ;    xor eax, eax
        ;    lodsd
        ;    sub al, '0'
        ;    imul eax, r13d
        ;    add ebx, eax
        ;    imul r13d, r13d, 10
        ;    loop .loop1_2
        ;    cld
    ; Save the number:
    ;    mov eax, ebx
    ;    stosd
    ;pop rdi
    ;pop rcx
    ;loop .loop1
; Calculate the value:
    ; Get the smaller candy price:
    ;    mov eax, [rel value3]
    ;    mov ebx, [rel value2]
    ;    cmp ebx, eax
    ;    cmovg ebx, eax ; Assumption: All x64 CPUs support CMOV.
    ; Divide the amount of money by the candy price:
    ;    xor edx, edx
    ;    mov eax, [rel value1]
    ;    div ebx
; Convert EDX to the value to output:
    ;sub rsp, 32
    ;mov ecx, eax ; value
    ;mov rdx, char_buffer ; buffer
    ;mov r8d, 12 ; size
    ;mov r9d, 10 ; radix
    ;call _itoa_s
    ;add rsp, 32
; Output the number:
    ; Prepare index:
    ;    mov rsi, char_buffer
    ; Do it:
    ;.loop2:
    ;    xor eax, eax
    ;    lodsb
    ;    test eax, eax
    ;    jz .loop2_end
    ;    sub rsp, 32
    ;    mov ecx, eax ; c
    ;    call _putch
    ;    add rsp, 32
    ;    jmp .loop2
    ;.loop2_end:
; Exit the process:
    mov eax, 0x37
    syscall
; Static allocations:
section .bss bss
value1: resd 1
value2: resd 1
value3: resd 1
char_buffer: resb 12

Test details

Test 1

Verdict:

input
100
1
1

correct output
100

user output
(empty)

Test 2

Verdict:

input
1
100
100

correct output
0

user output
(empty)

Test 3

Verdict:

input
50
2
3

correct output
25

user output
(empty)

Test 4

Verdict:

input
100
17
3

correct output
33

user output
(empty)

Test 5

Verdict:

input
5
5
5

correct output
1

user output
(empty)