QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505806#9116. DRD Stringhos_lyricAC ✓11ms11128kbC++144.4kb2024-08-05 11:40:122024-08-05 11:40:15

Judging History

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

  • [2024-08-05 11:40:15]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:11128kb
  • [2024-08-05 11:40:12]
  • 提交

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 <random>
#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>;


int main() {
  int N, A;
  for (; ~scanf("%d%d", &N, &A); ) {
    vector<Mint> AA(N + 1);
    AA[0] = 1;
    for (int i = 1; i <= N; ++i) AA[i] = AA[i - 1] * A;
    
    // border-free
    auto dp = AA;
    Mint sum = 0;
    for (int n = 1; n <= N; ++n) {
      // k: min border
      /*
      for (int k = 1; 2 * k <= n; ++k) {
        dp[n] -= dp[k] * AA[n - 2 * k];
      }
      */
      sum *= A;
      if (n % 2 == 0) sum += dp[n / 2];
      dp[n] -= sum;
    }
    
    Mint ans = AA[N] - dp[N];
    if (N % 2 == 0) {
      ans -= dp[N / 2];
    }
    printf("%u\n", ans.x);
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

6 2

output:

40

result:

ok "40"

Test #2:

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

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

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

input:

3 1

output:

1

result:

ok "1"

Test #4:

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

input:

4 7

output:

343

result:

ok "343"

Test #5:

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

input:

5 4

output:

304

result:

ok "304"

Test #6:

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

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

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

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

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

input:

1330 3031

output:

139921223

result:

ok "139921223"

Test #9:

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

input:

4946 3837

output:

64102067

result:

ok "64102067"

Test #10:

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

input:

4236 3305

output:

78581604

result:

ok "78581604"

Test #11:

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

input:

399 3245

output:

714500544

result:

ok "714500544"

Test #12:

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

input:

4881 2346

output:

28365995

result:

ok "28365995"

Test #13:

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

input:

4647 3069

output:

798067847

result:

ok "798067847"

Test #14:

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

input:

3414 4280

output:

669878613

result:

ok "669878613"

Test #15:

score: 0
Accepted
time: 11ms
memory: 10932kb

input:

1000000 1000000

output:

469217978

result:

ok "469217978"

Test #16:

score: 0
Accepted
time: 7ms
memory: 10880kb

input:

1000000 1

output:

1

result:

ok "1"

Test #17:

score: 0
Accepted
time: 5ms
memory: 6704kb

input:

418909 302156

output:

189551565

result:

ok "189551565"

Test #18:

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

input:

984572 895728

output:

567020798

result:

ok "567020798"

Test #19:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

50545 723857

output:

651400574

result:

ok "651400574"

Test #20:

score: 0
Accepted
time: 4ms
memory: 8504kb

input:

668791 286918

output:

27505324

result:

ok "27505324"

Test #21:

score: 0
Accepted
time: 3ms
memory: 10172kb

input:

898539 238506

output:

9072376

result:

ok "9072376"

Test #22:

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

input:

711024 686568

output:

221989803

result:

ok "221989803"

Test #23:

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

input:

970385 660016

output:

104842944

result:

ok "104842944"

Test #24:

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

input:

943632 224593

output:

631779281

result:

ok "631779281"

Test #25:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

26758 836991

output:

860673946

result:

ok "860673946"

Test #26:

score: 0
Accepted
time: 9ms
memory: 9824kb

input:

838661 823355

output:

34634389

result:

ok "34634389"

Test #27:

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

input:

923587 8580

output:

549615557

result:

ok "549615557"

Test #28:

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

input:

275456 449218

output:

745638801

result:

ok "745638801"

Test #29:

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

input:

96512 594328

output:

159367796

result:

ok "159367796"

Test #30:

score: 0
Accepted
time: 7ms
memory: 10940kb

input:

995445 996221

output:

785170205

result:

ok "785170205"

Test #31:

score: 0
Accepted
time: 9ms
memory: 9656kb

input:

821123 195922

output:

950462887

result:

ok "950462887"

Test #32:

score: 0
Accepted
time: 8ms
memory: 8804kb

input:

715365 748511

output:

571984302

result:

ok "571984302"

Test #33:

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

input:

867858 338674

output:

698272834

result:

ok "698272834"

Test #34:

score: 0
Accepted
time: 2ms
memory: 6276kb

input:

406213 206504

output:

201893603

result:

ok "201893603"

Test #35:

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

input:

729455 262034

output:

521537323

result:

ok "521537323"

Test #36:

score: 0
Accepted
time: 3ms
memory: 10332kb

input:

915061 381221

output:

361349035

result:

ok "361349035"

Test #37:

score: 0
Accepted
time: 2ms
memory: 6516kb

input:

426669 32501

output:

206011209

result:

ok "206011209"

Test #38:

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

input:

256786 708325

output:

287335753

result:

ok "287335753"

Extra Test:

score: 0
Extra Test Passed