제출 #1221597

#제출 시각아이디문제언어결과실행 시간메모리
1221597Theo830메시지 (IOI24_message)C++20
83.31 / 100
416 ms852 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define id pair<ll,vector<ll> >
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "message.h"
void send_message(std::vector<bool> M, std::vector<bool> C) {
    M.pb(1);
    reverse(all(M));
    ll pos = 0;
    f(i,0,31){
        if(C[i] == 0){
            pos = i;
            break;
        }
    }
    vector<bool>s;
    s.assign(31,0);
    f(i,0,4){
        f(j,0,31){
            if(C[j] == 0){
                if(pos & (1<<i)){
                    s[j] = 1;
                }
                else{
                    s[j] = 0;
                }
            }
        }
        send_packet(s);
    }
    f(i,0,30){
        if(i != pos){
            f(j,0,31){
                if(C[j] == 0){
                    if(j == pos){
                        s[j] = C[i];
                    }
                    else{
                        if(!M.empty()){
                            s[j] = M.back();
                            M.pop_back();
                        }
                        else{
                            s[j] = 0;
                        }
                    }
                }
            }
            send_packet(s);
        }
    }
    while(!M.empty()){
        f(j,0,31){
            if(C[j] == 0){
                if(!M.empty()){
                    s[j] = M.back();
                    M.pop_back();
                }
                else{
                    s[j] = 0;
                }
            }
        }
        send_packet(s);
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool> > R) {
    vector<bool>ans;
    vector<bool>c;
    c.assign(31,0);
    ll pos = 0;
    ll z = 0;
    f(i,0,4){
        ll sum = 0;
        f(j,0,31){
            sum += R[i][j];
        }
        if(sum >= 16){
            pos |= (1<<i);
        }
    }
    z = 4;
    ll sum = 0;
    f(i,0,30){
        if(i != pos){
            c[i] = R[z][pos];
            sum += c[i];
            z++;
        }
    }
    c.back() = 15 - sum;
    f(i,4,33){
        f(j,pos+1,31){
            if(c[j] == 0){
                ans.pb(R[i][j]);
            }
        }
    }
    f(i,33,R.size()){
        f(j,0,31){
            if(c[j] == 0){
                ans.pb(R[i][j]);
            }
        }
    }
    while(ans.back() == 0){
        ans.pop_back();
    }
    ans.pop_back();
    return ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...