QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137129 | #6347. XOR Determinant | berarchegas# | RE | 2ms | 5544kb | C++17 | 3.0kb | 2023-08-09 22:22:42 | 2023-08-09 22:22:46 |
Judging History
answer
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <random>
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
const int maxn = 2*100000 + 10;
// const int inf = 1000000000;
// const ll inf = 1000000000000000000LL;
const ll mod = 998244353;
// const ll mod = 1000000007; // 10^9 + 7
int n;
ll b[maxn], c[maxn];
ll inv(ll v) { return v == 1 ? 1 : ( (mod - mod/v)*inv(mod%v) )%mod; }
ll det(vector< vector<ll> >& a)
{
// int n = sz(a); double res = 1;
// rep(i,0,n) {
// int b = i;
// rep(j,i+1,n) if (fabs(a[j][i]) > fabs(a[b][i])) b = j;
// if (i != b) swap(a[i], a[b]), res *= -1;
// res *= a[i][i];
// if (res == 0) return 0;
// rep(j,i+1,n) {
// double v = a[j][i] / a[i][i];
// if (v != 0) rep(k,i+1,n) a[j][k] -= v * a[i][k];
// }
// }
// return res;
ll res = 1;
for(int i = 0 ; i < n ; i++)
{
int b = i;
for(int j = i + 1 ; j < n ; j++)
if( a[j][i] > a[b][i] ) b = j;
if( i != b )
swap( a[i] , a[b] ), res = mod - res;
res *= a[i][i]; res %= mod;
ll curInv = inv( a[i][i] );
if( res == 0 )
return 0;
for(int j = i + 1 ; j < n ; j++)
{
ll v = a[j][i]*curInv; v %= mod;
for(int k = i + 1 ; k < n && v != 0 ; k++)
{
a[j][k] -= v*a[i][k];
a[j][k] %= mod;
a[j][k] = (mod + a[j][k])%mod;
}
}
}
return res;
}
void solve(int testcase)
{
cin >> n;
for(int i = 1 ; i <= n ; i++)
cin >> b[i];
for(int i = 1 ; i <= n ; i++)
cin >> c[i];
if( n >= 70 )
{
cout << 0 << endl;
return;
}
vector< vector<ll> > a(n, vector<ll>(n, 0));
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
a[i][j] = (b[i + 1]^c[j + 1])%mod;
cout << det(a) << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
for(int testcase = 1 ; testcase <= t ; testcase++)
solve( testcase );
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5544kb
input:
3 2 2 5 4 1 1 1000000000000000001 987467354324283836 4 1 2 3 4 1 2 3 4
output:
21 214139910 998244129
result:
ok 3 number(s): "21 214139910 998244129"
Test #2:
score: -100
Runtime Error
input:
1 5 1 2 3 4 5 1 2 3 4 5