#include "Annalib.h"
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << '\n'
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
!is_same<T_container, string>::value,
typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
os << '[';
string sep;
for (const T &x : v) os << sep << x, sep = ", ";
return os << ']';
}
namespace ModInt { //{{{
template<int MOD>
struct mod_int {
int val;
operator int() const { return val; }
mod_int() : val(0) {}
mod_int(int _val) : val(_val % MOD) {}
mod_int operator+() const {
return mod_int(val);
}
mod_int operator-() const {
return mod_int(MOD-val);
}
mod_int inverse() const {
assert(val != 0);
return *this ^ (MOD - 2);
}
mod_int& operator+=(const mod_int& b) {
val += b.val;
if (val >= MOD) val -= MOD;
return *this;
}
mod_int& operator-=(const mod_int& b) {
return *this += -b;
}
mod_int& operator*=(const mod_int& b) {
val = (1LL*val*b.val) % MOD;
return *this;
}
mod_int& operator/=(const mod_int& b) {
val = (1LL*val*b.inverse().val) % MOD;
return *this;
}
mod_int& operator+=(int b) {
return *this += mod_int(b);
}
mod_int& operator-=(int b) {
return *this -= mod_int(b);
}
mod_int& operator*=(int b) {
return *this *= mod_int(b);
}
mod_int& operator/=(int b) {
return *this /= mod_int(b);
}
friend mod_int operator+(const mod_int& a, const mod_int& b) {
mod_int c = a; c += b;
return c;
}
friend mod_int operator-(const mod_int& a, const mod_int& b) {
mod_int c = a; c -= b;
return c;
}
friend mod_int operator*(const mod_int& a, const mod_int& b) {
mod_int c = a; c *= b;
return c;
}
friend mod_int operator/(const mod_int& a, const mod_int& b) {
mod_int c = a; c /= b;
return c;
}
friend mod_int operator+(const mod_int& a, int b) {
return a + mod_int(b);
}
friend mod_int operator-(const mod_int& a, int b) {
return a - mod_int(b);
}
friend mod_int operator*(const mod_int& a, int b) {
return a * mod_int(b);
}
friend mod_int operator/(const mod_int& a, int b) {
return a / mod_int(b);
}
friend mod_int operator+(int a, const mod_int& b) {
return mod_int(a) + b;
}
friend mod_int operator-(int a, const mod_int& b) {
return mod_int(a) - b;
}
friend mod_int operator*(int a, const mod_int& b) {
return mod_int(a) * b;
}
friend mod_int operator/(int a, const mod_int& b) {
return mod_int(a) / b;
}
friend mod_int operator^(mod_int a, int b) {
mod_int res(1);
while (b > 0) {
if (b&1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
friend ostream& operator<<(ostream& o, const mod_int& x) {
return o << x.val;
};
friend istream& operator>>(istream& i, mod_int& x) {
return i >> x.val;
}
};
} //}}}
using mint = ModInt::mod_int<2>;
int gauss (vector<vector<mint>> a, vector<mint> & ans) {
int n = (int) a.size();
int m = (int) a[0].size() - 1;
vector<int> where (m, -1);
for (int col=0, row=0; col<m && row<n; ++col) {
int sel = row;
for (int i=row; i<n; ++i)
if (a[i][col] > a[sel][col])
sel = i;
if (a[sel][col] == 0)
continue;
for (int i=col; i<=m; ++i)
swap (a[sel][i], a[row][i]);
where[col] = row;
for (int i=0; i<n; ++i)
if (i != row) {
assert(a[row][col] == 1);
// mint c = a[i][col] / a[row][col];
mint c = a[i][col];
for (int j=col; j<=m; ++j)
a[i][j] -= a[row][j] * c;
}
++row;
}
ans.assign (m, 0);
for (int i=0; i<m; ++i)
if (where[i] != -1)
ans[i] = a[where[i]][m] / a[where[i]][i];
for (int i=0; i<n; ++i) {
mint sum = 0;
for (int j=0; j<m; ++j)
sum += ans[j] * a[i][j];
if (sum - a[i][m] > 0)
return 0;
}
for (int i=0; i<m; ++i)
if (where[i] == -1)
return 2;
return 1;
}
void Anna( int N, long long X, int K, int P[] ){
std::mt19937 rng(6969);
const int MX = 60;
int A[MX][N];
for (int i = 0; i < MX; i++) {
for (int j = 0; j < N; j++) {
A[i][j] = rng() & 1;
}
}
vector<bool> broken(N, false);
for (int i = 0; i < K; i++) broken[P[i]] = true;
vector<vector<mint>> a(MX, vector<mint>(N+1, 0));
for (int j = 0; j < N; j++) {
if (broken[j]) continue;
for (int i = 0; i < MX; i++) a[i][j] = A[i][j];
}
for (int i = 0; i < MX; i++) a[i][N] = (X >> i) & 1;
vector<mint> ans(N);
int sol = gauss(a, ans);
assert(sol > 0);
for( int i = 0; i < N; i++ ){
if (broken[i]) Set(i, 0);
else Set(i, ans[i]);
}
}
#include "Brunolib.h"
#include <bits/stdc++.h>
using namespace std;
long long Bruno( int N, int A[] ){
std::mt19937 rng(6969);
const int MX = 60;
int B[MX][N];
for (int i = 0; i < MX; i++) {
for (int j = 0; j < N; j++) {
B[i][j] = rng() & 1;
}
}
long long ans = 0;
for (int j = 0; j < N; j++) if (A[j]) {
for (int i = 0; i < MX; i++) {
if (B[i][j]) ans ^= 1LL << i;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
2712 KB |
Output is correct - L* = 40 |
2 |
Correct |
731 ms |
2680 KB |
Output is correct - L* = 40 |
3 |
Correct |
739 ms |
2644 KB |
Output is correct - L* = 40 |
4 |
Correct |
731 ms |
2708 KB |
Output is correct - L* = 40 |
5 |
Correct |
747 ms |
2768 KB |
Output is correct - L* = 40 |
6 |
Correct |
732 ms |
2852 KB |
Output is correct - L* = 40 |
7 |
Correct |
725 ms |
2664 KB |
Output is correct - L* = 40 |
8 |
Correct |
761 ms |
2936 KB |
Output is correct - L* = 40 |
9 |
Correct |
718 ms |
2652 KB |
Output is correct - L* = 40 |
10 |
Correct |
831 ms |
2736 KB |
Output is correct - L* = 40 |
11 |
Correct |
733 ms |
2680 KB |
Output is correct - L* = 40 |
12 |
Correct |
742 ms |
2788 KB |
Output is correct - L* = 40 |
13 |
Correct |
779 ms |
2668 KB |
Output is correct - L* = 40 |
14 |
Correct |
730 ms |
2712 KB |
Output is correct - L* = 40 |
15 |
Correct |
709 ms |
2664 KB |
Output is correct - L* = 40 |
16 |
Correct |
749 ms |
2636 KB |
Output is correct - L* = 40 |
17 |
Correct |
728 ms |
2800 KB |
Output is correct - L* = 40 |
18 |
Correct |
711 ms |
2968 KB |
Output is correct - L* = 40 |
19 |
Correct |
739 ms |
2768 KB |
Output is correct - L* = 40 |
20 |
Correct |
720 ms |
2736 KB |
Output is correct - L* = 40 |
21 |
Correct |
733 ms |
2688 KB |
Output is correct - L* = 40 |
22 |
Correct |
718 ms |
2864 KB |
Output is correct - L* = 40 |
23 |
Correct |
714 ms |
2660 KB |
Output is correct - L* = 40 |
24 |
Correct |
716 ms |
2864 KB |
Output is correct - L* = 40 |
25 |
Correct |
718 ms |
2884 KB |
Output is correct - L* = 40 |
26 |
Correct |
727 ms |
2636 KB |
Output is correct - L* = 40 |
27 |
Correct |
711 ms |
2764 KB |
Output is correct - L* = 40 |
28 |
Correct |
725 ms |
2744 KB |
Output is correct - L* = 40 |
29 |
Correct |
714 ms |
2752 KB |
Output is correct - L* = 40 |
30 |
Correct |
718 ms |
2744 KB |
Output is correct - L* = 40 |
31 |
Correct |
734 ms |
2812 KB |
Output is correct - L* = 40 |
32 |
Correct |
719 ms |
2824 KB |
Output is correct - L* = 40 |
33 |
Correct |
722 ms |
2808 KB |
Output is correct - L* = 40 |
34 |
Correct |
773 ms |
2892 KB |
Output is correct - L* = 40 |
35 |
Correct |
715 ms |
2728 KB |
Output is correct - L* = 40 |
36 |
Correct |
725 ms |
2660 KB |
Output is correct - L* = 40 |
37 |
Correct |
713 ms |
2696 KB |
Output is correct - L* = 40 |
38 |
Correct |
736 ms |
2660 KB |
Output is correct - L* = 40 |
39 |
Correct |
707 ms |
2692 KB |
Output is correct - L* = 40 |
40 |
Correct |
720 ms |
2704 KB |
Output is correct - L* = 40 |