結果

問題 No.164 ちっちゃくないよ!!
ユーザー koyumeishikoyumeishi
提出日時 2015-03-12 23:39:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 795 ms
コンパイル使用メモリ 78,720 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 15:18:23
合計ジャッジ時間 1,521 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

//val(base-X) -> val(base-10);
long long base_X_to_decimal(string val, int X){
	long long ret = 0;
	long long k = 1;
	for(int i=val.size()-1; i>=0; i--){
		int tmp;
		if('0'<= val[i] && val[i] <= '9'){
			tmp = val[i] - '0';
		}else if('A' <= val[i] && val[i] <= 'Z'){
			tmp = val[i] - 'A' +10;
		}else if('a' <= val[i] && val[i] <= 'z'){
			tmp = val[i] - 'a' +10;
		}else{
			tmp = -1;
		}

		//assert(tmp>=0);

		if(tmp >= X) return -1;
		ret += tmp * k;
		k *= X;
	}
	return ret;
}

long long convert_to_d(string s){
	int base = *max_element(s.begin(),s.end()) - '0';
	if(base > 10) base = base - ('A' - ':');
	base = max(2, base+1);

	//cerr << s << " " << base << endl;

	long long ret = base_X_to_decimal(s, base);

	return ret;
}

int main(){
	int N;
	cin >> N;

	vector<string> v(N);
	for(int i=0; i<N; i++){
		cin >> v[i];
	}

	vector<long long> ans(N);
	for(int i=0; i<N; i++){
		ans[i] = convert_to_d(v[i]);
		//cerr << ans[i] << endl;
	}

	cout << (*min_element(ans.begin(), ans.end())) << endl;

	return 0;
}
0