結果
問題 | No.915 Plus Or Multiple Operation |
ユーザー |
|
提出日時 | 2020-05-13 06:09:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 451 bytes |
コンパイル時間 | 2,100 ms |
コンパイル使用メモリ | 191,008 KB |
最終ジャッジ日時 | 2025-01-10 10:45:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | int q; scanf("%d",&q); | ~~~~~^~~~~~~~~ main.cpp:21:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | int a,b,base; scanf("%d%d%d",&a,&b,&base); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; lint dfs(int a,int base){ lint res=(a+base-2)/(base-1); if(a>0){ lint cnt=1; if(a%base!=0) cnt++; res=min(res,cnt+dfs(a/base,base)); } return res; } int main(){ int q; scanf("%d",&q); rep(_,q){ int a,b,base; scanf("%d%d%d",&a,&b,&base); if(base==1) puts("-1"); else printf("%lld\n",b*dfs(a,base)); } return 0; }