提出 #71143514


ソースコード 拡げる

#include <bits/stdc++.h>
#define lb(x) (x&-x)
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)

namespace luoyh {
using namespace std;
using i64 = long long;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
void chmin(int &x, int c) { x = min(x, c); }
void chmax(int &x, int c) { x = max(x, c); }

const int maxn = 1e6 + 10, mod = 998244353;
int Add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int Del(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
int Mul(int a, int b) { return 1ll * a * b % mod; }
void Addc(int &a, int b) { a = Add(a, b); }
void Delc(int &a, int b) { a = Del(a, b); }
void Mulc(int &a, int b) { a = Mul(a, b); }

int qmi (int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % mod)
		if (b & 1) res = 1ll * res * a % mod;
	return res;
}
int inv (int x) { return qmi(x, mod - 2); }
int fac[maxn], infac[maxn];
int binom(int a, int b) {
	if (a < b) return 0;
	return 1ll * fac[a] * infac[b] % mod * infac[a - b] % mod;
}
int cnt[10];
int now[10];
 
void solve() {
  string S;
  cin >> S;
  for (auto c : S) cnt[c - '0']++;
  int res = 0;
  for (auto c : S) {
  	if (c - '0' <= 8) {
  	  int a = c - '0', b = a + 1;
  	  Addc(res, binom(now[a] + cnt[b] - now[b], now[a] + 1));
  	}
  	now[c - '0']++;
  }
  cout << res << '\n';
}

signed main() {
	fac[0] = 1; L (i, 1, maxn - 10) fac[i] = 1ll * fac[i - 1] * i % mod;
	infac[maxn - 10] = inv(fac[maxn - 10]);
	R (i, maxn - 11, 0) infac[i] = 1ll * infac[i + 1] * (i + 1) % mod;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--)solve();
  return 0;
}
} signed main() {
  return luoyh::main();
}

提出情報

提出日時
問題 F - 1122 Subsequence 2
ユーザ qazabcdef1111
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1764 Byte
結果 AC
実行時間 19 ms
メモリ 12384 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 27
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 13 ms 11212 KiB
00_sample_01.txt AC 12 ms 11376 KiB
00_sample_02.txt AC 12 ms 11380 KiB
01_random_00.txt AC 12 ms 11408 KiB
01_random_01.txt AC 18 ms 12348 KiB
01_random_02.txt AC 19 ms 12328 KiB
01_random_03.txt AC 18 ms 12348 KiB
01_random_04.txt AC 18 ms 12328 KiB
01_random_05.txt AC 18 ms 12344 KiB
01_random_06.txt AC 18 ms 12212 KiB
01_random_07.txt AC 18 ms 12332 KiB
01_random_08.txt AC 15 ms 11716 KiB
01_random_09.txt AC 18 ms 12320 KiB
01_random_10.txt AC 14 ms 11872 KiB
01_random_11.txt AC 17 ms 12344 KiB
01_random_12.txt AC 12 ms 11480 KiB
01_random_13.txt AC 17 ms 12340 KiB
01_random_14.txt AC 13 ms 11632 KiB
01_random_15.txt AC 17 ms 12384 KiB
01_random_16.txt AC 13 ms 11644 KiB
01_random_17.txt AC 19 ms 12348 KiB
01_random_18.txt AC 19 ms 12208 KiB
01_random_19.txt AC 18 ms 12264 KiB
01_random_20.txt AC 18 ms 12268 KiB
01_random_21.txt AC 15 ms 12212 KiB
01_random_22.txt AC 13 ms 11648 KiB
01_random_23.txt AC 13 ms 11624 KiB