結果

問題 No.313 π
ユーザー rickythetarickytheta
提出日時 2015-12-06 15:54:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,622 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 146,300 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 16:44:33
合計ジャッジ時間 3,056 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 17 ms
4,352 KB
testcase_03 AC 17 ms
4,352 KB
testcase_04 AC 17 ms
4,348 KB
testcase_05 AC 17 ms
4,348 KB
testcase_06 AC 16 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 16 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 9 ms
4,352 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 9 ms
4,352 KB
testcase_16 AC 10 ms
4,352 KB
testcase_17 AC 9 ms
4,348 KB
testcase_18 AC 10 ms
4,352 KB
testcase_19 AC 13 ms
4,352 KB
testcase_20 AC 17 ms
4,352 KB
testcase_21 AC 13 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 15 ms
4,352 KB
testcase_25 AC 15 ms
4,352 KB
testcase_26 AC 11 ms
4,352 KB
testcase_27 AC 10 ms
4,352 KB
testcase_28 AC 16 ms
4,348 KB
testcase_29 AC 12 ms
4,352 KB
testcase_30 AC 15 ms
4,352 KB
testcase_31 AC 16 ms
4,352 KB
testcase_32 AC 11 ms
4,352 KB
testcase_33 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++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 MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define MOD1 (MOD)
#define MOD2 (MOD+2ll)
#define BASE1 (ll)(1009)
#define BASE2 (ll)(1007)
#define FIX2(a) ((a)%MOD2+MOD2)%MOD2

ll myhash(string s,ll m,ll b){
  ll ret = 0;
  REP(i,s.size()){
    ret *= b;
    ret %= m;
    ret += s[i];
    ret %= m;
  }
  return ret;
}

int main(){
  string s;
  cin >> s;
  ll h1 = 904308214;
  ll h2 = 905431879;
  ll b1 = 1;
  ll b2 = 1;
  ll myhash1 = myhash(s,MOD1,BASE1);
  ll myhash2 = myhash(s,MOD2,BASE2);
  REP(_i,s.size()){
    ll i = s.size()-1-_i;
    if(s[i]!='.'){
      ll t = s[i]*b1%MOD1;
      ll h = (MOD1 + myhash1 - t)%MOD1;
      int cand = -1;
      REP(j,10){
        if(s[i]==j+'0')continue;
        ll hh = (h+('0'+j)*b1)%MOD1;
        if(hh == h1){
          cand = j;
          break;
        }
      }
      if(cand != -1){
        t = s[i]*b2%MOD2;
        h = (MOD2+myhash2-t)%MOD2;
        ll hh = (h+('0'+cand)*b2)%MOD2;
        if(hh == h2){
          cout << s[i] << " " << cand << endl;
          return 0;
        }
      }
    }
    b1 *= BASE1;
    b1 %= MOD1;
    b2 *= BASE2;
    b2 %= MOD2;
  }
  return 0;
}
0