結果
問題 | No.381 名声値を稼ごう Extra |
ユーザー | IL_msta |
提出日時 | 2017-01-15 02:31:24 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 7,876 ms / 8,000 ms |
コード長 | 6,813 bytes |
コンパイル時間 | 1,440 ms |
コンパイル使用メモリ | 103,068 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-01 08:33:21 |
合計ジャッジ時間 | 9,609 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 7,876 ms
5,376 KB |
ソースコード
#define _USE_MATH_DEFINES #include <iostream> #include <iomanip> #include <sstream> #include <algorithm> #include <cmath> #include <string> #include <cstring> #include <vector> #include <valarray> #include <array> #include <queue> #include <complex> #include <set> #include <map> #include <stack> #include <list> #include<cassert>//assert(); #include <fstream> ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)<<endl; #define PII pair<int,int> ///////// #ifdef getchar_unlocked #define mygc(c) (c)=getchar_unlocked() #else #define mygc(c) (c)=getchar() #endif #ifdef putchar_unlocked #define mypc(c) putchar_unlocked(c) #else #define mypc(c) putchar(c) #endif ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; ///////// using namespace::std; ///////// #ifdef _DEBUG #define DEBUG_BOOL(b) assert(b) #else #define DEBUG_BOOL(b) #endif ///////// //#define MY_TIME_COUNT 1 #ifdef MY_TIME_COUNT #include <windows.h> #endif /////数値読み込み #define ENABLE_READER_ON(T) \ inline void reader(T &x){\ int k;x = 0;bool flag = true;\ while(true){\ mygc(k);\ if( k == '-'){\ flag = false;break;\ }\ if('0' <= k && k <= '9'){\ x = k - '0';break;\ }\ }\ if( flag ){\ while(true){\ mygc(k);\ if( k<'0' || '9'<k)break;\ x = x * 10 + (k - '0');\ }\ }else{\ while(true){\ mygc(k);\ if( k<'0' || '9'<k)break;\ x = x * 10 - (k-'0');\ }\ }\ } //整数 ENABLE_READER_ON(int) ENABLE_READER_ON(long) ENABLE_READER_ON(long long) ENABLE_READER_ON(unsigned int) ENABLE_READER_ON(unsigned long) ENABLE_READER_ON(unsigned long long) ////// //文字読み込み inline int reader(char c[]){int i,s=0; for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;} c[s++]=i; for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;} c[s]='\0';return s; } inline int reader(string& c,int size=100){int i;c.reserve(size); for(;;){mygc(i);if(i != ' '&&i != '\n'&&i != '\r'&&i != '\t'&&i != EOF)break;} c.push_back(i); for(;;){mygc(i);if(i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF)break;c.push_back(i);} return c.size();} ///////// //数値出力 #define ENABLE_WRITER_ON(T) \ inline void writer(T x){char f[20];int s = 0;\ if (x<0){mypc('-');while(x){f[s++] = ~(x%10)+1,x /= 10;}}\ else{while(x){f[s++] = (x % 10), x /= 10;}}\ if (!s)f[s++] = 0;while (s--)mypc(f[s] + '0');} ENABLE_WRITER_ON(int) ENABLE_WRITER_ON(long) ENABLE_WRITER_ON(long long) ENABLE_WRITER_ON(unsigned int) ENABLE_WRITER_ON(unsigned long) ENABLE_WRITER_ON(unsigned long long) ///////// inline void writer(const char c[]){for (int i = 0; c[i] != '\0'; i++)mypc(c[i]); } inline void writer(const string str){writer( str.c_str() );} ///////// /**/ int popcount(ULL N){//64 N -= (N >> 1) & 0x5555555555555555ULL; N = ((N >> 2) & 0x3333333333333333ULL) + (N & 0x3333333333333333ULL); N = ((N >> 4) + N) & 0x0F0F0F0F0F0F0F0FULL; return (int)( (N * 0x0101010101010101ULL) >> 56); } #define ketaMax 19 #define BASE_MAX (ULL)0xFFFFFFFFFFFFFFFF #define FIVE_POW_19 (unsigned long long)19073486328125 #define MASK16_00 (unsigned long long)0x000000000000FFFF #define MASK16_01 (unsigned long long)0x00000000FFFF0000 #define MASK16_02 (unsigned long long)0x0000FFFF00000000 struct bigNum{ public: int NumSize;//確保しているindex+1 int TopIndex;//値の入っているindex+1 vector<unsigned long long> Num;//10^6 bigNum(){ NumSize = 1; TopIndex = 1; Num.reserve(65536);//Num.reserve(51906); } int setFromString(const string& str); }; int Count(const vector<unsigned long long>& Num,const int NumSize){ int ret = 0; for(int i=0;i<NumSize;++i){ ret += popcount(Num[i]); } return ret; } int bigNum::setFromString(const string& str){ //Numの初期化をする。 int len = str.size(); NumSize = (int)(len*0.05190512648) + 1; Num = vector<unsigned long long>(NumSize,0); TopIndex = 1;//0の値が[0]に入っている int Q = 1 + (len-1)%ketaMax; unsigned long long firstNum = 0; int NumPos = 0; int strPos = 0; for(strPos = 0;strPos<Q;++strPos){ firstNum = firstNum*10 + str[strPos] - '0'; } //this->add(calNum); this->Num[0] = firstNum;//最初の値。 unsigned long long CAL1,CAL2,CARR,CARR_UP; /////////////mul vector<unsigned long long> org; unsigned long long ter; unsigned long long calNum[4]; ///////////// CARR_UP = 0; while( strPos < len ){ for(int i=0;i<ketaMax;++i){ CARR_UP = CARR_UP*10 + str[strPos++] - '0'; } //mul //*10^19 DEBUG_BOOL( ((ULL)10000000000000000000) < BASE_MAX);//10^19 //値の保存 org = this->Num; const int orgTopIndex = this->TopIndex; //値が入っている部分だけ0初期化 for(int i=0; i<orgTopIndex; ++i){ this->Num[i] = 0; } //unsigned long long CAL1=0; //unsigned long long CAL2=0; CARR=0; int i; for(i=0; i<orgTopIndex; ++i){ //ter = org.Num[i]; ter = org[i]; calNum[0] = ((ter & MASK16_00)) * FIVE_POW_19; calNum[1] = ((ter & MASK16_01)>>16) * FIVE_POW_19; calNum[2] = ((ter & MASK16_02)>>32) * FIVE_POW_19; calNum[3] = (ter>>48) * FIVE_POW_19; CAL1 = this->Num[i];//値を持ってくる。 CAL2 = CAL1;//保存しておく CARR = CAL2 > (CAL1 += (CARR_UP));//下からの繰上げ//CARRのリセット CAL2 = CAL1; CARR += CAL2 > (CAL1 += (calNum[0]<<19) ); CAL2 = CAL1; CARR += CAL2 > (CAL1 += (calNum[1]<<35)); CAL2 = CAL1; CARR += CAL2 > (CAL1 += (calNum[2]<<51)); this->Num[i] = CAL1;//値を戻す。 CARR_UP =( ( ( calNum[0]>>(64-19) ) + ( calNum[1]>>(64-35) ) ) + ( ( calNum[2]>>(64-51) ) + (calNum[3]<<(3)) ) + CARR); } while( CARR_UP ){ CAL1 = this->Num[i];//値を持ってくる。 CAL2 = CAL1;//保存しておく CARR_UP = CAL2 > (CAL1 += (CARR_UP)); this->Num[i++] = CAL1;//値を戻す。 } if(i > this->TopIndex){ this->TopIndex = i; } DEBUG_BOOL(CARR_UP == 0); } return NumSize; } inline void solve(){ string str; reader(str); //char str[1000001]; //fread(str,1,1000001,stdin); ////////////////////////////// bigNum bn; bn.setFromString(str); //cout << "TopIndex\t" << bn.TopIndex << endl; //cout << "NumSize\t" << bn.NumSize << endl; writer( Count(bn.Num,bn.TopIndex) ); //mypc('\n'); } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;//小数を10進数表示 //cout << setprecision(16);//小数をいっぱい表示する。16? #ifdef MY_TIME_COUNT LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); LARGE_INTEGER start, end; QueryPerformanceCounter(&start); #endif solve(); #ifdef MY_TIME_COUNT QueryPerformanceCounter(&end); cout << (double)(end.QuadPart - start.QuadPart) / freq.QuadPart << "sec.\n"; #endif return 0; }