답안 #594686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
594686 2022-07-12T20:07:19 Z Blagojce Flight to the Ford (BOI22_communication) C++17
0 / 100
72 ms 1736 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

#include "communication.h"
vector<int> V = {2,2,3,3,2,3,3,3,3,3,2,2,2,2,2,2,2,3,2,3,2,3,3,2,3,3,2,3,3,2,2,3,2,3,2,3,2,2,2,3,2,2,3,2,2,3,2,2,2,3};
//bool aux[250];
/*

vector<int> v;
int send(int x){
	cout<<x<<" SENDED"<<endl;
	int c;
	cin >> c;
	v.pb(c);
	return c;
}
int P = 0;
int receive(){
	cout<<"SEND ME"<<endl;
	int c;
	return v[P++];
}
*/
void encode(int N, int X) {
	srand(N);
	
	int pos = 0;
	
	int T = 0;
	
	while(pos < 2){
		int r_bit = X&(1<<pos);
		if(r_bit != 0) r_bit = 1;
		
		int nxt = V[T++];
		T = T % ((int)V.size());
		
		int t = send(1);
		if(t == 1){
			bool ok = true;
			fr(i, 0, nxt){
				int c = send(r_bit);
				ok &= (c == r_bit);
			}
			if(ok) ++pos;
		}
		else{
			send(r_bit);
			fr(i, 0, nxt-1) send(0);
			++pos;
		}
	}
}


std::pair<int, int> decode(int N){
	srand(N);
	
	int pos = 0;
	
	int X = 0;
	
	int T = 0;
	while(pos < 2){
		
		int nxt = V[T++];
		T = T % ((int)V.size());
		
		
		int t = receive();
		if(t == 1){
			int sum = 0;
			fr(i, 0, nxt){
				sum += receive();
			}
			if(sum == 0) ++pos;
			else if(sum == nxt){
				X |= (1<<pos);
				++pos;
			}
		}
		else{
			if(receive() == 1) X |= (1<<pos);
			++pos;
			fr(i, 0, nxt-1){
				receive();
			}
			
		}
	}
	//cout<<X<<endl;
	
	return {X, X};
	
}/*
int main(){
	encode(10, 1);
	decode(10);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1736 KB Output is correct
2 Correct 16 ms 1712 KB Output is correct
3 Incorrect 3 ms 200 KB Not correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 200 KB Not correct
2 Halted 0 ms 0 KB -