結果

問題 No.1086 桁和の桁和2
ユーザー kakel-san
提出日時 2025-10-10 22:36:18
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 409 ms / 3,000 ms
コード長 1,528 bytes
コンパイル時間 8,006 ms
コンパイル使用メモリ 168,328 KB
実行使用メモリ 216,964 KB
最終ジャッジ日時 2025-10-10 22:36:37
合計ジャッジ時間 18,187 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var l = NList;
        var r = NList;
        var d = NList;
        var ans = 1L;
        var mod = 1_000_000_007;
        var nine = 111_111_112;
        for (var i = 0; i < n; ++i)
        {
            if (d[i] == 0)
            {
                if (i > 0 && d[i - 1] > 0)
                {
                    ans = 0;
                }
            }
            else
            {
                var mul = (Exp(10, r[i], mod) - 1 + mod) % mod * nine % mod;
                var mul2 = 0L;
                if (l[i] > 0) mul2 = (Exp(10, l[i], mod) - 1 + mod) % mod * nine % mod;
                if (i > 0 && d[i] == d[i - 1]) mul = (mul + 1) % mod;
                ans = ans * ((mul - mul2 + mod) % mod) % mod;
            }
        }
        WriteLine(ans);
    }
    static long Exp(long n, long p, int mod)
    {
        long _n = n % mod;
        var _p = p;
        var result = 1L;
        if ((_p & 1) == 1) result *= _n;
        while (_p > 0)
        {
            _n = _n * _n % mod;
            _p >>= 1;
            if ((_p & 1) == 1) result = result * _n % mod;
        }
        return result;
    }
}
0