답안 #2259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
2259 2013-07-20T17:41:09 Z kriii 생일수 II (GA4_birthday2) C++
25 / 100
53 ms 13232 KB
#include <iostream>
#include <string>
using namespace std;

const long long mod = 19980305;
long long linear[200020];
long long scalar[200020];
long long sum[200020];
long long ten[200020],cnt[200020];
long long three[200020];
long long eight[200020];

void add(long long &a, long long p){a = (a + p) % mod;}
void mul(long long &a, long long p){a = (a * p) % mod;}

long long get(string s)
{
	int i,l=s.length()-1;
	long long res = sum[l];
	long long in = 0, p, c;

	for (i=0;i<s.length();i++,l--){
		p = ten[l]; c = cnt[l];
		if (s[i] == '3'){
			in += 3 * p;
		}
		if (s[i] == '5'){
			add(res,(in+3*p)*(in+3*p)%mod*(c+mod-1)%mod);
			add(res,(linear[l]*2+mod*2-three[l]-eight[l])%mod*(in+3*p)%mod);
			add(res,scalar[l]);
			add(res,(in+3*p+eight[l])*(in+5*p+three[l])%mod);

			in += 5 * p;
		}
		if (s[i] == '8'){
			add(res,(in+3*p)*(in+3*p)%mod*(c+mod-1)%mod);
			add(res,(linear[l]*2+mod*2-three[l]-eight[l])%mod*(in+3*p)%mod);
			add(res,scalar[l]);
			add(res,(in+3*p+eight[l])*(in+5*p+three[l])%mod);

			add(res,(in+5*p)*(in+5*p)%mod*(c+mod-1)%mod);
			add(res,(linear[l]*2+mod*2-three[l]-eight[l])%mod*(in+5*p)%mod);
			add(res,scalar[l]);
			add(res,(in+5*p+eight[l])*(in+8*p+three[l])%mod);
			
			in += 8 * p;
		}
	}

	return res;
}

int main()
{
	int i;

	ten[0] = cnt[0] = 1; three[0] = eight[0] = 0;
	for (i=1;i<=200000;i++){
		ten[i] = ten[i-1] * 10 % mod;
		cnt[i] = cnt[i-1] * 3 % mod;
		three[i] = (three[i-1] * 10 + 3) % mod;
		eight[i] = (eight[i-1] * 10 + 8) % mod;
	}

	long long p;
	linear[0] = 0; p = 16;
	for (i=1;i<=200000;i++){
		linear[i] = linear[i-1] * 3 % mod;
		add(linear[i],p);
		mul(p,30);
	}

	scalar[1] = 55; p = 1;
	for (i=2;i<=200000;i++){
		mul(p,10);
		scalar[i] = 0;
		add(scalar[i],(cnt[i-1]+mod-1)*(9+25+64)%mod*p%mod*p%mod);
		add(scalar[i],(linear[i-1]*2+mod*2-three[i-1]-eight[i-1])*(3+5+8)%mod*p%mod);
		add(scalar[i],(scalar[i-1]*3)%mod);
		add(scalar[i],(3*p+eight[i-1])*(5*p+three[i-1])%mod);
		add(scalar[i],(5*p+eight[i-1])*(8*p+three[i-1])%mod);
	}

	for (i=1;i<=200000;i++){
		sum[i] = sum[i-1];
		add(sum[i],three[i+1]*eight[i]%mod);
		add(sum[i],scalar[i]);
	}

	string a,b;
	cin >> a >> b;
	cout << (get(b) - get(a) + mod) % mod << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 12320 KB Output is correct
2 Correct 18 ms 12320 KB Output is correct
3 Correct 23 ms 12320 KB Output is correct
4 Correct 21 ms 12320 KB Output is correct
5 Correct 22 ms 12320 KB Output is correct
6 Correct 21 ms 12320 KB Output is correct
7 Correct 19 ms 12320 KB Output is correct
8 Correct 19 ms 12320 KB Output is correct
9 Correct 20 ms 12320 KB Output is correct
10 Correct 20 ms 12320 KB Output is correct
11 Correct 23 ms 12320 KB Output is correct
12 Correct 22 ms 12320 KB Output is correct
13 Correct 19 ms 12320 KB Output is correct
14 Correct 21 ms 12320 KB Output is correct
15 Correct 19 ms 12320 KB Output is correct
16 Correct 18 ms 12320 KB Output is correct
17 Correct 21 ms 12320 KB Output is correct
18 Correct 21 ms 12320 KB Output is correct
19 Correct 20 ms 12320 KB Output is correct
20 Correct 17 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 12320 KB Output is correct
2 Correct 15 ms 12320 KB Output is correct
3 Correct 20 ms 12320 KB Output is correct
4 Correct 23 ms 12320 KB Output is correct
5 Correct 20 ms 12320 KB Output is correct
6 Correct 22 ms 12320 KB Output is correct
7 Correct 22 ms 12320 KB Output is correct
8 Correct 20 ms 12320 KB Output is correct
9 Correct 23 ms 12320 KB Output is correct
10 Correct 18 ms 12320 KB Output is correct
11 Correct 21 ms 12320 KB Output is correct
12 Correct 20 ms 12320 KB Output is correct
13 Correct 24 ms 12320 KB Output is correct
14 Correct 19 ms 12320 KB Output is correct
15 Correct 21 ms 12320 KB Output is correct
16 Correct 21 ms 12320 KB Output is correct
17 Correct 19 ms 12320 KB Output is correct
18 Correct 20 ms 12320 KB Output is correct
19 Correct 22 ms 12320 KB Output is correct
20 Correct 21 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 12320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 13128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 13232 KB Output isn't correct
2 Halted 0 ms 0 KB -