Submission #1107955

# Submission time Handle Problem Language Result Execution time Memory
1107955 2024-11-02T13:04:19 Z sleepntsheep Message (IOI24_message) C++17
Compilation error
0 ms 0 KB
#include "message.h"

void send_message(std::vector<bool> M, std::vector<bool> C) {
    int d[16] = { 0 }, g[16] = { 0 }, z = 0, buf[2000], y = 0;
    for (int j = 0, i = 0; i < 31; ++i) if (!C[i]) g[j++] = i;
    for (int i = 0; i < 15; ++i) d[i] = g[i + 1] - g[i];
    d[15] = 32 - g[15] + g[0];

    for (int i = 0; i < 10; ++i) buf[y++] = ((int)M.size() >> i) & 1;
    for (int x : M) buf[y++] = x;

    for (int i = 0; i < 67; ++i) {
	std::vector<int> p(31);
	for (int k = 0, ii; k < 16; ++k) {
	    ii = g[k];
	    if (i + 1 == d[k])
		p[ii] = 1;
	    else if (i + 1 < d[k])
		p[ii] = 0;
	    else
		p[ii] = buf[z++];
	}
	send_packet(p);
    }
}

std::vector<int> g[31];
int head, tail, par[31];

int cycle(int u, int p) {
    vis[u] = 1;
    par[u] = p;
    for (int v : g[u]) {
	if (!vis[v]) {
	    if (cycle(v, u)) return 1;
	} else {
	    head = u; tail = v;
	    return 1;
	}
    }
    return 0;
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
    int d[31] = { 0 }, g[16], e[31] = { 0 }, S = 0, z = 0, buf[2000];
    for (int i = 0; i < 67; ++i) {
	for (int j = 0; j < 31; ++j) {
	    if (!d[j] && R[i][j] == 1) {
		d[j] = (j + i + 1) % 31;
		g[j].push_back(d[j]);
		g[d[j]].push_back(j);
	    }
	}
    }
    
    for (int i = 0, p = 0; i < 31; ++i) if (!vis[i] && cycle(i, i)) {
	for (int c = head; c != tail; c = par[c]) g[p++] = c;
	g[p++] = tail;
    }

    for (int i = 0; i < 16; ++i) e[g[i]] = -1;

    for (int i = 0; i < 67; ++i) {
	for (int j = 0; j < 31; ++j) {
	    if (e[j] && d[j] <= i) {
		buf[z++] = R[i][j];
	    }
	}
    }

    for (int i = 0; i < 10; ++i) S |= buf[z++] << i;

    std::vector<bool> M(S);
    for (int &x : M) x = buf[z++];
    return M;
}

Compilation message

message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:23:14: error: could not convert 'p' from 'vector<int>' to 'vector<bool>'
   23 |  send_packet(p);
      |              ^
      |              |
      |              vector<int>
message.cpp: In function 'int cycle(int, int)':
message.cpp:31:5: error: 'vis' was not declared in this scope
   31 |     vis[u] = 1;
      |     ^~~
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:50:8: error: request for member 'push_back' in 'g[j]', which is of non-class type 'int'
   50 |   g[j].push_back(d[j]);
      |        ^~~~~~~~~
message.cpp:51:11: error: request for member 'push_back' in 'g[d[j]]', which is of non-class type 'int'
   51 |   g[d[j]].push_back(j);
      |           ^~~~~~~~~
message.cpp:56:46: error: 'vis' was not declared in this scope
   56 |     for (int i = 0, p = 0; i < 31; ++i) if (!vis[i] && cycle(i, i)) {
      |                                              ^~~
message.cpp:74:19: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   74 |     for (int &x : M) x = buf[z++];
      |                   ^
In file included from /usr/include/c++/10/vector:68,
                 from message.h:1,
                 from message.cpp:1:
/usr/include/c++/10/bits/stl_bvector.h:86:5: note:   after user-defined conversion: 'std::_Bit_reference::operator bool() const'
   86 |     operator bool() const _GLIBCXX_NOEXCEPT
      |     ^~~~~~~~