結果

問題 No.966 引き算をして門松列(その1)
ユーザー LayCurseLayCurse
提出日時 2020-01-13 20:56:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,559 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 212,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:42:41
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
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');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  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');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
int main(){
  int Lj4PdHRW;
  int A;
  int B;
  int C;
  int res;
  int tmp1;
  int tmp2;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    res = 0;
    rd(A);
    rd(B);
    rd(C);
    if(A > C){
      swap(A, C);
    }
    ;
    if(A==C && C==1){
      wt_L(-1);
      wt_L('\n');
      continue;
    }
    if(A==C){
      res++;
      A--;
    }
    if(B > C || B < A){
      wt_L(res);
      wt_L('\n');
      continue;
    }
    if(B==C){
      C--;
      res++;
      if(A==C){
        A--;
        res++;
      }
      if(A==0){
        res = -1;
      }
      wt_L(res);
      wt_L('\n');
      continue;
    }
    if(B==A){
      B--;
      res++;
      if(B==0){
        res = -1;
      }
      wt_L(res);
      wt_L('\n');
      continue;
    }
    if(A==1){
      tmp1 =1073709056;
    }
    else{
      tmp1 =B-A+1;
    }
    if(B==A+1){
      tmp2 =1073709056;
    }
    else{
      tmp2 =C-B+1;
    }
    if(tmp1==tmp2 && tmp2==1073709056){
      wt_L(-1);
      wt_L('\n');
      continue;
    }
    wt_L(res +min_L(tmp1, tmp2));
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200112-1

// --- original code ---
// {
//   int A, B, C, res, tmp1, tmp2;
//   REP(rd_int()){
//     res = 0;
//     rd(A,B,C);
//     sortE(A,C);
//     if(A==C==1) wt(-1), continue;
//     if(A==C) res++, A--;
//     
//     if(B > C || B < A) wt(res), continue;
//     if(B==C){
//       C--; res++;
//       if(A==C) A--, res++;
//       if(A==0) res = -1;
//       wt(res);
//       continue;
//     }
//     if(B==A){
//       B--; res++;
//       if(B==0) res = -1;
//       wt(res);
//       continue;
//     }
// 
//     tmp1 = if[A==1,int_inf,B-A+1];
//     tmp2 = if[B==A+1,int_inf,C-B+1];
//     if(tmp1==tmp2==int_inf) wt(-1), continue;
//     wt(res + min(tmp1,tmp2));
//   }
// }
0