結果

問題 No.164 ちっちゃくないよ!!
ユーザー furafyfurafy
提出日時 2015-07-30 04:48:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 76,444 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:25:54
合計ジャッジ時間 1,065 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

char getBiggestChar(string &s) {
	char ret = s[0];
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			if (s[j] > ret) {
				ret = s[j];
			}
		}
	}
	return ret;
}

bool isNumber(char c) {
	return c <= '9';
}

int toNumber(char c) {
	int ret = (int)c;
	if (isNumber(c)) {
		ret -= '0';
	} else {
		ret -= 'A' - 10;
	}
	return ret;
}

int toBase(char c) {
	return toNumber(c) + 1;
}

long long encode(string s, int b) {
	long long ret = 0;
	long long mul = 1;
	for (int i = 0; i < s.size(); i++) {
		int num = toNumber(s[s.size() - 1 - i]);
		ret += num * mul;
		mul *= b;
	}
	return ret;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	vector<string> V;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		V.push_back(s);
	}
	long long min = -1;
	for (int i = 0; i < V.size(); i++) {
		int base = toBase(getBiggestChar(V[i]));
		long long encoded = encode(V[i], base);
		if ((encoded < min) || (min == -1)) {
			min = encoded;
		}
	}
	cout << min << endl;
}
0