結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-06 03:52:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 704 bytes |
| コンパイル時間 | 2,007 ms |
| コンパイル使用メモリ | 191,896 KB |
| 最終ジャッジ日時 | 2025-01-10 07:08:23 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | int q; scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:13:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | lint a,b,c; scanf("%lld%lld%lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
const long long INF=1LL<<61;
int main(){
int q; scanf("%d",&q);
rep(_,q){
lint a,b,c; scanf("%lld%lld%lld",&a,&b,&c);
lint ans=INF;
if(b>=3){ // b を最大値にする
lint a2=a,c2=c,cost=0;
if(a>=b) a2=b-1, cost+=a-b+1;
if(c>=b) c2=b-1, cost+=c-b+1;
if(a2==c2) a2--, cost++;
if(a2==0) cost=INF;
ans=min(ans,cost);
}
if(a>=2 && c>=2){ // b を最小値にする
lint a2=a,c2=c,cost=0;
if(a==c){
a2--; cost++;
}
cost+=max({b-a2+1,b-c2+1,0LL});
if(a2==1) cost=INF;
ans=min(ans,cost);
}
printf("%lld\n",ans<INF?ans:-1);
}
return 0;
}