AtCoder Beginner Contest 164 D.Multiple of 2019(DP)

AtCoder Beginner Contest 164 D.Multiple of 2019(DP)_第1张图片
AtCoder Beginner Contest 164 D.Multiple of 2019(DP)_第2张图片
从后往前 d p dp dp

AC代码:

const int N = 2e5 + 10;
int n, m;
string s;
ll ans, res, now;
int cnt[N];
int main()
{
	cin >> s;
	int len = s.size();
	mem(cnt, 0);
	cnt[0] = 1;
	res = 1;
	ans = 0;
	now = 0;
	per(i, len-1, 0)
	{
		now = (now + ll(s[i] - '0') * res) % 2019;
		ans += cnt[now]++;
		res = res * 10 % 2019;
	}
	pld(ans);
	return 0;
}

你可能感兴趣的:(DP,AtCode)