結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー FF256grhyFF256grhy
提出日時 2018-12-05 01:14:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,212 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 169,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 23:56:03
合計ジャッジ時間 12,523 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 8 ms
4,376 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 9 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 40 ms
4,380 KB
testcase_31 AC 87 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 285 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 551 ms
4,380 KB
testcase_41 AC 551 ms
4,376 KB
testcase_42 AC 567 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 8 ms
4,380 KB
testcase_51 AC 8 ms
4,380 KB
testcase_52 AC 8 ms
4,376 KB
testcase_53 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int L = 100010;
// const int L = 30;

int b;
string n, m;

void f(string & s, int v, int p) {
	dec1(i, p) {
		s[i] += v % b;
		v /= b;
		if(s[i] >= '0' + b) { s[i - 1]++; s[i] -= b; }
		else if(v == 0) { return; }
	}
	assert(false);
}

string diff(const string & s, const string & t) { // s - t
	assert(s.size() == t.size());
	
	string ans = string(s.size(), '0');
	dec(i, s.size()) {
		ans[i] += s[i] - t[i];
		if(ans[i] < '0') { ans[i - 1]--; ans[i] += b; }
	}
	return ans;
}

int strmod(const string & s, int x) {
	int v = 0;
	inc(i, s.size()) { v = (b * v + (s[i] - '0')) % x; }
	return v;
}

int si(const string & s) {
	int v = 0;
	inc(i, s.size()) { v = b * v + (s[i] - '0'); }
	return v;
}

string strdiv(const string & s, int x) {
	string t = s;
	
	string ans = string(t.size(), '0');
	int p = 0;
	inc(i, t.size()) {
		int y = si(t.substr(p, i - p + 1));
		ans[i] += y / x;
		y %= x;
		string u = to_string(y);
		u = string(i - p + 1 - u.size(), '0') + u;
		assert(u.size() == i - p + 1);
		incII(j, p, i) { t[j] = u[j - p]; }
		while(p < i && t[p] == '0') { p++; }
	}
	return ans;
}

int main() {
	cin >> b >> n;
	m = "1";
	
	n = string(L - n.size(), '0') + n;
	m = string(L - m.size(), '0') + m;
	
	int l = -1;
	inc1(i, 100001) {
		string m2 = m;
		f(m2, i * (b - 1), L - i);
		if(n < m2) { l = i; break; }
		m = m2;
	}
	assert(l != -1);
	
	// cout << n << endl;
	// cout << m << endl;
	
	string d = diff(n, m);
	
	// cout << "l: " << l << endl;
	// cout << "d: " << d << endl;
	
	int    mo = strmod(d, l);
	string di = strdiv(d, l);
	di[L - l] += 1;
	
	// cout << "mo: " << mo << endl;
	// cout << "di: " << di << endl;
	
	cout << di[L - l + mo] << endl;
	
	return 0;
}
0