結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー momoyuumomoyuu
提出日時 2023-03-19 20:21:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,372 bytes
コンパイル時間 3,342 ms
コンパイル使用メモリ 254,628 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 17:53:06
合計ジャッジ時間 6,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 AC 2 ms
4,348 KB
testcase_115 AC 2 ms
4,348 KB
testcase_116 AC 2 ms
4,348 KB
testcase_117 AC 1 ms
4,348 KB
testcase_118 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll mod = 998'244'353;
const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};
ll k,l,r;
vector<ll> len;
vector<mint> sum,mul;
void calc(ll now){
    ll w = now * now;
    mint s = 0;
    ll le = 0;
    mint m = 1;
    while(w){
        ll a = w % 10;
        w /= 10;
        if(a==0) a = 10;
        le++;
        s += mint(a);
        m *= mint(a);
    }
    le += 2 * len[now-1];
    s += mint(2) * sum[now-1];
    m *= mul[now-1] * mul[now-1];
    len.push_back(le);
    sum.push_back(s);
    mul.push_back(m);
    if(le<r) calc(now+1);
    else return;
}

pair<mint,mint> c(ll m,ll a){
    if(a==0) return make_pair(mint(0),mint(1));
    if(m==1){
        assert(a==1);
        return make_pair(sum[m],mul[m]);
    }
    if(len[m-1]>=a) return c(m-1,a);
    ll l = len[m-1];
    ll b = len[m] - 2*len[m-1];
    if(l+b<=a){
        pair<mint,mint> now = make_pair(sum[m]-sum[m-1],mul[m]*(mul[m-1].inv()));
        pair<mint,mint> nxt = c(m-1,a-l-b);
        return make_pair(now.first+nxt.first,now.second*nxt.second);
    }else{
        pair<mint,mint> now = make_pair(sum[m-1],mul[m-1]);
        vector<mint> use;
        ll w = m * m;
        while(w){
            ll mm = w % 10;
            w /= 10;
            if(mm==0) mm = 10;
            use.push_back(mint(mm));
        }
        reverse(use.begin(),use.end());
        for(int i = 0;i<a-l;i++){
            now.first += use[i];
            now.second *= use[i];
        }
        return now;
    }
}

pair<mint,mint> solve(ll a){
    ll mx = len.size()-1;
    return c(mx,a);
}

int main(){
    cin>>k>>l>>r;
    len.push_back(0);
    sum.push_back(0);
    mul.push_back(1);
    calc(1);
    ll mx = len.size()-1;
    if(mx>k){
        cout<<-1<<endl;
        return 0;
    }
    pair<mint,mint> L = solve(l-1);
    pair<mint,mint> R = solve(r);
    cout<<R.first-L.first<<" "<<R.second*(L.second.inv())<<endl;
}

0