結果
| 問題 |
No.493 とても長い数列と文字列(Long Long Sequence and a String)
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2017-03-11 00:13:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,709 bytes |
| コンパイル時間 | 1,684 ms |
| コンパイル使用メモリ | 162,616 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 09:12:53 |
| 合計ジャッジ時間 | 4,356 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 3 WA * 112 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int K;
ll L,R;
ll F[100],S[100],P[100];
ll mo=1000000007;
string ST[100];
ll modpow(ll a, ll n = mo-2) {
ll r=1;
while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
return r;
}
pair<ll,ll> getval(int K,ll V) {
if(V<=0) return {0,1};
if(V==F[K]) return {S[K],P[K]};
if(V<=F[K-1]) return getval(K-1,V);
ll sum=0,prod=1;
V -= F[K-1];
ll i;
FOR(i,min(V,(ll)ST[K].size())) {
sum += ST[K][i];
(prod *= ST[K][i])%=mo;
}
auto r=getval(K-1,V-ST[K].size());
sum += r.first;
(prod *= r.second)%=mo;
return {sum,prod};
}
void solve() {
int i,j,k,l,r,x,y; string s;
F[1]=S[1]=P[1]=1;
ST[1]="1";
ST[1][0]-='0';
for(i=2;i<=61;i++) {
F[i]=2*F[i-1];
S[i]=2*S[i-1];
P[i]=P[i-1]*P[i-1]%mo;
char buf[20];
sprintf(buf,"%d",i*i);
ST[i]=buf;
FORR(c,ST[i]) {
c-='0';
if(c==0) c+=10;
F[i]++;
S[i]+=c;
P[i]=P[i]*c%mo;
}
}
cin>>K>>L>>R;
K=min(K,60);
if(R>F[K]) return _P("-1\n");
auto RR = getval(K,R);
auto LL = getval(K,L-1);
cout<<RR.first-LL.first<<" "<<RR.second*modpow(LL.second)%mo<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n';
FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
solve(); return 0;
}
kmjp