結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-01-19 05:29:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,066 bytes |
| コンパイル時間 | 2,356 ms |
| コンパイル使用メモリ | 212,408 KB |
| 最終ジャッジ日時 | 2025-01-08 20:10:22 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline int rd_int(void){
int x;
rd(x);
return x;
}
inline void wt_L(char a){
putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
putchar_unlocked('-');
}
while(s--){
putchar_unlocked(f[s]+'0');
}
}
template<class S, class T> inline S chmin(S &a, T b){
if(a>b){
a=b;
}
return a;
}
int solve(int a, int b, int c){
long long res = 0;
if(b >= c){
res += b-c+1;
b = c-1;
}
if(a >= b){
res += a-b+1;
a = b-1;
}
if(a <= 0){
res = 1073709056;
}
return res;
}
int main(){
int Lj4PdHRW;
int A;
int B;
int C;
int res;
int KL2GvlyY = rd_int();
for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
res = 1073709056;
rd(A);
rd(B);
rd(C);
chmin(res, solve(A,C,B));
chmin(res, solve(B,A,C));
chmin(res, solve(C,A,B));
chmin(res, solve(B,C,A));
if(res==1073709056){
wt_L(-1);
wt_L('\n');
}
else{
wt_L(res);
wt_L('\n');
}
}
return 0;
}
// cLay varsion 20200119-1
// --- original code ---
// int solve(int a, int b, int c){
// ll res = 0;
// if(b >= c){
// res += b-c+1;
// b = c-1;
// }
// if(a >= b){
// res += a-b+1;
// a = b-1;
// }
// if(a <= 0) res = int_inf;
// return res;
// }
//
// {
// int A, B, C;
// int res;
// REP(rd_int()){
// res = int_inf;
// rd(A,B,C);
// res <?= solve(A,C,B);
// res <?= solve(B,A,C);
// res <?= solve(C,A,B);
// res <?= solve(B,C,A);
// wt(if[res==int_inf,-1,res]);
// }
// }
LayCurse