Submission #1190257

#TimeUsernameProblemLanguageResultExecution timeMemory
1190257NotLinux메시지 (IOI24_message)C++20
0 / 100
202 ms860 KiB
#include "message.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l , int r){
    return rng() % (r-l+1) + l;
}
long long decipher = 0;
long long cur = 120397273ll;
const long long sabit = 893721095ll;
const long long mod = 1e9 + 7;
const long long epoch = 30;
void init(){
    decipher = 0;
    cur = 120397273ll;
}
int nxt(){
    cur = (cur * decipher + sabit) % mod;
    return cur & 1;
}
vector<vector<int>>dizi(epoch , vector<int>(31,0));
void send_message(vector<bool> M, vector<bool> C) {
    // cout << "flag0" << endl;
    init();
    // decipheri belirle
    vector<bool>vec(31,0);
    for(int i = 0;i<31;i++)vec[i] = rand(0,1);
    vector<bool>v1 = send_packet(vec);
    decipher = 0;
    for(int i = 0;i<31;i++){
        if(v1[i]){
            decipher += 1ll << i;
        }
    }
    // cout << "decipher : " << decipher << endl;
    // cout << "flag1" << endl;
    // cout << "C : ";for(auto itr : C)cout << itr << " ";cout << endl;
    // kleopatralari bul
    for(int i = 0;i<epoch;i++){
        vec.assign(31,0);
        for(int j = 0;j<31;j++){
            if(C[j] == 0){
                vec[j] = nxt();
            }
            else{
                nxt();
            }
        }
        // cout << "vec : ";for(auto itr : vec)cout << itr << " ";cout << endl;
        send_packet(vec);
    }
    // cout << "flag2" << endl;
    // mesajin uzunlugunu da yollamak lazim
    int len = sz(M);
    for(int i = 0;i<10;i++){
        M.insert(M.begin() + i , len & (1ll << i));
    }
    // cout << "flag3" << endl;
    // mesaji yolla
    int sayac = 0;
    for(int i = 0;i<sz(M);i++){
        while(C[sayac]){
            sayac = (sayac + 1) % 32;
            if(sayac == 0){
                send_packet(vec);
                vec.assign(31,0);
            }
        }
        vec[sayac] = M[i];
        sayac = (sayac + 1) % 32;
        if(sayac == 0){
            send_packet(vec);
            vec.assign(31,0);
        }
    }
    // cout << "flag4" << endl;
    if(sayac != 0){
        send_packet(vec);
        vec.assign(31,0);
    }
}

vector<bool> receive_message(vector<vector<bool>> R) {
    init();
    // cout << "flag5" << endl;
    // decipheri bul
    for(int i = 0;i<31;i++){
        if(R[0][i]){
            decipher += 1ll << i;
        }
    }
    // cout << "decipher : " << decipher << endl;
    // cout << "flag6" << endl;
    // kleopatralari bul
    vector<bool>cleo(31,0);
    for(int i = 1;i<=epoch;i++){
        for(int j = 0;j<31;j++){
            if(R[i][j] != nxt()){
                cleo[j] = 1;
            }
        }
    }
    // cout << "cleo : ";for(auto itr : cleo)cout << itr << " ";cout << endl;
    // cout << "flag7" << endl;
    // mesajin uzunlugunu bul
    int sayac = 0 , mindx = epoch+1 , len = 0;
    for(int i = 0;i<10;i++){
        while(cleo[sayac]){
            sayac = (sayac + 1) % 32;
            if(sayac == 0)mindx++;
        }
        if(R[mindx][sayac])len += 1 << i;
        sayac = (sayac + 1) % 32;
        if(sayac == 0)mindx++;
    }
    // cout << "len : " << len << endl;
    // cout << "flag8" << endl;
    // mesaji bul
    vector<bool>ret(len);
    for(int i = 0;i<len;i++){
        while(cleo[sayac]){
            sayac = (sayac + 1) % 32;
            if(sayac == 0)mindx++;
        }
        ret[i] = R[mindx][sayac];
        sayac = (sayac + 1) % 32;
        if(sayac == 0)mindx++;
    }
    return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...