結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-25 22:00:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 853 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 166,308 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-07 03:29:40 |
| 合計ジャッジ時間 | 2,020 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll query(int a, int b, int c){
if(c == 1) return -1;
ll ans = 0;
while(a){
if(a < c){
ans += b;
a = 0;
}else if(a < 2*c-1){
ans += b;
a -= c-1;
}else if(a%c){
ans += b;
a -= a%c;
}else{
ans += b;
a /= c;
}
}
return ans;
}
int main(void){
int q;
cin >> q;
rep(i, q){
int a, b, c;
cin >> a >> b >> c;
co(query(a, b, c));
}
return 0;
}