Submission details
Task:Tulkki
Sender:j3rmu
Submission time:2025-10-29 12:15:20 +0200
Language:C
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.00 s1, 2, 3details
#20.00 s1, 2, 3details
#30.00 s1, 2, 3details
#40.00 s1, 2, 3details
#50.00 s1, 2, 3details
#60.00 s1, 2, 3details
#70.00 s2, 3details
#80.00 s2, 3details
#90.00 s2, 3details
#100.00 s2, 3details
#110.00 s2, 3details
#120.00 s2, 3details
#130.00 s3details
#140.00 s3details
#150.00 s3details
#160.00 s3details
#170.00 s3details
#180.00 s3details

Code

#include <asm-generic/errno.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>

#define OP(A) A >> 24
#define VAR(A) (A >> 16) & 0xFF  
#define OFFSET(A) A & 0xFFFF

enum opco
    {
	CLEAR = 1,
	INCREASE,
	PRINT,
	BRANCH_CND,
	BRANCH_UNC,
	LDLAR,
    };

unsigned int varar[255] = {0};
unsigned int lar[255] = {0};

int32_t prog[1000] = {0};
int pc = 0, pwc = 0;
unsigned char eof = 0;

long getln (char* b, size_t n, FILE* stream)
{
    int c ,rc = 0;
    while (rc < n)
    {
	c = getc(stream);
	if (c <= 0)
	{
	    return -1;
	}
	else if (c == '\n')
	    break;
	b[rc] = (char)(c & 0xFF);
	rc++;
    }
    b[rc] = 0;

    return rc;
}

#define psh(V) __asm__ ("push %0" : : "r" (V));
#define pop(V) __asm__ ("pop %0" : "=r" (V) :)

void eval (void)
{
    unsigned int inst;

    while ((inst = prog[pc++]))
    {
	switch (OP(inst))
	{
	case CLEAR:
	    varar[VAR(inst)] = 0;
	    break;
	case INCREASE:
	    varar[VAR(inst)]++;
	    break;
	case PRINT:
	    printf("%u ", varar[VAR(inst)]);
	    break;
	case LDLAR:
	    lar[VAR(inst)] = varar[VAR(inst)] + 1;
	case BRANCH_CND:
	    if (!lar[VAR(inst)])
		pc = OFFSET(inst);
	    else
		lar[VAR(inst)]--;
	    break;
	case BRANCH_UNC:
	    pc = OFFSET(inst);
	    break;
	}
    }
}

int main (void)
{
    char ib[100];
    unsigned int opc = 0;
	
    ungetc(getc(stdin), stdin);

    fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
 nl:
    while (getln(ib, sizeof(ib), stdin) != -1)
    { 
	char *op, *var; 
	unsigned long bc_dec = 0; 

	op = strtok(ib, " ");
	do
	{
	    
	    if (op == NULL)
		break;

	    switch (op[0]) 
	    { 
	    case 'C': 
		var = strtok(NULL, " "); 
		opc = CLEAR << 24 | var[0] << 16; 
		break; 
	    case 'I': 
		var = strtok(NULL, " "); 
		opc = INCREASE << 24 | var[0] << 16; 
		break; 
	    case 'P': 
		var = strtok(NULL, " "); 
		opc = PRINT << 24 | var[0] << 16; 
		break; 
	    case 'R': 
		var = strtok(NULL, " "); 
		opc = LDLAR << 24 | var[0] << 16;
		prog[pwc++] = opc;
		opc = BRANCH_CND << 24 | var[0] << 16; 
		bc_dec = BRANCH_UNC << 24 | var[0] << 16 | pwc; 
		psh(bc_dec); 
		break; 
	    case ')': 
		pop(bc_dec); 
		opc = bc_dec; 
		prog[OFFSET(opc)] |= (pwc + 1) & 0xFFFF;
		break;
	    case '#':
		goto nl;
	    default:
		opc = 0;
	    } 

	    if (opc != 0) 
		prog[pwc++] = opc; 
	} while ((op = strtok(NULL, " ")));
    }

    eval();
    
    return 0;
}

Test details

Test 1 (public)

Group: 1, 2, 3

Verdict:

input
PRINT X
INCREASE X
PRINT X
INCREASE X
PRINT X
...

correct output
0 1 2 0 

user output
(empty)

Test 2 (public)

Group: 1, 2, 3

Verdict:

input
INCREASE
X
# aybabtu
   PRINT    X
INCREASE # test
...

correct output
1 3 

user output
(empty)

Test 3 (public)

Group: 1, 2, 3

Verdict:

input
# Create number 3
INCREASE X
INCREASE X
INCREASE X

...

correct output

user output
(empty)

Test 4 (public)

Group: 1, 2, 3

Verdict:

input
INCREASE A
PRINT A
INCREASE B
PRINT B
INCREASE C
...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
(empty)

Test 5 (public)

Group: 1, 2, 3

Verdict:

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
999 

user output
(empty)

Test 6 (public)

Group: 1, 2, 3

Verdict:

input
PRINT X
PRINT X
PRINT X
PRINT X
PRINT X
...

correct output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

user output
(empty)

Test 7 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 5 5 5 

user output
(empty)

Test 8 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
0 0 0 0 0 

user output
(empty)

Test 9 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
6 7 8 9 10 

user output
(empty)

Test 10 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 

user output
(empty)

Test 11 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
20 

user output
(empty)

Test 12 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A

INCREASE B
INCREASE B
...

correct output
42 

user output
(empty)

Test 13 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 

user output
(empty)

Test 14 (public)

Group: 3

Verdict:

input
# Create number 3
INCREASE A INCREASE A INCREASE...

correct output
12 

user output
(empty)

Test 15 (public)

Group: 3

Verdict:

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
531441 

user output
(empty)

Test 16 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1337 

user output
(empty)

Test 17 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A

REPEAT A TIMES (
    REPEAT A TIMES (
...

correct output
1 2 1 2 1 1 3 4 3 4 3 4 3 4 3 ...

user output
(empty)

Test 18 (public)

Group: 3

Verdict:

input
# Efficient algorithm for find...

correct output
2 3 5 7 11 13 17 19 23 29 31 3...

user output
(empty)