#include"communication.h"
#include <bits/stdc++.h>
//
// --- Sample implementation for the task communication ---
//
// To compile this program with the sample grader, place:
// communication.h communication_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
// g++ -std=c++17 communication_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
//
using namespace std;
string arr[3] = {"0000","1111","1001"};
void encode(int N, int X) {
for(auto &i:arr[X-1])send(i-'0');
return;
}
bool check(string a,string b){
vector<int> dif;
for(int i = 0;i<a.size();i++){
if(a[i] != b[i])dif.push_back(i);
}
for(int i = 1;i<dif.size();i++){
if(dif[i]-dif[i-1]<=1)return false;
}
return true;
}
std::pair<int, int> decode(int N) {
string s;
for(int i = 0;i<4;i++)s += '0'+receive();
vector<int> ans;
for(int i = 0;i<3;i++){
if(check(arr[i],s))ans.push_back(i+1);
}
assert(ans.size()<=2);
if(ans.size()<2)ans.push_back(ans.back() ==1?2:1);
return make_pair(ans[0],ans[1]);
}
Compilation message
communication.cpp: In function 'bool check(std::string, std::string)':
communication.cpp:26:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0;i<a.size();i++){
| ~^~~~~~~~~
communication.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 1;i<dif.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2852 KB |
Output is correct |
2 |
Correct |
7 ms |
2792 KB |
Output is correct |
3 |
Correct |
10 ms |
2744 KB |
Output is correct |
4 |
Correct |
6 ms |
2740 KB |
Output is correct |
5 |
Correct |
11 ms |
2740 KB |
Output is correct |
6 |
Correct |
13 ms |
2900 KB |
Output is correct |
7 |
Correct |
28 ms |
2736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |