結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー kmjpkmjp
提出日時 2017-03-10 23:09:59
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,935 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 162,820 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 08:33:35
合計ジャッジ時間 3,985 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 WA * 108
権限があれば一括ダウンロードができます

ソースコード

diff #

#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))
//-------------------------------------------------------

ll K,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,0};
	
	if(V==F[K]) return {S[K],P[K]};
	
	if(V<=F[K-1]) {
		return getval(K-1,V);
	}
	else {
		pair<ll,ll> r = {S[K-1],P[K-1]};
		V -= F[K-1];
		
		ll i;
		FOR(i,min(V,(ll)ST[K].size())) {
			char c=ST[K][i];
			if(c==0) (r.second*=10)%=mo;
			else {
				r.first += c;
				(r.second *= c)%=mo;
			}
		}
		
		if(V>ST[K].size()) {
			auto b=getval(K-1,V-ST[K].size());
			r.first += b.first;
			(r.second *= b.second)%=mo;
		}
		return r;
	}
	
	
	
	
}


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<=60;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';
			F[i]++;
			S[i]+=c;
			if(c==0) P[i]=P[i]*10%mo;
			else P[i]=P[i]*c%mo;
		}
	}
	
	cin>>K>>L>>R;
	if(K>60) K=60;
	if(R>F[K]) return _P("-1\n");
	
	auto RR = getval(K,R);
	if(L>1) {
		auto LL = getval(K,L-1);
		cout<<RR.first-LL.first<<" "<<RR.second*modpow(LL.second)%mo<<endl;
	}
	else {
		cout<<RR.first<<" "<<RR.second<<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;
}
0