Submission #70665951


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m, l; cin >> n >> m >> l;
	vector<mint>a(n + 1);
	rep(i, m) {
		int x; cin >> x;
		a[x] = (mint(m)).inv();
	}
	vector<bool>ng(n + 1);
	rep(i, l) {
		int x; cin >> x;
		ng[x] = true;
	}
	vector<mint>dp(n + 1);
	dp[0] = 1;
	auto dfs = [&](auto &&self, int l, int r)->void {
		if (l + 1 == r) {
			if (ng[l])dp[l] = 0;
			return;
		}
		int m = (l + r) / 2;
		self(self, l, m);

		vector<mint>f(m - l);
		rep(i, m - l)f[i] = dp[i + l];

		vector<mint>g(r - l);
		rep(i, r - l)g[i] = a[i];
		if (r == n + 1)g = a;

		auto h = convolution(f, g);

		if (r == n + 1) {
			rep(i, h.size()) {
				int x = i + l;
				if (x >= m)dp[min(n, x)] += h[i];
			}
		}
		else {
			rep2(i, m, r)if (!ng[i])dp[i] += h[i - l];
		}

		self(self, m, r);
	};
	dfs(dfs, 0, n + 1);
	cout << dp[n].val() << endl;
	return 0;
}

Submission Info

Submission Time
Task J - Sugoroku
User kwm_t
Language C++ 23 (gcc 12.2)
Score 4
Code Size 1760 Byte
Status AC
Exec Time 482 ms
Memory 46184 KiB

Compile Error

Main.cpp: In lambda function:
Main.cpp:11:37: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<atcoder::static_modint<998244353> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   11 | #define rep(i, n) for (int i = 0; i < (n); ++i)
      |                                     ^
Main.cpp:55:25: note: in expansion of macro ‘rep’
   55 |                         rep(i, h.size()) {
      |                         ^~~
Main.cpp: In instantiation of ‘main()::<lambda(auto:55&&, int, int)> [with auto:55 = main()::<lambda(auto:55&&, int, int)>&]’:
Main.cpp:66:5:   required from here
Main.cpp:11:37: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<atcoder::static_modint<998244353> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   11 | #define rep(i, n) for (int i = 0; i < (n); ++i)
      |                                     ^
Main.cpp:55:25: note: in expansion of macro ‘rep’
   55 |                         rep(i, h.size()) {
      |                         ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 4 / 4
Status
AC × 2
AC × 6
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3516 KiB
00_sample_01.txt AC 445 ms 46120 KiB
01_random_00.txt AC 475 ms 46104 KiB
01_random_01.txt AC 482 ms 46112 KiB
01_random_02.txt AC 465 ms 46184 KiB
01_random_03.txt AC 436 ms 41708 KiB