結果
| 問題 | No.164 ちっちゃくないよ!! |
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2015-05-16 15:02:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,168 bytes |
| 記録 | |
| コンパイル時間 | 1,123 ms |
| コンパイル使用メモリ | 108,636 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 04:54:24 |
| 合計ジャッジ時間 | 1,989 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cstdlib> // require abs exit atof atoi
#include <cstdio> // require scanf printf
#include <functional>
#include <numeric> // require accumulate
#include <cmath> // require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip> // require setw
#include <sstream> // require stringstream
#include <cstring> // require memset
#include <cctype> // require tolower, toupper
#include <fstream> // require freopen
#include <ctime> // require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define DIGIT 8 // 区切る数字の桁数
class MDC{
public:
vector<ll> s2i (string s );
string ladd (vector<ll>, vector<ll> );
string lsub (vector<ll>, vector<ll> );
string lmul (vector<ll>, ll );
string ldiv (vector<ll>, ll );
private:
string vi2s(vector<ll> );
};
ll s2ll (string s ){
stringstream ss (s );
ll res;
ss >> res;
return res;
}
string lltos (int n, int flag ){
stringstream ss;
ss << n;
string res;
ss >> res;
if (flag ){
while (res.length() != DIGIT ){
res = '0' + res;
} // end while
} // end if
return res;
}
// 文字列の数字を DIGIT で区切った数字群に変換
vector<ll> MDC::s2i (string s ){
vector<ll> res; res.clear();
while (s.length() % DIGIT != 0 ){
s = '0' + s;
} // end while
for (int i = 0; i < s.length(); i += DIGIT ){
string t = s.substr (i, DIGIT );
res.push_back (s2ll(t ) );
} // end for
return res;
}
// 数字群を文字列に変換
string MDC::vi2s (vector<ll> v ){
int n = v.size();
string res = "";
rep (i, n ) res += lltos(v[i], i );
return res;
}
// 足し算
string MDC::ladd (vector<ll> a, vector<ll> b ){
reverse (ALL (a ) );
reverse (ALL (b ) );
while (a.size() != b.size() ){
if (a.size() < b.size() )
a.push_back (0LL );
else
b.push_back (0LL );
} // end while
int n = a.size();
ll carry = 0LL;
vector<ll> res; res.clear();
rep (i, n ){
ll c = (a[i] + b[i] ) + carry;
if (c >= (ll)pow(10, DIGIT ) ){
c -= (ll)pow(10, DIGIT );
carry = 1LL;
}else{
carry = 0LL;
} // end if
res.push_back (c );
} // end if
if (carry ){
res.push_back (carry );
} // end if
reverse(ALL (res ) );
return vi2s(res );
}
// 掛け算
string MDC::lmul (vector<ll> a, ll b ){
reverse (ALL (a ) );
int n = a.size();
ll carry = 0LL;
vector<ll> res; res.clear();
rep (i, n ){
ll d = a[i]*b + carry;
ll c = d % ((ll)pow(10, DIGIT ) );
carry = (d - c ) / ((ll)pow(10, DIGIT ) );
res.push_back (c );
} // end if
if (carry ) res.push_back (carry );
reverse (ALL (res ) );
return vi2s(res );
}
map<char,int> digits;
string ladds (string s, string t ){
MDC MDC;
vector<ll> a = MDC.s2i (s );
vector<ll> b = MDC.s2i (t );
string res = MDC.ladd (a, b );
return res;
}
string lmuls (ll s, ll b ){
MDC MDC;
vector<ll> a; a.push_back (s );
string res = MDC.lmul (a, b );
return res;
}
// bit進数から10進数に変換する
string todigit (string s, int bit ){
int n = s.length();
reverse (ALL (s ) );
ll d = 1LL;
string res = ""; res += '0';
rep (i, n ){
string add = lmuls ((ll)digits[s[i]], d );
res = ladds (res, add );
d *= (ll)bit;
} // end rep
return res;
}
bool max_bool (string s, string t ){
if (s.length() != t.length() ){
if (s.length() > t.length() )
return true;
else
return false;
} // end if
rep (i, s.length() ){
if (s[i] == t[i] ) continue;
return s[i] >= t[i];
} // end rep
return true;
}
string max_s (string s, string t ){
return (max_bool(s, t ) ? s : t );
}
bool min_bool (string s, string t ){
if (s.length() != t.length() )
return (s.length() < t.length() );
rep (i, s.length() ){
if (s[i] == t[i] ) continue;
return s[i] <= t[i];
} // end rep
return true;
}
string min_s (string s, string t ){
return (min_bool(s, t ) ? s : t );
}
const char order[36] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int main()
{
digits.clear();
rep (i, sizeof(order)/sizeof(order[0] ) ) digits[order[i]] = i;
ios_base::sync_with_stdio(0);
int N; cin >> N;
string res = "";
rep (i, N ){
string s; cin >> s;
int max_digits = 0;
rep (j, s.length() ){
max_digits = max (max_digits, digits[s[j]]+1 );
} // end rep
string curr = todigit (s, max_digits );
res = (i == 0 ? curr : min_s (res, curr ) );
// cerr << s <<'(' << max_digits << ')' << ' ' << curr << endl;
} // end rep
cout << res << endl;
return 0;
}
ty70