Submission details
Task:Hypyt
Sender:NicholasAhman
Submission time:2025-11-04 19:14:29 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.00 s1, 2, 3, 4, 5details
#20.00 s1, 2, 3, 4, 5details
#30.00 s1, 2, 3, 4, 5details
#40.00 s1, 2, 3, 4, 5details
#50.00 s1, 2, 3, 4, 5details
#60.01 s2, 5details
#70.00 s2, 5details
#80.00 s2, 5details
#90.03 s3, 4, 5details
#100.03 s3, 4, 5details
#110.03 s3, 4, 5details
#120.03 s4, 5details
#130.03 s4, 5details
#140.03 s4, 5details
#150.03 s5details
#160.03 s5details
#170.03 s5details
#180.03 s5details
#190.03 s5details
#200.03 s5details
#210.03 s5details
#220.00 s1, 2, 3, 4, 5details
#230.00 s1, 2, 3, 4, 5details
#240.03 s5details
#250.03 s5details
#260.03 s5details
#270.03 s5details

Compiler report

input/code.cpp: In function 'void draw_line(int, size_t, int)':
input/code.cpp:49:39: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |     for (size_t i = ops.size() - 1; i != -1; i--) {
      |                                     ~~^~~~~

Code

#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

uint64_t *colors;

size_t width;
size_t height;
size_t color_count;

struct Drawing {
    int rc;
    size_t n;
    int color;
};

struct Point {
    size_t x;
    size_t y;
};

std::vector<Drawing> ops;

Point intersection(int rc1, size_t n1, int rc2, size_t n2) {
    if (rc1 == 'C') {
        return { .x = n1,  .y = n2};
    } else {
        return { .x = n2,  .y = n1};
    }
}

void draw_line(int rc, size_t n, int color) {
    colors[color] += rc == 'R' ? width : height;

    if (ops.size() == 0) {
        ops.push_back({rc, n, color});
        return;
    }

    bool same_line = false;

    std::unordered_map<size_t, Point> intersections;
    for (size_t i = ops.size() - 1; i != -1; i--) {
        if (ops[i].rc != rc) {
            Point is = intersection(rc, n, ops[i].rc, ops[i].n);
            if (intersections.count(is.x + width * is.y) == 0) {
                colors[ops[i].color]--;
                intersections.insert({is.x + width * is.y, is});
            }
        } else {
            if (n != ops[i].n) {
                continue;
            }

            if (same_line) {
                continue;
            }

            std::unordered_set<size_t> is2;
            size_t covered = rc == 'R' ? width : height;
            for (size_t j = i + 1; j < ops.size(); j++) {
                if (ops[j].rc != ops[i].rc) {
                    Point is = intersection(ops[i].rc, ops[i].n, ops[j].rc, ops[j].n);
                    if (is2.count(is.x + width * is.y) == 0) {
                        covered--;
                        is2.insert(is.x + width * is.y);
                    }
                } else {
                    if (ops[i].n != ops[j].n) {
                        continue;
                    }

                    covered = 0;
                    break;
                }
            }

            colors[ops[i].color] -= covered;
            same_line = true;
        }
    }

    ops.push_back({rc, n, color});
}

int main(void) {
    char *input = (char *)malloc(1024*1024*8);
    const size_t len = read(0, input, 1024*1024*8);
    size_t idx = 0;

    size_t next_space = strchr(input, ' ') - input;
    input[next_space] = '\0';
    height = atoi(input);
    idx += next_space + 1;

    next_space = strchr((input + idx), ' ') - (input + idx);
    (input + idx)[next_space] = '\0';
    width = atoi((input + idx));
    idx += next_space + 1;

    next_space = strchr((input + idx), ' ') - (input + idx);
    (input + idx)[next_space] = '\0';
    color_count = atoi((input + idx));
    idx += next_space + 1;

    next_space = strchr((input + idx), '\n') - (input + idx);
    (input + idx)[next_space] = '\0';
    size_t operations = atoi((input + idx));
    idx += next_space + 1;

    colors = (uint64_t *)malloc((color_count + 1) * sizeof(uint64_t));
    ops.reserve(operations);

    for (size_t i = 0; i < color_count + 1; i++) {
        colors[i] = 0;
    }

    for (size_t i = 0; i < operations; i++) {
        int rc = (input + idx)[0];
        idx += 2;

        next_space = strchr((input + idx), ' ') - (input + idx);
        (input + idx)[next_space] = '\0';
        size_t n = atoi((input + idx));
        idx += next_space + 1;

        if (i == operations - 1) {
            next_space = len - ((input + idx) - input) - 1;
        } else {
            next_space = strchr((input + idx), '\n') - (input + idx);
        }

        (input + idx)[next_space] = '\0';
        size_t color = atoi((input + idx));
        idx += next_space + 1;

        draw_line(rc, n, color);
    }

    for (size_t i = 1; i < color_count + 1; i++) {
        printf("%lu ", colors[i]);
    }

    free(input);
    free(colors);

}

Test details

Test 1 (public)

Group: 1, 2, 3, 4, 5

Verdict:

input
4 6 5
.*.***
*...**
*****.
*..*.*
...

correct output
1
0
3
3
-1

user output
0 4 0 0 0 

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 2

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
..........
.....*....
........*.
*.*....*..
...

correct output
1
2
1
2
2
...

user output
0 0 0 0 0 17 9 0 0 9 

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 3

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
*...***.**
*****.*...
**..**.**.
..**.**.*.
...

correct output
1
2
2
1
2
...

user output
0 0 0 0 0 0 0 0 19 0 

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 4

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 10
***.*.****
**********
*.********
.*.***.**.
...

correct output
3
4
2
3
4
...

user output
0 0 0 10 9 0 0 0 0 16 

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 5

Group: 1, 2, 3, 4, 5

Verdict:

input
10 10 1
.****.****
**.**..***
**********
*******..*
...

correct output
7

user output
(empty)

Test 6

Group: 2, 5

Verdict:

input
250 250 250
.*...*.....*******..**...*.......

correct output
2
3
3
2
2
...

user output
0 0 0 18446744073709551608 0 4...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 7

Group: 2, 5

Verdict:

input
250 250 250
...*......**.**.*.*..**..*..**...

correct output
2
2
2
2
3
...

user output
0 0 0 0 0 469 0 0 244 0 223 6 ...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 8

Group: 2, 5

Verdict:

input
250 250 250
**..**..****.****.*.***.***..*...

correct output
2
3
3
3
3
...

user output
207 6 0 0 0 0 0 0 0 0 0 0 9 18...

Feedback: Incorrect character on line 1 col 2: expected "2", got "207"

Test 9

Group: 3, 4, 5

Verdict:

input
40 40 200000
...*.**.*..*.............*.*.....

correct output
2
2
2
2
2
...

user output
35 0 0 61 0 0 0 0 0 1 1 184467...

Feedback: Incorrect character on line 1 col 1: expected "2", got "35"

Test 10

Group: 3, 4, 5

Verdict:

input
40 40 200000
**.**..*.*.*.******....****.*....

correct output
2
1
3
2
2
...

user output
0 0 24 79 0 2 1844674407370955...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 11

Group: 3, 4, 5

Verdict:

input
40 40 200000
.*.*.**.*****.***.*.****.**.**...

correct output
3
3
3
3
3
...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 12

Group: 4, 5

Verdict:

input
80 80 200000
*....**.***..****...*.....*......

correct output
2
2
2
2
2
...

user output
0 0 0 79 0 0 0 0 0 0 0 0 0 79 ...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 13

Group: 4, 5

Verdict:

input
80 80 200000
.***.*..*.***..*****....**...*...

correct output
3
2
2
3
2
...

user output
0 0 0 0 0 0 0 2 0 0 71 80 3 1 ...

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 14

Group: 4, 5

Verdict:

input
80 80 200000
*******.*****.*..*..****...***...

correct output
2
3
1
2
2
...

user output
0 0 0 0 0 0 0 0 0 0 0 0 80 0 0...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 15

Group: 5

Verdict:

input
250 250 200000
*....*..*..*..**..*.........**...

correct output
3
2
2
2
2
...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 16

Group: 5

Verdict:

input
250 250 200000
..*....*..*......*.**.*.*..***...

correct output
2
2
2
2
2
...

user output
0 0 0 224 0 0 1 0 250 0 0 0 18...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 17

Group: 5

Verdict:

input
250 250 200000
*..*.*****.*********.****.****...

correct output
3
3
2
2
2
...

user output
0 0 0 0 0 248 0 2 0 0 1 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 18

Group: 5

Verdict:

input
250 250 200000
*********.**********.******.**...

correct output
3
3
3
3
3
...

user output
0 0 0 18446744073709551613 0 2...

Feedback: Incorrect character on line 1 col 1: expected "3", got "0"

Test 19

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
104
422
145
93
65
...

user output
0 0 0 0 0 0 184467440737095515...

Feedback: Incorrect character on line 1 col 1: expected "104", got "0"

Test 20

Group: 5

Verdict:

input
250 250 200000
..****************************...

correct output
57
155
38
65
98
...

user output
0 0 0 0 18446744073709551573 0...

Feedback: Incorrect character on line 1 col 1: expected "57", got "0"

Test 21

Group: 5

Verdict:

input
250 250 200000
.*****************************...

correct output
498
498
498
498
498
...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "498", got "0"

Test 22

Group: 1, 2, 3, 4, 5

Verdict:

input
10 1 10
*
*
.
*
...

correct output
0
1
1
0
0
...

user output
10 0 0 0 0 0 0 0 0 0 

Feedback: Incorrect character on line 1 col 1: expected "0", got "10"

Test 23

Group: 1, 2, 3, 4, 5

Verdict:

input
1 10 10
........*.
1 7 1 10
1 4 1 7
1 5 1 1
...

correct output
1
1
1
1
1
...

user output
7 0 0 0 0 0 0 0 0 0 

Feedback: Incorrect character on line 1 col 1: expected "1", got "7"

Test 24

Group: 5

Verdict:

input
250 1 200000
*
.
*
.
...

correct output
1
1
1
1
1
...

user output
250 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "1", got "250"

Test 25

Group: 5

Verdict:

input
1 250 200000
*.*.*...*.*.**.***..**.*.*..**...

correct output
1
1
1
1
1
...

user output
4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 1: expected "1", got "4"

Test 26

Group: 5

Verdict:

input
250 250 200000
.................................

correct output
2
2
2
2
2
...

user output
0 0 18446744073709551613 0 228...

Feedback: Incorrect character on line 1 col 1: expected "2", got "0"

Test 27

Group: 5

Verdict:

input
250 250 200000
******************************...

correct output
0
0
0
0
0
...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Feedback: Incorrect character on line 1 col 499: expected "0", got "250"