結果

問題 No.381 名声値を稼ごう Extra
ユーザー IL_mstaIL_msta
提出日時 2017-01-09 07:56:52
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,499 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 88,208 KB
実行使用メモリ 11,180 KB
最終ジャッジ日時 2023-08-22 21:43:13
合計ジャッジ時間 10,139 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>

#include <sstream>
 
#include <algorithm>
#include <cmath>

#include <string>
#include <vector>
#include <valarray>
/*
#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>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////
#define ketaMax 9

inline ULL popcount(ULL b){
	b -=  (b >> 1) & 0x5555555555555555ULL;
	b  = ((b >> 2) & 0x3333333333333333ULL) + (b & 0x3333333333333333ULL);
	b  = ((b >> 4) + b) & 0x0F0F0F0F0F0F0F0FULL;
	return (b * 0x0101010101010101ULL) >> 56;
}

int to_num(ULL* ans, string str){
	int len = str.length();
	string temp;
	ULL pow10 = 1;

	int pos = 0;
	ans[0] = 0;
	for(int i= 0;i<len;++i){
		if((len-i)%ketaMax == 0 && i != 0){
			++pos;
			ans[pos] = 0;
		}
		temp = str[i];
		ans[pos] = ans[pos]*10 +stoi( temp );
	}
	return pos+1;
}

class vnum{
public:
	ULL num[1000000/ketaMax + 1];

	int m_len;
	ULL powMax;
	ULL divNum;
	int divShift;
	void set(string str){
		powMax = 1;
		m_len = to_num(num, str);
		
		powMax = 1000000000ULL;
		/*for(int i=0;i<ketaMax;++i){
			powMax *= 10;
		}*/
		divNum		= (ULL)536870912;
		divShift	= 29;

		/*
		divNum = 1;
		divShift = 0;//怪しい
		while(divNum < powMax){
			divNum *= 2;
			++divShift;
		}
		divNum /= 2;
		--divShift;
		*/
		/*
		cout << "ketaMax\t" << ketaMax << endl;
		cout << "powMax\t" << powMax << endl;
		cout << "divNum\t" << divNum << endl;
		*/
	}

	void div(){//
		ULL ans = 0;
		ULL ama = 0;
		int start = 0;
		int len = m_len;
		while( len != start ){
			ULL temp;
			for(int i=start; i < len;++i){//上の桁から
				temp	= powMax * ama + num[i];
				num[i]	= temp >> divShift;	//商
				ama		= temp & (divNum-1);//あまり
				//num[i]	= temp / divNum;
				//ama		= temp % divNum;
			}
			ans += popcount(ama);
			ama = 0;
			
			if( num[start] == 0 ){
				++start;
			}
		}
		cout << ans << endl;
	}
};

void solve(){
	string str;
	str.reserve(1000000);
	cin >> str;
	
	vnum Num;
	Num.set(str);
	Num.div();
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	solve();
	
	return 0;
}
0