結果

問題 No.381 名声値を稼ごう Extra
ユーザー IL_mstaIL_msta
提出日時 2017-01-09 09:08:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,201 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 88,056 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-08-22 21:48:38
合計ジャッジ時間 10,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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

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;
}

struct vnum{
	ULL num[1000000/ketaMax + 1];

	int len;
	ULL powMax;
	ULL divNum;
	int divShift;
	void set(string str){
		powMax = 1;
		len = to_num(num, str);
		
		powMax		= (ULL)1000000000;
		divNum		= (ULL)4294967296;//(ULL)17179869184;//(ULL)536870912;
		divShift	= 32;//34;//29;
	}

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

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

	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