QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185468#4907. djq 学生物hos_lyric#50 1058ms9816kbC++146.8kb2023-09-22 08:18:082024-07-04 02:06:36

Judging History

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

  • [2024-07-04 02:06:36]
  • 管理员手动重测该提交记录
  • 测评结果:50
  • 用时:1058ms
  • 内存:9816kb
  • [2023-09-22 08:18:08]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


// solution: a[j][n]
bool solveEq(vector<vector<Mint>> &a) {
  const int n = a.size();
  for (int h = 0; h < n; ++h) {
    for (int i = h; i < n; ++i) if (a[i][h]) {
      swap(a[h], a[i]);
      break;
    }
    if (!a[h][h]) return false;
    const Mint s = a[h][h].inv();
    for (int j = h + 1; j <= n; ++j) a[h][j] *= s;
    for (int i = h + 1; i < n; ++i) {
      for (int j = h + 1; j <= n; ++j) a[i][j] -= a[i][h] * a[h][j];
    }
  }
  for (int i = n; --i >= 0; ) {
    for (int j = i + 1; j < n; ++j) a[i][n] -= a[i][j] * a[j][n];
  }
  return true;
}


int SIX[9];
int INV[6], MUL[6][6];

int N;
vector<Mint> C;
Mint M, invM;


/*
  Pr[u -> v] = (1/M) [u = v] + \sum[i] (C[i]/M) Pr[u i -> v]
  ans[v] = Pr[0 -> v]
  
  Pr[u -> v] =: f(v^-1 u)
  f(u) = (1/M) [u = id] + \sum[i] (C[i]/M) f(u i)
  ans[v] = f(v^-1)
*/
namespace brute {
vector<Mint> run() {
  vector<vector<Mint>> a(SIX[N], vector<Mint>(SIX[N] + 1, 0));
  a[0][SIX[N]] += invM;
  for (int u = 0; u < SIX[N]; ++u) {
    a[u][u] += 1;
    for (int i = 0; i < SIX[N]; ++i) {
      int v = 0;
      for (int e = 0; e < N; ++e) {
        const int p = u / SIX[e] % 6;
        const int q = i / SIX[e] % 6;
        v += MUL[p][q] * SIX[e];
      }
// if(C[i])cerr<<u<<" "<<i<<": "<<v<<endl;
      a[u][v] -= invM * C[i];
    }
  }
// for(int u=0;u<SIX[N];++u)cerr<<a[u]<<endl;
  const bool res = solveEq(a);
  if (res) {
    vector<Mint> ans(SIX[N]);
    for (int u = 0; u < SIX[N]; ++u) {
      ans[u] = a[u][SIX[N]];
    }
    return ans;
  } else {
    return {};
  }
}
}  // brute


int main() {
  SIX[0] = 1;
  for (int e = 1; e < 9; ++e) SIX[e] = SIX[e - 1] * 6;
cerr<<"SIX = ";pv(SIX,SIX+9);
  {
    vector<vector<int>> perms;
    {
      vector<int> perm{0, 1, 2};
      do {
        perms.push_back(perm);
      } while (next_permutation(perm.begin(), perm.end()));
    }
    map<vector<int>, int> tr;
    for (int p = 0; p < 6; ++p) {
      tr[perms[p]] = p;
    }
    for (int p = 0; p < 6; ++p) {
      vector<int> perm(3);
      for (int i = 0; i < 3; ++i) {
        perm[perms[p][i]] = i;
      }
      INV[p] = tr[perm];
    }
    for (int p = 0; p < 6; ++p) for (int q = 0; q < 6; ++q) {
      vector<int> perm(3);
      for (int i = 0; i < 3; ++i) {
        perm[i] = perms[p][ perms[q][i] ];
      }
      MUL[p][q] = tr[perm];
    }
  }
cerr<<"INV = ";pv(INV,INV+6);
for(int p=0;p<6;++p){cerr<<"MUL["<<p<<"] = ";pv(MUL[p],MUL[p]+6);}
  
  for (; ~scanf("%d", &N); ) {
    C.resize(SIX[N]);
    for (int i = 0; i < SIX[N]; ++i) {
      scanf("%u", &C[i].x);
    }
    
    M = 1;
    for (int i = 0; i < SIX[N]; ++i) {
      M += C[i];
    }
    assert(M);
    invM = Mint(M).inv();
    
    const auto ans = brute::run();
#ifdef LOCAL
cerr<<"ans = "<<ans<<endl;
#endif
    if (!ans.empty()) {
      unsigned key = 0;
      for (int u = 0; u < SIX[N]; ++u) {
        key ^= ans[u].x;
      }
      printf("%u\n", key);
    } else {
      puts("-1");
    }
  }
  return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3808kb

input:

1
10 10 10 10 499122217 499122156

output:

-1

result:

ok 1 number(s): "-1"

Test #2:

score: 10
Accepted
time: 1ms
memory: 3752kb

input:

1
719885386 651516139 596516649 191397068 26958009 352245674

output:

320270701

result:

ok 1 number(s): "320270701"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3720kb

input:

1
783368690 104275706 48409057 969269573 366936187 542139073

output:

252144401

result:

ok 1 number(s): "252144401"

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #4:

score: 20
Accepted
time: 1ms
memory: 3980kb

input:

2
304089172 305211383 35005211 521595368 294702567 728712076 336465782 861021530 278722862 233665123 148685361 468703135 103269576 803735449 317389669 635723058 370888716 127653814 61717040 92529750 628175011 658233689 132931876 655133020 859484421 916300566 608413784 756898537 736330845 975349971 1...

output:

396724238

result:

ok 1 number(s): "396724238"

Test #5:

score: 20
Accepted
time: 0ms
memory: 3724kb

input:

2
913515603 749241873 137806862 42999170 982906996 135497281 511702305 87932219 939232731 829091974 572660336 160882152 805750846 634377376 102416960 435681504 143371771 84353895 939819582 4611839 2410108 549989014 610515434 587746011 376099690 760313750 478926734 356426808 945117276 891702825 78245...

output:

870050121

result:

ok 1 number(s): "870050121"

Test #6:

score: 20
Accepted
time: 6ms
memory: 3912kb

input:

3
57511226 265850707 413305323 845749015 943947739 985965659 855636226 751454233 471103741 958053186 37896442 463480570 44162728 977716025 317097467 893822248 378465744 927612902 332328964 603570492 689682299 660260756 959997301 485560280 402724286 593209441 196709512 894429689 364228444 949102266 2...

output:

315521842

result:

ok 1 number(s): "315521842"

Test #7:

score: 20
Accepted
time: 6ms
memory: 4112kb

input:

3
349517445 588219756 858424826 59174065 995706887 824845059 66858995 625032172 387451659 471017656 564157983 298625210 296921989 59223234 801633853 557074948 382697713 476667372 72330968 260401255 296864819 774044599 697517721 4741198 952711586 337695458 798829587 758671314 67067352 719346228 84681...

output:

927050034

result:

ok 1 number(s): "927050034"

Subtask #3:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

7
13237606 0 0 696947386 879320747 0 0 0 0 0 0 0 0 0 0 0 0 0 266959993 0 0 371358373 632390641 0 666960563 0 0 708812199 564325578 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 299649176 0...

output:


result:


Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #12:

score: 20
Accepted
time: 1058ms
memory: 9808kb

input:

4
887790043 739693399 870246744 301313259 18507681 629005716 67544354 58092673 642897565 70732414 899481125 727551664 871859472 220238086 708355050 385234243 645860416 129326472 850844210 577801468 684900507 461005014 934205121 591855867 526169505 197643478 136123938 67642730 682939149 949635706 281...

output:

602449578

result:

ok 1 number(s): "602449578"

Test #13:

score: 20
Accepted
time: 1010ms
memory: 9816kb

input:

4
557598958 113906113 211073291 59019633 110287605 318903034 307171270 201167854 142201998 886457896 24068541 289099056 55884864 35794579 11689085 615385706 684842316 559228752 366244387 646068652 535314708 313739657 846826781 931109365 759018899 574643185 553946098 150095139 137782333 741636661 949...

output:

37335981

result:

ok 1 number(s): "37335981"

Test #14:

score: 20
Accepted
time: 1026ms
memory: 9816kb

input:

4
376545129 990894084 275573387 559810624 528344836 360116901 406141975 630960645 550842736 709965265 690253412 98881522 427656896 104902833 504114740 620019063 359704636 908644219 755230881 459810186 435557594 214555147 965394547 449697679 122566226 581267354 68455475 593798485 142522444 164230614 ...

output:

75788971

result:

ok 1 number(s): "75788971"

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%