QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#100587#6347. XOR Determinantczhang2718TL 6ms3384kbC++202.9kb2023-04-26 21:53:082023-04-26 21:53:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-26 21:53:13]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:3384kb
  • [2023-04-26 21:53:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define per(i, b, a) for(int i=b; i>=a; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef pair<int, int> pii;
#define nl '\n'

typedef long long ll;

template <ll Mod>
struct ModInt {
  ll n;

  ModInt(const ll x = 0) : n(x) {
    while (n < 0) n += Mod;
    n %= Mod;
  }
  explicit operator int() const { return n; }
  inline ModInt operator+(const ModInt r) const noexcept { return ModInt(*this) += r; }
  inline ModInt operator-(const ModInt r) const noexcept { return ModInt(*this) -= r; }
  inline ModInt operator*(const ModInt r) const noexcept { return ModInt(*this) *= r; }
  inline ModInt operator/(const ModInt r) const noexcept { return ModInt(*this) /= r; }
  inline ModInt &operator+=(const ModInt r) noexcept {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  inline ModInt &operator-=(const ModInt r) noexcept {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  inline ModInt &operator*=(const ModInt r) noexcept {
    n = n * r.n % Mod;
    return *this;
  }
  inline ModInt &operator/=(const ModInt r) noexcept { return *this *= r.inv(); }

  inline ModInt pow(ll x) const noexcept {
    ModInt<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  inline ModInt inv() const noexcept { return pow(Mod-2); }

  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) {
    ll t;
    is >> t;
    obj = ModInt(t);
    return is;
  }
};
const ll mod = 998244353; //check!
using mi = ModInt<mod>;
mi operator"" _mi(unsigned long long n) { return mi(n); }

int t, n;

signed main(){
  cin.tie(0)->sync_with_stdio(0);

  cin >> t;
  while(t--){
    cin >> n;
    vector<ll> a(n), b(n);
    for(ll &x:a) cin >> x;
    for(ll &x:b) cin >> x;

    if(n>60){
      cout << "0\n";
      continue;
    }

    vector<vector<mi>> c(n, vector<mi>(n));
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        c[i][j]=a[i]^b[j];
      }
    }
    
    mi det=1;
    for(int i=0; i<n; i++){
      // rep(i,0,n-1){
      //   rep(j,0,n-1){
      //     cout << c[i][j] << " ";
      //   }
      //   cout << nl;
      // }
      int k=i;
      while(k<n && !int(c[k][i])) k++;
      if(k==n){
        det=0;
        break;
      }
      // cout << "k " << k << " " << c[k][i] << nl;
      if(k!=i) det=mi(-1)*det;
      swap(c[k], c[i]);
      det*=c[i][i];
      k=i;
      while(++k<n){
        for(int j=n-1; j>=i; j--) c[k][j]-=c[i][j]/c[i][i]*c[k][i];
      }
    }
    cout << det << nl;
  }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3332kb

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: 0
Accepted
time: 2ms
memory: 3284kb

input:

1
5
1 2 3 4 5
1 2 3 4 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 6ms
memory: 3384kb

input:

100
10
1107560013855173757 966681903163989710 521892103913129269 1038348664970462356 604430971757857481 1106581500345020431 788162934600883665 124672524392773463 534904853987097709 784497626701360420
402515001559379490 846591944896429860 761680713769800085 722846292535048189 621369111578909792 49581...

output:

548320033
488137899
509538360
732652365
956551480
888843023
560651618
189658616
667887492
788885505
155196573
934158515
897579513
928218896
846866262
443345610
390799518
148725345
892245870
273938687
487734460
478338536
258981818
853512398
952636045
406224138
199504048
631337716
29490784
62730160
94...

result:

ok 100 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

181
55
259826570151423127 58870406144128000 310271049587997524 401710073886773698 514286909385841735 162284846714225243 536074036455895273 265892726370365687 1083624247485293743 2294265759278634 1109697269509916767 119509764279027081 676809147172263541 685533985118893838 578164705093722225 749670267...

output:


result: