結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
tkmst201
|
| 提出日時 | 2019-10-25 22:07:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,043 bytes |
| コンパイル時間 | 1,388 ms |
| コンパイル使用メモリ | 159,424 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-07 03:30:51 |
| 合計ジャッジ時間 | 1,901 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | scanf("%d %d %d", &A, &B, &C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
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 = 0;
//---------------------------------//
ll solve(ll A, ll B, ll C) {
if (C == 1) return -1;
ll cnt = 0;
bool f = false;
while (A > 0) {
if (A > C && A <= C*C && A <= 2*(C-1)) {
f = true;
}
if (A % C > 0) {
A -= A % C; cnt++;
}
if (A > 0) { A /= C; cnt++; }
}
if (f) cnt--;
ll res = cnt * B;
return res;
}
int main() {
int Q;
cin >> Q;
while (Q--) {
int A, B, C;
scanf("%d %d %d", &A, &B, &C);
cout << solve(A, B, C) << endl;
}
return 0;
}
tkmst201