結果
問題 | No.1312 Snake Eyes |
ユーザー |
![]() |
提出日時 | 2020-12-09 11:33:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,405 bytes |
コンパイル時間 | 2,118 ms |
コンパイル使用メモリ | 198,200 KB |
最終ジャッジ日時 | 2025-01-16 20:41:07 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 WA * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) begin(v),end(v)template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }using ll = long long;using pii = pair<int, int>;constexpr ll INF = 1ll<<30;constexpr ll longINF = 1ll<<60;constexpr ll MOD = 1000000007;constexpr bool debug = false;//---------------------------------//int main() {ll N;cin >> N;ll ans = longINF;FOR(len, 1, 41) {FOR(m, 1, 10) {vector<ll> num(len, m);// p 進法での nauto make = [](ll p, ll n) -> vector<ll> {vector<ll> res;while (n > 0) {res.emplace_back(n % p);n /= p;}reverse(ALL(res));return res;};// p 進法で比較 a <= bauto compare = [](const vector<ll> a, const vector<ll> b) -> bool {if (a.size() != b.size()) return a.size() < b.size();REP(i, a.size()) if (a[i] != b[i]) return a[i] < b[i];return true;};ll l = 1, r = max<ll>(3, N - 1);while (r - l > 1) {ll p = (l + r) >> 1;if (compare(make(p, N), num)) r = p;else l = p;}if (make(r, N) == num) chmin(ans, r);}}cout << ans << endl;}