#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
read some solutions a long time ago, remember some key ideas from there
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "communication.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
//
void encode(int n, int k) {
vector<int> a = {0,6,9,15};
amax(n,4);
int x = a[k-1];
rep(bit,4){
int b = 0;
if(x&(1<<bit)) b = 1;
send(b);
}
}
std::pair<int, int> decode(int n) {
vector<int> a = {0,6,9,15};
vector<vector<int>> possible(4);
rep(i,4){
int x = a[i];
rep(mask,1<<4){
int pb = -1;
bool ok = true;
rep(bit,4){
int b = 0;
if(mask&(1<<bit)) b = 1;
if(b == 1 and pb == 1){
ok = false;
}
pb = b;
}
if(ok){
possible[i].pb(x^mask);
}
}
}
int x = 0;
rep(bit,4){
x = (x<<1)|receive();
}
vector<int> res;
rep(i,n){
if(count(all(possible[i]),x)){
res.pb(i+1);
}
}
assert(!res.empty());
while(sz(res) < 2){
res.pb(res[0]);
}
return {res[0],res[1]};
// receive();
// receive();
// receive();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2740 KB |
Output is correct |
2 |
Correct |
6 ms |
2740 KB |
Output is correct |
3 |
Correct |
10 ms |
2924 KB |
Output is correct |
4 |
Correct |
8 ms |
2740 KB |
Output is correct |
5 |
Correct |
12 ms |
2740 KB |
Output is correct |
6 |
Correct |
17 ms |
2736 KB |
Output is correct |
7 |
Correct |
34 ms |
2732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |