Submission #298223

#TimeUsernameProblemLanguageResultExecution timeMemory
298223shayan_pVision Program (IOI19_vision)C++17
100 / 100
18 ms1536 KiB
#include<bits/stdc++.h>
#include "vision.h"

#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int LOG = 9; // kam tare!
const int maxn = 210;

int counter;

int MY_LOG;

vector<int> operator + (vector<int> a, vector<int> b){
    vector<int> ans;
    int ext = -1;
    for(int i = 0; i < max(sz(a), sz(b)); i++){
	vector<int> sm;
	if(ext != -1)
	    sm.PB(ext);
	if(i < sz(a))
	    sm.PB(a[i]);
	if(i < sz(b))
	    sm.PB(b[i]);
	ans.PB(counter++);
	add_xor(sm);

	vector<int> toOr;
	for(int w = 0; w < sz(sm); w++)
	    for(int w2 = w+1; w2 < sz(sm); w2++){
		vector<int> chert = {sm[w], sm[w2]};
		toOr.PB(counter++);
		add_and(chert);
	    }
	if(toOr.empty()){
	    ext = -1;
	}
	else{
	    ext = counter++;
	    add_or(toOr);
	}
    }
    if(ext != -1)
	ans.PB(ext);
    while(sz(ans) > MY_LOG)
	ans.pop_back();
    return ans;
}

vector<int> solve(vector<int> &toSum, int l, int r){
    vector<int> ans;
    if(r-l == 1){
	ans.PB(toSum[l]);
	return ans;
    }
    int mid = (l+r) >> 1;
    vector<int> A = solve(toSum, l, mid), B = solve(toSum, mid, r);
    MY_LOG = 32 - __builtin_clz(r-l);
    ans = A + B;
    return ans;
}

int rows[maxn], cols[maxn];

void construct_network(int H, int W, int K){
    auto to = [&](int x, int y){
		  return x * W + y;
	      };
    counter = H * W;
    for(int i = 0; i < H; i++){
	vector<int> chert;
	for(int j = 0; j < W; j++)
	    chert.PB(to(i, j));
	rows[i] = counter++;
	add_xor(chert);
    }
    for(int j = 0; j < W; j++){
	vector<int> chert;
	for(int i = 0; i < H; i++)
	    chert.PB(to(i, j));
	cols[j] = counter++;
	add_xor(chert);
    }

    vector<int> toSum;
    
    int Nw = -1;
    for(int i = 0; i < H; i++){
	if(Nw == -1){
	    Nw = rows[i];
	}
	else{
	    vector<int> chert = {Nw, rows[i]};
	    Nw = counter++;
	    add_xor(chert);
	}
	toSum.PB(Nw);
    }

    Nw = -1;
    for(int j = 0; j < W; j++){
	if(Nw == -1){
	    Nw = cols[j];
	}
	else{
	    vector<int> chert = {Nw, cols[j]};
	    Nw = counter++;
	    add_xor(chert);
	}
	toSum.PB(Nw);
    }

    vector<int> sum = solve(toSum, 0, sz(toSum));

    bool bad = 0;
    for(int i = 0; i < LOG; i++){
	if(bit(K, i)){
	    bad|= sz(sum) <= i;
	}
	else if(sz(sum) > i){
	    add_not(sum[i]);
	    sum[i] = counter++;
	}
    }
    add_and(sum);
    counter++;

    if(bad){
	add_not(0);
	counter++;
	vector<int> chert = {0, counter-1, counter-2};
	add_and(chert);
    }    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...