Submission #599777

# Submission time Handle Problem Language Result Execution time Memory
599777 2022-07-19T21:33:47 Z Mounir Flight to the Ford (BOI22_communication) C++17
Compilation error
0 ms 0 KB
#include "communication.h"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define chmax(x, v) x = max(x, v)
#define chmin(x, v) x = min(x, v)
#define pb push_back
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
 
void encode(int N, int X){
      if (X == 1){
            for (int i = 0; i < 6; ++i)
                  int ans = send(0);
      }
      else if (X == 2){
            for (int i = 0;  i < 6; ++i)
                  int ans = send(1);
      }
      else {
            for (int i = 0; i < 6; ++i)
                  int ans = send(i%3 == 0);
      }
}

pii decode(int N){
      vector<int> vals;
      for (int i = 0; i < 6; ++i)
            vals.pb(receive());
      
      sets<int> possibles;
      for (int mask = 0; mask < (1 << 6); ++mask){
            bool valid = true;
            vector<int> inds;
            for (int i = 0; i < 6; ++i){
                  if ((mask&(1 << i)) > 0)      
                        inds.pb(i);
            }
 
            for (int i = 0; i < sz(inds) - 1; ++i)
                  valid &= (inds[i] != inds[i + 1] - 1);
            if (!valid) continue;
            vector<int> change = vals;
            for (int ind : inds)    
                  change[ind] ^= 1;
            bool un = true, deux = true, trois = true;
            for (int i = 0; i < 6; ++i){
                  un &= change[i] == 0;
                  deux &= change[i] == 1;
                  trois &= (change[i]^(i%3 == 0));
            }
            if (un)
                  possibles.insert(1);
            if (deux)
                  possibles.insert(2);
            if (trois)
                  possibles.insert(3);
      }

      vector<int> v;
      for (int a : possibles)
            v.pb(a);
      if (sz(v) == 2)
            return {v[0], v[1]};
      else if (sz(v) == 1)
            return {v[0], 1};
      else 
            return {-1, -1}
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:16:23: warning: unused variable 'ans' [-Wunused-variable]
   16 |                   int ans = send(0);
      |                       ^~~
communication.cpp:20:23: warning: unused variable 'ans' [-Wunused-variable]
   20 |                   int ans = send(1);
      |                       ^~~
communication.cpp:24:23: warning: unused variable 'ans' [-Wunused-variable]
   24 |                   int ans = send(i%3 == 0);
      |                       ^~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:33:7: error: 'sets' was not declared in this scope; did you mean 'setns'?
   33 |       sets<int> possibles;
      |       ^~~~
      |       setns
communication.cpp:33:12: error: expected primary-expression before 'int'
   33 |       sets<int> possibles;
      |            ^~~
communication.cpp:55:19: error: 'possibles' was not declared in this scope
   55 |                   possibles.insert(1);
      |                   ^~~~~~~~~
communication.cpp:57:19: error: 'possibles' was not declared in this scope
   57 |                   possibles.insert(2);
      |                   ^~~~~~~~~
communication.cpp:59:19: error: 'possibles' was not declared in this scope
   59 |                   possibles.insert(3);
      |                   ^~~~~~~~~
communication.cpp:63:20: error: 'possibles' was not declared in this scope
   63 |       for (int a : possibles)
      |                    ^~~~~~~~~
communication.cpp:70:28: error: expected ';' before '}' token
   70 |             return {-1, -1}
      |                            ^
      |                            ;
   71 | }
      | ~