QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185984 | #4907. djq 学生物 | hos_lyric | 100 ✓ | 752ms | 17564kb | C++14 | 8.4kb | 2023-09-22 22:22:41 | 2023-09-22 22:22:42 |
Judging History
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>;
vector<vector<Mint>> inverse(vector<vector<Mint>> a) {
const int n = a.size();
vector<vector<Mint>> b(n, vector<Mint>(n, 0));
for (int i = 0; i < n; ++i) b[i][i] = 1;
for (int h = 0; h < n; ++h) {
for (int i = h; i < n; ++i) if (a[i][h]) {
swap(a[h], a[i]);
swap(b[h], b[i]);
break;
}
// assert(a[h][h]);
if (!a[h][h]) return {};
const Mint s = a[h][h].inv();
for (int j = h + 1; j < n; ++j) a[h][j] *= s;
for (int j = 0; j < n; ++j) b[h][j] *= s;
for (int i = h + 1; i < n; ++i) {
const Mint t = a[i][h];
if (t) {
for (int j = h + 1; j < n; ++j) a[i][j] -= t * a[h][j];
for (int j = 0; j < n; ++j) b[i][j] -= t * b[h][j];
}
}
}
for (int h = n; --h >= 0; ) for (int i = 0; i < h; ++i) {
const Mint t = a[i][h];
if (t) for (int j = 0; j < n; ++j) b[i][j] -= t * b[h][j];
}
return b;
}
/*
Pr[u -> v] = (1/M) [u = v] + \sum[i] (C[i]/M) Pr[u i -> v]
ans[v] = Pr[id -> v]
Pr[u -> v] = ans[u^-1 v]
ans[u^-1 v] = (1/M) [u = v] + \sum[i] (C[i]/M) ans[i^-1 u^-1 v]
ans[u] = (1/M) [u = i] + \sum[i] (C[i]/M) ans[i^-1 u]
ans = (1/M) + (C/M) * ans
ans = (M - C)^-1
K[S_3] \cong K * K * Mat_2(K)
trivial representation
p -> 1
sign representation
p -> sgn(p)
standard representation
V = {(x[0], x[1], x[2]) | x[0] + x[1] + x[2] = 0}
p: (x[0], x[1], x[2]) -> (x[p[0]], x[p[1]], x[p[2]])
basis: ((1, 0, -1), (0, 1, -1))
*/
// 012, 021, 102, 120, 201, 210
constexpr int W[6][6] = {
// trivial
{1, 1, 1, 1, 1, 1},
// sign
{+1, -1, -1, +1, +1, -1},
// standard
{1, 1, 0, 0, -1, -1}, {0, 0, 1, 1, -1, -1},
{0, -1, 1, -1, 1, 0}, {1, -1, 0, -1, 0, 1},
};
// 6 W^-1
constexpr int INV_W[6][6] = {
{1, 1, 2, 0, 0, 2},
{1, -1, 2, -2, 0, -2},
{1, -1, 0, 2, 2, 0},
{1, 1, -2, 2, -2, 0},
{1, 1, 0, -2, 2, -2},
{1, -1, -2, 0, -2, 2},
};
constexpr int MAX_N = 8;
int SIX[MAX_N + 1];
int N;
vector<Mint> C;
int main() {
SIX[0] = 1;
for (int e = 1; e <= MAX_N; ++e) SIX[e] = SIX[e - 1] * 6;
cerr<<"SIX = ";pv(SIX,SIX+MAX_N+1);
for (; ~scanf("%d", &N); ) {
C.resize(SIX[N]);
for (int i = 0; i < SIX[N]; ++i) {
scanf("%u", &C[i].x);
}
Mint M = 1;
for (int i = 0; i < SIX[N]; ++i) {
M += C[i];
}
vector<Mint> cs(SIX[N], 0);
cs[0] += M;
for (int i = 0; i < SIX[N]; ++i) {
cs[i] -= C[i];
}
// DFT
for (int e = 0; e < N; ++e) {
for (int i = 0; i < SIX[N]; i += SIX[e + 1]) {
for (int j = 0; j < SIX[e]; ++j) {
Mint fs[6], gs[6];
for (int p = 0; p < 6; ++p) fs[p] = cs[i + j + p * SIX[e]];
fill(gs, gs + 6, 0);
for (int p = 0; p < 6; ++p) for (int q = 0; q < 6; ++q) gs[p] += W[p][q] * fs[q];
for (int p = 0; p < 6; ++p) cs[i + j + p * SIX[e]] = gs[p];
}
}
}
// pointwise inv
int ids[1 << MAX_N][1 << MAX_N];
for (int i = 0; i < SIX[N]; ++i) {
int ps[MAX_N];
for (int e = 0; e < N; ++e) {
ps[e] = i / SIX[e] % 6;
}
if (*max_element(ps, ps + N) < 3) {
int esLen = 0;
int es[MAX_N];
for (int e = 0; e < N; ++e) if (ps[e] == 2) {
es[esLen++] = e;
}
vector<vector<Mint>> a(1 << esLen, vector<Mint>(1 << esLen));
for (int x = 0; x < 1 << esLen; ++x) for (int y = 0; y < 1 << esLen; ++y) {
int &ii = ids[x][y];
ii = i;
for (int j = 0; j < esLen; ++j) {
if (x & 1 << j) ii += 2 * SIX[es[j]];
if (y & 1 << j) ii += SIX[es[j]];
}
a[x][y] = cs[ii];
}
a = inverse(a);
if (a.empty()) {
goto failed;
}
for (int x = 0; x < 1 << esLen; ++x) for (int y = 0; y < 1 << esLen; ++y) {
cs[ids[x][y]] = a[x][y];
}
}
}
// inverse DFT
for (int e = 0; e < N; ++e) {
for (int i = 0; i < SIX[N]; i += SIX[e + 1]) {
for (int j = 0; j < SIX[e]; ++j) {
Mint fs[6], gs[6];
for (int p = 0; p < 6; ++p) fs[p] = cs[i + j + p * SIX[e]];
fill(gs, gs + 6, 0);
for (int p = 0; p < 6; ++p) for (int q = 0; q < 6; ++q) gs[p] += INV_W[p][q] * fs[q];
for (int p = 0; p < 6; ++p) cs[i + j + p * SIX[e]] = gs[p];
}
}
}
{
const Mint invSix = Mint(SIX[N]).inv();
unsigned key = 0;
for (int i = 0; i < SIX[N]; ++i) {
cs[i] *= invSix;
key ^= cs[i].x;
}
// cerr<<"cs = "<<cs<<endl;
printf("%u\n", key);
}
continue;
failed:{}
puts("-1");
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3764kb
input:
1 10 10 10 10 499122217 499122156
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
1 719885386 651516139 596516649 191397068 26958009 352245674
output:
320270701
result:
ok 1 number(s): "320270701"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3952kb
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: 0ms
memory: 3940kb
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: 0
Accepted
time: 1ms
memory: 4000kb
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: 0
Accepted
time: 1ms
memory: 3952kb
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: 0
Accepted
time: 1ms
memory: 3996kb
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: 15
Accepted
Test #8:
score: 15
Accepted
time: 95ms
memory: 6000kb
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:
101942575
result:
ok 1 number(s): "101942575"
Test #9:
score: 0
Accepted
time: 688ms
memory: 17564kb
input:
8 114962507 0 0 952617546 783387964 0 0 0 0 0 0 0 0 0 0 0 0 0 950188130 0 0 79845349 400660703 0 865722684 0 0 186015033 757001842 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 563538995 0...
output:
976515923
result:
ok 1 number(s): "976515923"
Test #10:
score: 0
Accepted
time: 678ms
memory: 17536kb
input:
8 125443968 0 0 825927837 967844197 0 0 0 0 0 0 0 0 0 0 0 0 0 128726374 0 0 893763697 934490504 0 811156183 0 0 90656766 98645533 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 858436076 0 ...
output:
660528054
result:
ok 1 number(s): "660528054"
Test #11:
score: 0
Accepted
time: 700ms
memory: 17560kb
input:
8 553951831 0 0 3610932 151003694 0 0 0 0 0 0 0 0 0 0 0 0 0 239318443 0 0 408922789 79644945 0 59445445 0 0 144621393 336045244 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 329064496 0 0 ...
output:
355824768
result:
ok 1 number(s): "355824768"
Subtask #4:
score: 20
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 20
Accepted
time: 0ms
memory: 3988kb
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: 0
Accepted
time: 0ms
memory: 3988kb
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: 0
Accepted
time: 1ms
memory: 3956kb
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: 35
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #15:
score: 35
Accepted
time: 3ms
memory: 4076kb
input:
5 927227492 433462495 682484392 792453283 515614277 572882205 869882034 134859027 597519975 814230265 964334366 928235854 270932934 360466938 859244355 704701658 346892037 476472729 774188464 647828172 144729335 72341130 766681749 361690425 376034039 468002144 849139480 955698428 333940200 373129969...
output:
686998100
result:
ok 1 number(s): "686998100"
Test #16:
score: 0
Accepted
time: 14ms
memory: 4104kb
input:
6 385889732 715940941 809320622 760587593 48446951 239838379 284668020 435499616 783637300 661145708 795068133 683289232 266510512 857809122 222215801 224926125 466282573 608613056 185036526 287480814 167824917 97954516 142934563 171158492 770699609 561543368 480089055 586572221 651141452 799987124 ...
output:
756516704
result:
ok 1 number(s): "756516704"
Test #17:
score: 0
Accepted
time: 96ms
memory: 6136kb
input:
7 583414677 13185768 916028761 542120858 174890922 432766097 261428292 687179011 399149458 532692284 358330290 657368988 412309829 754665617 536729693 165455952 22417688 748902222 615463894 882513992 900486064 764721436 220757216 65352706 517273741 256026961 133801752 615488054 822452736 229994169 4...
output:
955317918
result:
ok 1 number(s): "955317918"
Test #18:
score: 0
Accepted
time: 739ms
memory: 17412kb
input:
8 722924649 273219172 349651365 41915785 311046537 705921640 746058964 357806254 718138974 84445040 79595086 251117241 8624872 866367338 408762219 598199999 60640485 115204883 548538809 54077438 212857282 240798456 472239435 239920809 672764634 530778816 863403314 761529500 295233355 398430959 73502...
output:
292468538
result:
ok 1 number(s): "292468538"
Test #19:
score: 0
Accepted
time: 746ms
memory: 17456kb
input:
8 901364377 737641198 390124043 384040299 644146054 200624031 993471282 293435314 103879437 130156485 346617872 283946775 965945085 365263135 121266329 102639256 887945102 157743898 416970183 477347448 24776016 443539767 42416462 737135796 845686455 482442538 541148724 503452456 726958687 561435942 ...
output:
432716847
result:
ok 1 number(s): "432716847"
Test #20:
score: 0
Accepted
time: 752ms
memory: 17468kb
input:
8 545150581 655612063 770584467 64807262 59386893 54096891 24835050 321857897 139160667 36569422 684241896 796854649 149475829 756409627 556478348 822273756 156817397 886061038 342086666 553513252 586949363 979798902 46022878 697210794 908441481 975926648 889488153 79097921 273378779 983155816 34872...
output:
769329621
result:
ok 1 number(s): "769329621"
Extra Test:
score: 0
Extra Test Passed