結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー |
![]() |
提出日時 | 2023-03-19 20:21:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,372 bytes |
コンパイル時間 | 2,550 ms |
コンパイル使用メモリ | 253,304 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-18 13:52:11 |
合計ジャッジ時間 | 5,214 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 60 WA * 55 |
ソースコード
#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;}