답안 #754099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754099 2023-06-06T17:07:09 Z Tekor 앨리스, 밥, 서킷 (APIO23_abc) C++17
24 / 100
487 ms 485660 KB
#include "abc.h"

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define pii pair <int,int>
#define all(v) v.begin(),v.end()
// you may find the definitions useful
const int OP_ZERO    = 0;  // f(OP_ZERO,    x0, x1) = 0
const int OP_NOR     = 1;  // f(OP_NOR,     x0, x1) = !(x0 || x1)
const int OP_GREATER = 2;  // f(OP_GREATER, x0, x1) = (x0 > x1)
const int OP_NOT_X1  = 3;  // f(OP_NOT_X1,  x0, x1) = !x1
const int OP_LESS    = 4;  // f(OP_LESS,    x0, x1) = (x0 < x1)
const int OP_NOT_X0  = 5;  // f(OP_NOT_X0,  x0, x1) = !x0
const int OP_XOR     = 6;  // f(OP_XOR,     x0, x1) = (x0 ^ x1)
const int OP_NAND    = 7;  // f(OP_NAND,    x0, x1) = !(x0 && x1)
const int OP_AND     = 8;  // f(OP_AND,     x0, x1) = (x0 && x1)
const int OP_EQUAL   = 9;  // f(OP_EQUAL,   x0, x1) = (x0 == x1)
const int OP_X0      = 10; // f(OP_X0,      x0, x1) = x0
const int OP_GEQ     = 11; // f(OP_GEQ,     x0, x1) = (x0 >= x1)
const int OP_X1      = 12; // f(OP_X1,      x0, x1) = x1
const int OP_LEQ     = 13; // f(OP_LEQ,     x0, x1) = (x0 <= x1)
const int OP_OR      = 14; // f(OP_OR,      x0, x1) = (x0 || x1)
const int OP_ONE     = 15; // f(OP_ONE,     x0, x1) = 1
const int mod = 65536;

int k;
// Alice
int // returns la
alice(
    /*  in */ const int n,
    /*  in */ const char names[][5],
    /*  in */ const unsigned short numbers[],
    /* out */ bool outputs_alice[]
) {
	k = 0;
	vector <pair <char,pii> >g;
	for(int i = 0;i < n;i++) {
		g.pb(mp(names[i][0],mp(numbers[i],i)));
	}
	sort(all(g));
    for(int i = 0;i < n;i++) {
    	for(int j = 0;j < 16;j++) {
    		if(g[i].s.f & (1 << j))outputs_alice[k++] = 1;
    		else outputs_alice[k++] = 0;
		}
	}
	for(int i = 0;i < n;i++) {
		int val = g[i].s.s;
		for(int j = 0;j < 16;j++) {
			if(val & (1 << j))outputs_alice[k++] = 1;
			else outputs_alice[k++] = 0;
		}
	}
	return k;
}


// Bob
int // returns lb
bob(
    /*  in */ const int m,
    /*  in */ const char senders[][5],
    /*  in */ const char recipients[][5],
    /* out */ bool outputs_bob[]
) {
    int c[30][30];
	k = 0;
    for(int i = 0;i <= 25;i++) {
    	for(int j = 0;j <= 25;j++) {
    		c[i][j] = 0;
		}
	}
	for(int i = 0;i < m;i++) {
		c[senders[i][0] - 'a'][recipients[i][0] - 'a']++;
	}
	for(int i = 0;i <= 25;i++) {
		for(int j = 0;j <= 25;j++) {
			for(int h = 0;h < 16;h++) {
				if(c[i][j] & (1 << h))outputs_bob[k++] = 1;
				else outputs_bob[k++] = 0;
			}
		}
	}
	return k;
}


vector <int> pos,cur;
// Circuit
int // returns l
circuit(
    /*  in */ const int la,
    /*  in */ const int lb,
    /* out */ int operations[],
    /* out */ int operands[][2],
    /* out */ int outputs_circuit[][16]
) {
	k = la + lb;
	int L = 0,n = la / 32;
	for(int i = 0;i < n;i++) {
		pos.pb(k);
		for(int j = 0;j < 16;j++) {
			operations[k] = 10;
			operands[k][0] = L;
			operands[k][1] = L++;
			k++;
		}
	}
	for(int i = 0;i < n;i++) {
		cur.pb(k);
		for(int j = 0;j < 16;j++) {
			operations[k] = 0;
			operands[k][0] = 0;
			operands[k][1] = 0;
			k++;
		}
	}
	L += 16 * n;
	for(int i = 0;i <= 25;i++) {
		for(int j = 0;j <= 25;j++) {
			for(int h = 0;h < 16;h++) {
				for(int pp = 0;pp < 16 - h;pp++) {
					int nL = k + 16 - (h + pp) + 1;
					for(int cc = 0;cc < pp + h;cc++) {
						// = x0
						operations[nL + cc] = 10;
						operands[nL + cc][0] = cur[j] + cc;
						operands[nL + cc][1] = cur[j] + cc;
					}
					// and
					operations[k] = 8; 
					operands[k][0] = pos[i] + pp;
					operands[k][1] = L;
					for(int cc = pp + h;cc < 16;cc++) {
						//xor
						operations[nL + cc] = 6;
						operands[nL + cc][0] = k;
						operands[nL + cc][1] = cur[j] + cc;
						k++;
						operations[k] = 8;
						operands[k][0] = cur[j] + cc;
						operands[k][1] = k - 1;
					}
					k++;
//					if(k != nL) {
//						cout << k << " " << nL;
//						assert(0);
//					}
					k = nL + 16;
					cur[j] = nL;
				}
				L++;
			}
		}
	}
	vector <int> ans;
	for(int i = 0;i < n;i++) {
		ans.pb(k);
		for(int j = 0;j < 16;j++) {
			operations[k] = 0;
			operands[k][0] = 0;
			operands[k][1] = 0;
			k++;
		}
	} 
	for(int i = 0;i < n;i++) {
		for(int j = 0;j < n;j++) {
			int l = 16 * (n + i);
			operations[k] = 15;
			operands[k][0] = 0;
			operands[k][1] = 0;
			k++;
			for(int h = 0;h < 16;h++) {
				if(j & (1 << h)) {
					operations[k] = 8; 
					operands[k][0] = k - 1;
					operands[k][1] = l + h;
					k++;
				}else {
					operations[k] = 3;
					operands[k][0] = l + h;
					operands[k][1] = l + h;
					k++;
					operations[k] = 8;
					operands[k][0] = k - 1;
					operands[k][1] = k - 2;
					k++;
				}
			}
			int last = k - 1;
			int nL = k + 16;
			for(int h = 0;h < 16;h++) {
				operations[k] = 8;
				operands[k][0] = last;
				operands[k][1] = cur[i] + h;
				operations[nL + h] = 6;
				operands[nL + h][0] = ans[j] + h;
				operands[nL + h][1] = k;
				k++;
			}
			assert(k == nL);
			ans[j] = nL;
			k = nL + 16;
		}
	}
	for(int i = 0;i < n;i++) {
		for(int j = 0;j < 16;j++) {
			outputs_circuit[i][j] = ans[i] + j;
		}
	}
	return k;
}    
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 54220 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 54220 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 54220 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 47280 KB Correct!
2 Correct 103 ms 49108 KB Correct!
3 Correct 124 ms 49620 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 47280 KB Correct!
2 Correct 103 ms 49108 KB Correct!
3 Correct 124 ms 49620 KB Correct!
4 Incorrect 112 ms 49100 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 47280 KB Correct!
2 Correct 103 ms 49108 KB Correct!
3 Correct 124 ms 49620 KB Correct!
4 Incorrect 112 ms 49100 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 487 ms 485660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 487 ms 485660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 54220 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -