結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
wheson
|
| 提出日時 | 2019-10-25 23:50:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,466 bytes |
| コンパイル時間 | 1,649 ms |
| コンパイル使用メモリ | 169,600 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 03:40:05 |
| 合計ジャッジ時間 | 2,247 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int q;
cin >> q;
REP(i, q)
{
LL a, b, c;
cin >> a >> b >> c;
if(c == 1)
{
cout << -1 << endl;
continue;
}
vector<LL> vec;
while(a > 0)
{
vec.push_back(a % c);
a /= c;
}
reverse(all(vec));
int cnt = vec.size() - 1;
REP(i, vec.size())
{
if(vec[i] > 0) cnt++;
}
if(vec.size() >= 2 && vec[1] > 0 && vec[0] * c + vec[1] <= (c-1)*2) cnt--;
cout << b * cnt << endl;
}
}
wheson