結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー koyumeishikoyumeishi
提出日時 2017-03-11 00:05:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,837 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 110,340 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 14:46:18
合計ジャッジ時間 4,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 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,380 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 2 ms
4,380 KB
testcase_116 AC 1 ms
4,376 KB
testcase_117 AC 2 ms
4,376 KB
testcase_118 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
#include <tuple>
#include <utility>
using namespace std;

namespace {
  using Integer = long long; //__int128;
  template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;}
  template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
  template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
  template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;}
  template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
  template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}

istream& operator >> (istream& is, __int128& x){
  static char buff[100];
  is >> buff;
  x = 0;
  size_t i = 0;
  if(buff[0] == '-') i++;
  for(; buff[i]; i++){
    x *= 10;
    x += buff[i]-'0';
  }
  if(buff[0] == '-') x *= -1;
  return is;
}

ostream& operator << (ostream& os, __int128 x){
  if(x==0) return os << 0;
  string s;
  if(x<0){
    os << "-";
    x *= -1;
  }
  while(x!=0){
    s += (x%10) + '0';
    x /= 10;
  }
  reverse(s.begin(), s.end());
  return os << s;
}

  template<class H> void print(const H& head){ cout << head; }
  template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); }
  template<class ... T> void println(const T& ... values){ print(values...); cout << endl; }

  template<class H> void eprint(const H& head){ cerr << head; }
  template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); }
  template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; }

  class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator   end(){ return range_iterator(  end_, step_); } };

  inline string operator "" _s (const char* str, size_t size){ return move(string(str)); }
  constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);}
  constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);}
  constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); }

  inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed

  mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count());

  template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); }

  inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; }
}
constexpr long long mod = 9_ten + 7;

long long dfs_sum(vector<__int128>& len, vector<__int128>& sum, long long l){
  long long k = 0;
  while( len[k+1] <= l ) k++;
  long long ret = sum[k];
  long long ll = len[k];

  k++;
  stringstream ss;
  ss << k*k;
  string tmp = ss.str();

  for(int i=0; i<tmp.size() && ll<l; i++, ll++){
    ret += tmp[i] - '0';
  }

  if(ll < l){
    ret += dfs_sum(len, sum, l-ll);
  }

  return ret;
}

long long dfs_pro(vector<__int128>& len, vector<__int128>& pro, long long l){
  long long k = 0;
  while( len[k+1] <= l ) k++;
  long long ret = pro[k];
  long long ll = len[k];

  k++;
  stringstream ss;
  ss << k*k;
  string tmp = ss.str();

  for(int i=0; i<tmp.size() && ll<l; i++, ll++){
    ret *= tmp[i]=='0' ? 10 : tmp[i] - '0';
    ret %= mod;
  }

  if(ll < l){
    (ret *= dfs_pro(len, pro, l-ll)) %= mod;
  }

  return ret;
}

int main(){
  long long k,l,r;
  cin >> k,l,r;

  k = min(61LL, k);

  vector<__int128> len(k+1, 0);
  len[0] = 0;
  for(long long i=1; i<len.size(); i++){
    stringstream ss;
    ss << i*i;
    len[i] = len[i-1]*2 + ss.str().size();
  }

  vector<__int128> sum(k+1, 0);
  vector<__int128> pro(k+1, 1);
  for(long long i=1; i<sum.size(); i++){
    stringstream ss;
    ss << i*i;
    string tmp = ss.str();
    sum[i] = sum[i-1] * 2 + [&](){ long long ret=0; for(auto c : tmp) ret += c-'0'; return ret; }();
    pro[i] = pro[i-1] * pro[i-1] % mod * [&](){ long long ret=1; for(auto c : tmp){
      ret *= c=='0'?10 : c-'0';
      ret %= mod;
    }
    return ret; }() % mod;
  }

  // eprintln( join(len, "\n") );
  // eprintln( join(sum, "\n") );
  // eprintln( join(pro, "\n") );

  if( r>len.back() ){
    println(-1);
    return 0;
  }

  l--;

  __int128 ans_sum = sum[k];
  ans_sum -= dfs_sum(len,sum, l);
  ans_sum -= dfs_sum(len,sum, len[k]-r);


  long long ans_pro = pro[k];
  (ans_pro *= my_pow_mod( dfs_pro(len,pro, l) , mod-2, mod)) %= mod;
  (ans_pro *= my_pow_mod( dfs_pro(len,pro, len[k]-r) , mod-2, mod)) %= mod;

  println(ans_sum, ans_pro);

  return 0;
}
0