結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
noisy_noimin
|
| 提出日時 | 2019-10-25 23:04:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,244 bytes |
| コンパイル時間 | 1,599 ms |
| コンパイル使用メモリ | 172,856 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-07 03:37:37 |
| 合計ジャッジ時間 | 2,187 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
{ 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
void solve() {
ll a, b, c, ans = 0;
cin >> a >> b >> c;
if(c == 1) {
cout << c * b << endl;
return;
}
ll c_pow = 1LL, ci = 0LL;
for(ci=0;c_pow*c<=a;++ci) {
c_pow = c_pow * c;
}
deque<ll> digits;
ll a_copy = a, c_pow_copy = c_pow;
for(ll i=0;i<=ci;++i) {
digits.push_back(a_copy/c_pow_copy);
a_copy -= a_copy / c_pow_copy * c_pow_copy;
c_pow_copy /= c;
}
for(int i=0;i<ci;++i) {
if(digits[i] == 1) {
digits[i+1] += c;
digits[i] = 0;
}
}
while(digits.front() == 0) digits.pop_front();
for(int i=0;i<digits.size();++i) {
if(digits[i]) {
ans += (digits[i]+c-2)/(c-1);
}
++ans;
}
--ans;
ans *= b;
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int q;
cin >> q;
while(q--) {
solve();
}
}
noisy_noimin