結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー latte0119latte0119
提出日時 2017-03-10 23:13:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,966 bytes
コンパイル時間 4,155 ms
コンパイル使用メモリ 148,716 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 14:05:53
合計ジャッジ時間 4,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
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,376 KB
testcase_115 AC 1 ms
4,380 KB
testcase_116 AC 2 ms
4,376 KB
testcase_117 AC 1 ms
4,376 KB
testcase_118 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int mod=1000000007;
const int lim=60;

int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

int l[111111];
int s[111111];
int m[111111];


pint solve(int r,int k){
    if(r==l[k])return pint(s[k],m[k]);
    if(r<l[k-1]){
        return solve(r,k-1);
    }
    pint ret=pint(s[k-1],m[k-1]);
    r-=l[k-1];
    stringstream ss;ss<<k*k;
    string str;ss>>str;
    for(int i=0;r&&i<str.size();i++,r--){
        int d=str[i]-'0';
        ret.fi+=d;
        if(d==0)ret.se=ret.se*10%mod;
        else ret.se=ret.se*d%mod;
    }
    if(r==0)return ret;

    pint latte=solve(r,k-1);
    ret.fi+=latte.fi;
    ret.se=ret.se*latte.se%mod;
    return ret;
}

signed main(){
    l[1]=s[1]=m[1]=1;
    m[0]=1;
    for(int i=2;i<100;i++){
        stringstream ss;ss<<i*i;
        string str;ss>>str;
        l[i]=l[i-1]*2+str.size();
        s[i]=s[i-1]*2;
        m[i]=m[i-1]*m[i-1]%mod;
        for(int j=0;j<str.size();j++)s[i]+=str[j]-'0';
        for(int j=0;j<str.size();j++){
            if(str[j]=='0')m[i]=m[i]*10%mod;
            else m[i]=m[i]*(str[j]-'0')%mod;
        }
    }

    int K,L,R;
    cin>>K>>L>>R;L--;
    if(K<lim&&l[K]<R){
        cout<<-1<<endl;
        return 0;
    }

    pint x,y;
    x=solve(L,lim);
    y=solve(R,lim);

    cout<<y.fi-x.fi<<" ";
    cout<<y.se*mpow(x.se,mod-2)%mod<<endl;
    return 0;
}
0