結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー rickythetarickytheta
提出日時 2017-03-10 23:57:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 800 ms
コード長 3,066 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 149,936 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-06 14:44:36
合計ジャッジ時間 5,527 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,500 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 2 ms
4,376 KB
testcase_64 AC 1 ms
4,380 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 1 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 1 ms
4,376 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 1 ms
4,376 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 1 ms
4,376 KB
testcase_75 AC 2 ms
4,376 KB
testcase_76 AC 1 ms
4,376 KB
testcase_77 AC 1 ms
4,376 KB
testcase_78 AC 1 ms
4,376 KB
testcase_79 AC 1 ms
4,376 KB
testcase_80 AC 2 ms
4,380 KB
testcase_81 AC 1 ms
4,376 KB
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 1 ms
4,380 KB
testcase_84 AC 2 ms
4,380 KB
testcase_85 AC 1 ms
4,380 KB
testcase_86 AC 2 ms
4,376 KB
testcase_87 AC 1 ms
4,380 KB
testcase_88 AC 1 ms
4,380 KB
testcase_89 AC 1 ms
4,376 KB
testcase_90 AC 2 ms
4,376 KB
testcase_91 AC 2 ms
4,380 KB
testcase_92 AC 2 ms
4,376 KB
testcase_93 AC 1 ms
4,376 KB
testcase_94 AC 1 ms
4,376 KB
testcase_95 AC 2 ms
4,376 KB
testcase_96 AC 1 ms
4,376 KB
testcase_97 AC 1 ms
4,376 KB
testcase_98 AC 1 ms
4,380 KB
testcase_99 AC 1 ms
4,380 KB
testcase_100 AC 1 ms
4,376 KB
testcase_101 AC 1 ms
4,380 KB
testcase_102 AC 2 ms
4,376 KB
testcase_103 AC 2 ms
4,380 KB
testcase_104 AC 2 ms
4,376 KB
testcase_105 AC 1 ms
4,376 KB
testcase_106 AC 1 ms
4,380 KB
testcase_107 AC 1 ms
4,376 KB
testcase_108 AC 1 ms
4,376 KB
testcase_109 AC 1 ms
4,376 KB
testcase_110 AC 1 ms
4,376 KB
testcase_111 AC 1 ms
4,376 KB
testcase_112 AC 1 ms
4,380 KB
testcase_113 AC 2 ms
4,380 KB
testcase_114 AC 1 ms
4,380 KB
testcase_115 AC 1 ms
4,376 KB
testcase_116 AC 1 ms
4,376 KB
testcase_117 AC 1 ms
4,376 KB
testcase_118 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll k,l,r;

ll lensum[125];
ll wasum[125];
ll sekisum[125];
string val[125];

string tos(ll v){
  string ret = "";
  while(v){
    ret = (char)(v%10 + '0') + ret;
    v/=10;
  }
  return ret;
}

inline pll merge(const pll &a, const pll &b){
  return pll(a.first+b.first,a.second*b.second%MOD);
}

pll dfs(int level, ll lft){
  if(l<=lft && lft+lensum[level]<=r){
    pll ret = pll(wasum[level],sekisum[level]);
    return ret;
  }else if(r<=lft || lft+lensum[level]<=l){
    pll ret = pll(0,1);
    return ret;
  }
  pll ret(0,1);
  ret = merge(ret,dfs(level-1,lft));
  lft += lensum[level-1];
  REP(i,val[level].size()){
    if(l<=lft+i && lft+i<r){
      int yo = val[level][i]-'0';
      if(yo==0)yo=10;
      ret = merge(ret,pll(yo,yo));
    }
  }
  lft += val[level].size();
  ret = merge(ret,dfs(level-1,lft));
  return ret;
}

pll naive(){
  string s;
  FOR(i,1,k+1){
    string a = tos(i*i);
    s = s + a + s;
  }
  ll wa = 0, seki = 1;
  FOR(i,l,r){
    int v = s[i]-'0';
    if(v==0)v=10;
    wa += v;
    seki = seki*v%MOD;
  }
  return pll(wa,seki);
}

uint32_t xorshift(void) {
  static uint32_t x = 123456789;
  static uint32_t y = 362436069;
  static uint32_t z = 521288629;
  uint32_t t;

  t = (x ^ (x << 3)) ^ (y ^ (y >> 19)) ^ (z ^ (z << 6));
  x = y; y = z;
  return z = t;
}

int main(){
  cin>>k>>l>>r;
  lensum[0] = 0;
  wasum[0] = 0;
  sekisum[0] = 1;
  val[0] = "";
  FOR(i,1,k+1){
    ll v = i*i;
    val[i] = tos(v);
    lensum[i] = 2*lensum[i-1] + val[i].size();
    wasum[i] = 2*wasum[i-1];
    sekisum[i] = sekisum[i-1]*sekisum[i-1]%MOD;
    REP(j,val[i].size()){
      int yo = val[i][j]-'0';
      if(yo==0)yo=10;
      wasum[i] = wasum[i]+yo;
      sekisum[i] = sekisum[i]*yo%MOD;
    }
    if(lensum[i]>=r){
      k = i;
      break;
    }
  }
  if(lensum[k]<r){
    puts("-1");
    return 0;
  }
  --l;
  // DEBUG(lensum[k]);
  // while(true){
  //   int len = lensum[k];
  //   while(true){
  //     l = xorshift()%len;
  //     r = xorshift()%len;r++;
  //     if(l<r)break;
  //   }
  //   pll ans = dfs(k,0);
  //   pll yo = naive();
  //   if(ans!=yo){
  //     DEBUG(ans.first);
  //     DEBUG(ans.second);
  //     DEBUG(yo.first);
  //     DEBUG(yo.second);
  //     DEBUG(k);
  //     DEBUG(l);
  //     DEBUG(r);
  //     break;
  //   }
  // }
  pll ans = dfs(k,0);
  printf("%lld %lld\n",ans.first,ans.second);
  return 0;
}
0