QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359786#7838. 往日之影wsyear0 12ms3744kbC++143.2kb2024-03-20 20:54:112024-03-20 20:54:11

Judging History

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

  • [2024-03-20 20:54:11]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:3744kb
  • [2024-03-20 20:54:11]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

int n, a[4], mod, iv2, ans;

inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
inline int Sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }

struct Complex {
  int a, b;
  // a + bi
  Complex() { a = b = 0; }
  Complex(int x, int y) { a = x, b = y; }
  friend Complex operator+(Complex x, Complex y) { return Complex(Add(x.a, y.a), Add(x.b, y.b)); }
  friend Complex operator-(Complex x, Complex y) { return Complex(Sub(x.a, y.a), Sub(x.b, y.b)); }
  friend Complex operator*(Complex x, Complex y) { return Complex(Sub(1ll * x.a * y.a % mod, 1ll * x.b * y.b % mod), Add(1ll * x.a * y.b % mod, 1ll * x.b * y.a % mod)); }
} w[4], iw[4];

Complex fpw(Complex a, ll p) {
  Complex res = Complex(1, 0);
  while (p) {
    if (p & 1) res = res * a;
    a = a * a, p >>= 1;
  }
  return res;
}

void work() {
  cin >> n, ans = 0;
  rep (i, 0, 3) cin >> a[i];
  Complex sum = Complex();
  rep (x, -1, 3) rep (y, -1, 3) {
    if (x != -1 && !a[x]) continue;
    if (y != -1 && !a[y]) continue;
    if (x != -1 && x == y && a[x] <= 1) continue;
    // i 在 x,-i 在 y
    int rest = n - (x != -1) - (y != -1);
    if (rest < 0) continue;
    for (int p : {0, 2}) {
      Complex t = fpw((w[p] * w[p] + Complex(1, 0)) * Complex(iv2, 0), 1ll * rest * (rest - 1) / 2);
      if (x != -1) t = t * fpw((w[p] * w[1] + Complex(1, 0)) * Complex(iv2, 0), rest);
      if (y != -1) t = t * fpw((w[p] * w[3] + Complex(1, 0)) * Complex(iv2, 0), rest);
      if (x != -1 && y != -1) t = t * ((w[1] * w[3] + Complex(1, 0)) * Complex(iv2, 0));
      if (x != -1 && y != -1) {
        if (x == y) t = t * Complex(1ll * a[x] * (a[x] - 1) % mod, 0);
        else t = t * Complex(1ll * a[x] * a[y] % mod, 0);
      } else if (x != -1) {
        t = t * Complex(a[x], 0);
      } else if (y != -1) {
        t = t * Complex(a[y], 0);
      }
      static int b[4];
      rep (i, 0, 3) b[i] = a[i];
      if (x != -1) b[x]--;
      if (y != -1) b[y]--;
      rep (i, 0, 3) t = t * fpw(iw[p], 1ll * i * b[i]);
      if (x != -1) t = t * fpw(iw[1], x);
      if (y != -1) t = t * fpw(iw[3], y);
      sum = sum + t;
    }
  }
  rep (i, 1, n) sum = sum * Complex(iv2, 0), sum = sum * Complex(iv2, 0);
  cout << sum.a << '\n';
}

int main() {
  // freopen("in", "r", stdin);
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  int t; cin >> t >> mod, iv2 = (mod + 1) >> 1;
  w[0] = Complex(1, 0), w[1] = Complex(0, 1);
  w[2] = Complex(mod - 1, 0), w[3] = Complex(0, mod - 1);
  iw[0] = Complex(1, 0), iw[1] = Complex(0, mod - 1);
  iw[2] = Complex(mod - 1, 0), iw[3] = Complex(0, 1);
  while (t--) work();
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

1 998244353
3
1 1 0 1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

1 998244353
7
0 2 1 4

output:

998069185

result:

ok single line: '998069185'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

1 998244353
4
0 1 0 3

output:

0

result:

ok single line: '0'

Test #4:

score: -10
Wrong Answer
time: 0ms
memory: 3676kb

input:

1 998244353
2
1 0 1 0

output:

124780544

result:

wrong answer 1st lines differ - expected: '0', found: '124780544'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 12ms
memory: 3744kb

input:

999 999999001
2
2 0 0 0
3
3 0 0 0
4
4 0 0 0
5
5 0 0 0
6
6 0 0 0
7
7 0 0 0
8
8 0 0 0
9
9 0 0 0
10
10 0 0 0
11
11 0 0 0
12
12 0 0 0
13
13 0 0 0
14
14 0 0 0
15
15 0 0 0
16
16 0 0 0
17
17 0 0 0
18
18 0 0 0
19
19 0 0 0
20
20 0 0 0
21
21 0 0 0
22
22 0 0 0
23
23 0 0 0
24
24 0 0 0
25
25 0 0 0
26
26 0 0 0
27...

output:

374999626
874999126
359374641
919920956
691222454
586081873
33512082
496961574
790501684
206445579
708073277
492142887
486007979
21786019
802052117
198521403
854660059
658779344
904643630
538486221
357736277
949763680
94144464
342842045
695164947
276856011
552666277
813428208
572457238
910726512
177...

result:

wrong answer 1st lines differ - expected: '499999501', found: '374999626'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%