結果

問題 No.2017 Mod7 Parade
ユーザー startcppstartcpp
提出日時 2022-07-28 01:34:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 65,024 KB
実行使用メモリ 10,464 KB
最終ジャッジ日時 2023-09-24 14:37:32
合計ジャッジ時間 3,341 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,376 KB
testcase_01 AC 2 ms
5,392 KB
testcase_02 AC 2 ms
5,380 KB
testcase_03 AC 60 ms
10,072 KB
testcase_04 AC 41 ms
8,632 KB
testcase_05 AC 31 ms
8,060 KB
testcase_06 AC 66 ms
10,176 KB
testcase_07 AC 10 ms
6,024 KB
testcase_08 AC 39 ms
8,424 KB
testcase_09 AC 16 ms
6,532 KB
testcase_10 AC 39 ms
8,524 KB
testcase_11 AC 53 ms
9,644 KB
testcase_12 AC 47 ms
9,252 KB
testcase_13 AC 75 ms
10,356 KB
testcase_14 AC 75 ms
10,420 KB
testcase_15 AC 75 ms
10,332 KB
testcase_16 AC 75 ms
10,332 KB
testcase_17 AC 75 ms
10,352 KB
testcase_18 AC 78 ms
10,384 KB
testcase_19 AC 51 ms
10,464 KB
testcase_20 AC 2 ms
5,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//何も考えなければ、上の桁から途中まで作った数をnとして dp[n mod 7] : 何通り? とすればOK.
//10^3 ≡ (-1) mod 7 を使うことで、L_i <-- L_i % 6していいので、あとは簡単。
//なお、等比級数の和はmod 7の逆元が存在しないことがあるので、使えない。
//modが一般ならダブリングを使うという手がある。
#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int mod = 1000000007;
int n;
int d[100000], L[100000];
int dp[100001][7];
int p10[6] = {1, 10, 100, 1000, 10000, 100000};
int repunit[6] = {0, 1, 11, 111, 1111, 11111};

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) { cin >> d[i] >> L[i]; L[i] %= 6; }
	
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 7) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= mod;
			int nj = (j * p10[L[i]] + repunit[L[i]] * d[i]) % 7;
			dp[i + 1][nj] += dp[i][j];
			dp[i + 1][nj] %= mod;
		}
	}
	
	int ans = 0;
	rep(i, 7) {
		ans += dp[n][i] * i;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}
0