結果

問題 No.428 小数から逃げる夢
ユーザー ojisan_ITojisan_IT
提出日時 2017-10-14 05:36:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 5,213 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 100,972 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 13:26:47
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<tuple>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define tii tuple<int,int>
#define tiii tuple<int,int,int>
#define mt make_tuple
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000000007
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

const ll BigIntDig = 100; // BigIntDig*9-dig
const ll Base = 1000000000;
class BigInt{
public:
  int Num[BigIntDig];
  bool sign; // 0 is positive,1 is negative - number
  int size; // how many using Num-Array
  BigInt();
  BigInt(ll);
  BigInt(string);
  void Setstr(string);
  int Carry(int,int);
  void Deb();
};
 
BigInt operator-(BigInt x){
  x.sign ^= 1;
  return x;
}
 
// you can use this func after setting "size"
void BigInt::Setstr(string str){
  int m = str.size() % 9;
  if(m == 0)
    m = 9;
  Num[size-1]=atoi(str.substr(0,m).c_str());
  for(int i = size-2; i >= 0; i--)
    Num[i] = std::atoi(str.substr((size-i-1)*9-(9-m),9).c_str());
}
 
ostream &operator<<(ostream &os, BigInt x) {
  if(x.sign) os << '-';
  os << x.Num[x.size-1];
  for (int i = x.size-2; i >= 0; --i)
    os << setw(9) << setfill('0') << x.Num[i];
  return os;
}
 
BigInt::BigInt(){
  memset(Num,0,sizeof(Num));
  size = 1;
  sign = 0;
}
 
BigInt::BigInt(string str){
  if(str[0] == '-'){sign = 1; str = str.substr(1);}
  else sign = 0;
  memset(Num,0,sizeof(Num));
  if(str == "INF"){
    size = BigIntDig;
    Num[size-1] = Base/10;
  }else{
    size = (str.size()-1)/9 + 1;
    Setstr(str);
  }
}
 
BigInt::BigInt(ll num){
  memset(Num,0,sizeof(Num));
  if(num < 0) sign = 1;
  else sign = 0;
  num = llabs(num);
  Num[0] = num % Base;
  Num[1] = num / Base;
  if(Num[1] != 0)
    size = 2;
  else
    size = 1;
}
 
bool operator < (BigInt x,BigInt y){
  if(x.sign && y.sign) return ((-y)<(-x));
  if(x.sign && y.sign == 0) return true;
  if(x.sign == 0 && y.sign) return false;
  if(x.size != y.size) return x.size < y.size;
  for(int i=x.size-1; i >= 0; i--)
    if(x.Num[i] != y.Num[i]) return x.Num[i] < y.Num[i];
  return false; // x == y
}
bool operator >  (BigInt x,BigInt y){return y<x;}
bool operator <= (BigInt x,BigInt y){return !(y<x);}
bool operator >= (BigInt x,BigInt y){return !(x<y);}
bool operator != (BigInt x,BigInt y){return x<y || y<x;}
bool operator == (BigInt x,BigInt y){return !(x<y)&& !(y<x);}
 
BigInt resize(BigInt x){
  while(x.Num[x.size-1] == 0 && x.size != 1)
    x.size--;
  return x;
}
 
int BigInt::Carry(int nsize,int value){ // nsize:point of carrying, value: value of carrying
  if(value == 0)return 0;
  int index = nsize+1;
  if(index >= size){
    size = index+1;
    Num[index] = value;
  }else{
    int sum = Num[index] + value;
    if(sum >= Base){
      Carry(index,sum/Base);
      sum %= Base;
      Num[index] = sum;
    }else{
      Num[index] = sum;
    }
  }
  return 0;
}
 
 
 
BigInt operator-(BigInt x, BigInt y);
BigInt operator+(BigInt x, BigInt y) {
  if(x.sign && y.sign) return (-(-x+(-y)));
  if(x.sign && y.sign == 0) return (y-(-x));
  if(x.sign == 0 && y.sign) return (x-(-y));
  if (x.size < y.size) x.size = y.size;
  for (int i = 0; i < y.size; ++i){
    x.Num[i] += y.Num[i];
    if(x.Num[i] >= Base){
      x.Carry(i,x.Num[i]/Base);
      x.Num[i] %= Base;
    }
  }
  return x;
}
 
BigInt operator-(BigInt x, BigInt y) {
  if(x.sign && y.sign) return (-y)-(-x);
  if(x.sign == 0 && y.sign) return x+y;
  if(x.sign && y.sign == 0) return x+(-y); 
  if (x < y) {swap(x,y); x.sign ^= 1;}
  for (int i = 0; i < y.size; ++i){
    x.Num[i] -= y.Num[i];
    if(x.Num[i] < 0){
      x.Carry(i,-1);
      x.Num[i] += Base;
    }
  }
  return resize(x);
}
 
BigInt operator*(BigInt x,BigInt y){
  int ys=y.size,xs = x.size;
  BigInt ret;ret.size = 1; ret.sign = (x.sign + y.sign)%2;
  for (int i = 0; i < xs; ++i){
  for(int j = 0; j < ys; ++j){
    ll mul = (ll)x.Num[i] * y.Num[j];
    ret.Carry(i+j,mul/Base);
    ret.Carry(i+j-1,mul%Base);
  }
  }
  return ret;
}
void BigInt::Deb(){
  for(int i = 0;i < size;i++)
    cout << Num[i] << " " << i << endl;
}

int main(){
  string s = "1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991";
  BigInt bi(s);
  int n; cin >> n;
  stringstream ss;
  ss << bi*n << endl;
  string ans = ss.str();
  if(n < 9)
    ans = "0." + ans;
  else if(n < 82)
    ans.insert(1,".");
  else
    ans.insert(2,".");
  cout << ans << endl;
}
0