QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415496 | #6529. Alice, Bob and Circuit | Xiaohuba | 0 | 8ms | 33616kb | C++23 | 8.4kb | 2024-05-20 22:16:03 | 2024-05-20 22:16:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define LOCK_GETCHAR
// #define USE_INT_128
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
template <class T ENABLE_IF_INT>
constexpr T INF = numeric_limits<T>::max() >> 1;
#endif
#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif
#define il inline
#define mkp make_pair
#define fi first
#define se second
#define For(i, j, k) for (decltype(j - k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k) for (decltype(j - k) i = (j); i >= (k); --i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) \
freopen(filename ".in", "r", stdin); \
freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif
// clang-format off
#define lg(x) (31 ^ __builtin_clz((x)))
#define lgll(x) (31ll ^ __builtin_clzll((x)))
template<typename T> constexpr il T sq(const T & x){ return x * x; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y);}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y, T mod){T ans = 1; x %= mod; while (y) { if(y & 1)(ans *= x) %= mod;(x *= x) %= mod; y >>= 1;} return ans;}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y){T ans = 1; while (y) {if(y & 1) ans *= x;x *= x;y >>= 1;} return ans;}
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while(!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while(isdigit(c)) {x = x * 10 + c - '0';c = getchar();} x *= f;}
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x); read(y...); }
int gcd(int a, int b) { if (!a | !b) return a + b; int az = __builtin_ctz(a); int bz = __builtin_ctz(b); int z = min(az, bz); a >>= az, b >>= bz; while (a != b) { int diff = b - a; az = __builtin_ctz(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
ll gcd(ll a, ll b) { if (!a | !b) return a + b; ll az = __builtin_ctzll(a); ll bz = __builtin_ctzll(b); ll z = min(az, bz); a >>= az, b >>= bz; while (a != b) { ll diff = b - a; az = __builtin_ctzll(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
// clang-format on
// File head end
vector<tuple<int, int, int>> Gates;
int cnt = 0, ZERO_BIT = 0, ONE_BIT = -1;
struct Bit {
int _id;
Bit(int _ = 0) : _id(_) {}
bool known() const { return _id == ZERO_BIT || _id == ONE_BIT; }
bool val() const {
assert(this->known());
return _id == ONE_BIT;
}
Bit operator&(const Bit &rhs) const {
if (_id == ZERO_BIT || rhs._id == ZERO_BIT)
return ZERO_BIT;
else if (_id == ONE_BIT || rhs._id == ONE_BIT)
return (_id == ONE_BIT) ? rhs._id : _id;
Gates.eb(_id, rhs._id, 8);
return ++cnt;
}
Bit operator|(const Bit &rhs) const {
if (_id == ONE_BIT || rhs._id == ONE_BIT)
return 1;
else if (_id == ZERO_BIT || rhs._id == ZERO_BIT)
return (_id == ZERO_BIT) ? rhs._id : _id;
Gates.eb(_id, rhs._id, 14);
return ++cnt;
}
Bit operator^(const Bit &rhs) const {
if (_id == ZERO_BIT || rhs._id == ZERO_BIT)
return _id == ZERO_BIT ? rhs._id : _id;
else if (_id == ONE_BIT || rhs._id == ONE_BIT)
return _id == ONE_BIT ? ~rhs : ~*this;
Gates.eb(_id, rhs._id, 6);
return ++cnt;
}
Bit operator~() const {
if (_id == ZERO_BIT)
return ONE_BIT;
else if (_id == ONE_BIT)
return ZERO_BIT;
Gates.eb(_id, 1, 5);
return ++cnt;
}
Bit operator==(const Bit &rhs) const {
if (this->known() && rhs.known())
return (this->val() == rhs.val()) ? ONE_BIT : ZERO_BIT;
Gates.eb(_id, rhs._id, 9);
return ++cnt;
}
};
struct Ushort {
array<Bit, 16> bits;
Ushort operator+(const Ushort &rhs) const {
Ushort res;
Bit carry;
For(i, 0, 15) {
auto tmp = bits[i] ^ rhs.bits[i];
res.bits[i] = tmp ^ carry;
if (i < 15)
carry = (bits[i] & rhs.bits[i]) | (carry & tmp);
}
return res;
}
Ushort check(Bit x) const {
Ushort ans;
For(i, 0, 15) ans.bits[i] = bits[i] & x;
return ans;
}
};
#define _Find(x) \
(lower_bound(names2.begin(), names2.end(), (x)) - names2.begin())
int alice(const int n, const char names[][5], const unsigned short numbers[],
bool outputs_alice[]) {
vector<pair<string, unsigned short>> names2(n);
For(i, 0, n - 1) names2[i] = {names[i], numbers[i]};
sort(names2.begin(), names2.end());
int len = n * 16 + n * 5;
For(i, 0, n - 1) {
For(j, i * 16, i * 16 + 15) {
outputs_alice[j] = (names2[i].se >> (j - i * 16)) & 1;
}
}
For(i, 0, n - 1) {
For(j, i * 5, i * 5 + 4) {
int id = _Find(mkp(string(names[i]), numbers[i]));
outputs_alice[n * 16 + j] = (id >> (j - i * 5)) & 1;
}
}
return len;
}
int bob(const int m, const char senders[][5], const char recipients[][5],
bool outputs_bob[]) {
vector<string> names2;
For(i, 0, m - 1) names2.eb(senders[i]), names2.eb(recipients[i]);
sort(names2.begin(), names2.end());
int len = m * 10;
For(i, 0, m - 1) {
int u = _Find(senders[i]);
int v = _Find(recipients[i]);
For(j, 0, 4) outputs_bob[i * 10 + j] = (u >> i & 1);
For(j, 0, 4) outputs_bob[i * 10 + 5 + j] = (v >> i & 1);
}
return len;
}
int circuit(const int la, const int lb, int operations[], int operands[][2],
int outputs_circuit[][16]) {
Gates.clear(), cnt = la + lb + 1;
operands[la + lb][0] = 0, operands[la + lb][1] = 0,
operations[la + lb] = 0; // zero
operands[la + lb + 1][0] = 0, operands[la + lb + 1][1] = 0,
operations[la + lb + 1] = 15; // one
int n = la / 21, m = lb / 10;
vector<Ushort> ans(n), real_ans(n), num(n);
// array<Bit, 5> ok(n, Bit(ONE_BIT));
For(i, 0, n - 1) For(j, 0, 15) num[i].bits[j] = i * 16 + j;
auto trans = [&](int x) {
array<Bit, 5> ans;
For(i, 0, 4) ans[i] = (x >> i & 1) ? ONE_BIT : ZERO_BIT;
return ans;
};
auto get_and = [&](Bit &x, const array<Bit, 5> &y) {
For(i, 0, 4) x = x & y[i];
};
auto op_equ = [&](const array<Bit, 5> &x, const array<Bit, 5> &y) {
array<Bit, 5> res;
For(i, 0, 4) res[i] = x[i] == y[i];
return res;
};
For(i, 0, m - 1) {
vector<Bit> flg1(n, ONE_BIT), flg2(n, ONE_BIT);
array<Bit, 5> cur1, cur2;
For(j, 0, 4) cur1[j] = Bit(la + i * 10 + j);
For(j, 0, 4) cur2[j] = Bit(la + i * 10 + 5 + j);
For(u, 0, n - 1) { get_and(flg1[u], op_equ(trans(u), cur1)); }
For(v, 0, n - 1) { get_and(flg2[v], op_equ(trans(v), cur2)); }
For(u, 0, n - 1) For(v, 0, n - 1) {
ans[v] = ans[v] + num[u].check(flg1[u] & flg2[v]);
}
}
For(i, 0, n - 1) {
array<Bit, 5> cur1, cur2;
For(j, 0, 4) cur1[i] = n * 16 + i * 5 + j;
For(j, 0, n - 1) {
Bit flg = ONE_BIT;
cur2 = trans(j);
get_and(flg, op_equ(cur1, cur2));
real_ans[i] = real_ans[i] + ans[j].check(flg);
}
}
cnt = la + lb + 2;
for (auto [u, v, f] : Gates) {
if (u == ZERO_BIT)
u = la + lb;
else if (u == ONE_BIT)
u = la + lb + 1;
if (v == ZERO_BIT)
v = la + lb;
else if (v == ONE_BIT)
v = la + lb + 1;
operations[cnt] = f, operands[cnt][0] = u, operands[cnt][1] = v;
cnt++;
}
For(i, 0, n - 1) For(j, 0, 15) outputs_circuit[i][j] =
real_ans[i].bits[j]._id;
return cnt;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4064kb
Manager to Alice
Hello 1 m 24780 nzy 52939 tm 29958 iuj 64676 umeq 3500 shh 4229 y 12233 bq 63191 jzt 56793 t 48748 a 4365 pf 872 dlr 64046 vq 784 pzsc 44311 aaza 2656 y 55455 nru 19207 ic 59468 ztv 18363 ab 20822 ov 61699 yjyx 33953 yv 47740 zj 34266 wvlb 25668 xc 29514 ad 64127 gsd 13272 g 45279 hhlw 6505 ag 18873...
Alice to Manager
235fc77fd78da210d6b5a61b92603c4f 001100110000011000000 110100110111001100000 011000001010111000000 001001010011111100000 001101011011000000000 101000010000100000000 100100111111010000000 111010110110111100000 100110111011101100000 001101100111110100000 101100001000100000000 000101101100000000000 011...
Manager to Bob
Hello 0 Goodbye
Bob to Manager
235fc77fd78da210d6b5a61b92603c4f
Manager to Circuit
Hello 21 0 1 m 24780 nzy 52939 tm 29958 iuj 64676 umeq 3500 shh 4229 y 12233 bq 63191 jzt 56793 t 48748 a 4365 pf 872 dlr 64046 vq 784 pzsc 44311 aaza 2656 y 55455 nru 19207 ic 59468 ztv 18363 ab 20822 ov 61699 yjyx 33953 yv 47740 zj 34266 wvlb 25668 xc 29514 ad 64127 gsd 13272 g 45279 hhlw 6505 ag ...
Circuit to Manager
Circuit Output Finished. WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
Manager to Checker
0
result:
wrong answer WA!
Subtask #2:
score: 0
Skipped
Subtask #3:
score: 0
Skipped
Subtask #4:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 8ms
memory: 33616kb
Manager to Alice
Hello 26 a 3454 b 58767 c 58056 d 35863 e 10993 f 13428 g 44400 h 14808 i 42152 j 41685 k 4945 l 33302 m 37616 n 51927 o 14597 p 52276 q 30489 r 49388 s 61314 t 3571 u 45422 v 36417 w 14325 x 25271 y 54399 z 2849 a 45858 b 2285 c 25181 d 56233 e 46605 f 16378 g 8603 h 57322 i 27711 j 54646 k 43915 l...
Alice to Manager
235fc77fd78da210d6b5a61b92603c4f 011111101011000011110001101001110001001101000111111010000011000110001111010101000010111000101100000011101011010100011011100111000001010100100101101010110100010110001010110010000110100001000001000011110100100111101011010100111010000010011100001011000011001110011000111...
Manager to Bob
Hello 13 r w p c g e v j h q y z m b k x u a i t s l n f d o d g l z c i e k y o u m j n q a b h w s v r f x t p f a x j n g w y e c z q d k m o h b s p t u r l v i d m a g u x e i t l r h c v w s z n b p y k q f o j e l a c s h y d v q j m w t z f i n o g b p r x u k r a v c t j y i p g e x s l z h...
Bob to Manager
235fc77fd78da210d6b5a61b92603c4f 1111100000111111111111111111110000011111000001111100000000000000000000000000000000000000000000000000000000000000000000000000000000 1111100000111110000000000000000000011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000 11111...
Manager to Circuit
Hello 546 130 26 a 3454 b 58767 c 58056 d 35863 e 10993 f 13428 g 44400 h 14808 i 42152 j 41685 k 4945 l 33302 m 37616 n 51927 o 14597 p 52276 q 30489 r 49388 s 61314 t 3571 u 45422 v 36417 w 14325 x 25271 y 54399 z 2849 a 45858 b 2285 c 25181 d 56233 e 46605 f 16378 g 8603 h 57322 i 27711 j 54646 k...
Circuit to Manager
Circuit Output Finished. WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
Manager to Checker
0
result:
wrong answer WA!
Subtask #5:
score: 0
Skipped
Subtask #6:
score: 0
Skipped
Subtask #7:
score: 0
Instance #2 Time Limit Exceeded
Test #12:
score: 0
Instance #2 Time Limit Exceeded
Manager to Alice
Hello 676 aa 3802 ab 7056 ac 59883 ad 34872 ae 7482 af 50954 ag 3033 ah 10947 ai 45175 aj 38968 ak 25809 al 5243 am 51663 an 29607 ao 51746 ap 7026 aq 28678 ar 19365 as 9937 at 50580 au 32268 av 36219 aw 12499 ax 11217 ay 36118 az 42569 ba 27331 bb 61063 bc 46216 bd 42920 be 31324 bf 61604 bg 40272 ...
Alice to Manager
235fc77fd78da210d6b5a61b92603c4f 010110110111000000001001110110001101011110010111000111000001000101011100101110000101000011100011100110111101000011000011010101001110111000001101000111000001100110001011001001101101111000101000111100111001001111100101110011100100010001010011010011101101100001100000000...
Manager to Bob
Hello 997 mx jl jv ck gp fv iu hn cj wo uf ek ox ux ln na yo ss ro zg vx al ji zc zt qi lt vf kk pb hj mm mr fz is jo ym vz ju yt dd oj vm ga xd ww ce is wf ej cv ib ad dp qj pr wn zr al yo gr vi dd vv bm lf ky on gb oh zy oe mf xo cb nv ri pb we cy oh qg xo zq ci mg dy wq cv gy sr vx wo mn jg zs qw...
Bob to Manager
235fc77fd78da210d6b5a61b92603c4f 000001111111111000001111100000000001111111111111111111100000000001111111111000001111111111000001111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Manager to Circuit
Hello 14196 9970
Circuit to Manager
Manager to Checker
result:
Subtask #8:
score: 0
Skipped
Subtask #9:
score: 0
Instance #2 Time Limit Exceeded
Test #16:
score: 0
Instance #2 Time Limit Exceeded
Manager to Alice
Hello 699 wkm 49893 hus 29682 wba 42773 byj 30204 ikc 65421 agqd 20734 fwy 42563 icr 64301 yl 36787 bz 41537 xlka 6691 iq 37001 wij 10013 dfoq 13371 vdy 10291 wpwc 43193 rz 43253 engz 13755 rou 22700 lq 12011 jkn 21719 jleh 57791 olpm 12289 nbqf 57325 vyx 18438 ldgz 10230 ts 50054 odgx 30982 jfst 42...
Alice to Manager
235fc77fd78da210d6b5a61b92603c4f 011111100111011011100001001110100010111111111110001010100110101010000111001111110111111100001010101110000100011011011101010010011010010101000100011011100000110011100011000011000111101001011100100011100100011111000101110011110000101001110101000101111011110011010110100...
Manager to Bob
Hello 999 jrym hpu td ej llf hqoa hlay ej amz ej qr vzvu erf ej mh ej fwj qi dd ej ay ej dbvr lsgs sag ja hop ej vdcc ej wpwc cag la cugy mfbg ern pgj twc qjs byj u ej wwa ej mv ej utwd no swl mvnr pjar agel vnq ipe fp mwh atl lmnb dr ej nufb eqf wsxj wonu hqoa ej rbhe ej l vme ihwn weks kaz il se k...
Bob to Manager
235fc77fd78da210d6b5a61b92603c4f 000000000000000111111111100000000001111111111000001111111111000000000011111000001111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Manager to Circuit
Hello 14679 9990