結果

問題 No.853 河原の石
ユーザー LayCurseLayCurse
提出日時 2019-07-26 23:08:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 3,153 ms
コード長 3,306 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 198,724 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 04:07:07
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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, 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 void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  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(long long x){
  char f[20];
  int m=0, s=0;
  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(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int H;
int W;
int main(){
  int i, j, k;
  long long p, res=0;
  rd(H);
  rd(W);
  W = abs(W);
  if(W==0 || H==0){
    wt_L(0);
    wt_L('\n');
    return 0;
  }
  res += H;
  W--;
  k = H;
  for(i=1;;i++){
    if(k >= i && i <= W){
      res += (long long) i * i;
      k -= i;
      W -= i;
      continue;
    }
    if(k >= i){
      res += (long long) i * W;
      break;
    }
    p = (long long) k * i + (long long) (i - k) * (i - 1);
    res += (W / i) * p;
    W %= i;
    res += (long long)min_L(W, k)* i;
    if(W > k){
      res += (long long) (W - k) * (i - 1);
    }
    break;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
  {
    int arr[100], i, j, k, m;
    for(H=1;H<15;H++){
      for(i=0;i<100;i++){
        arr[i] = 0;
      }
      arr[0] = H;
      wt_L("H = ");
      wt_L(H);
      wt_L("\n");
      for(m=0;m<53;m++){
        wt_L(m);
        wt_L(' ');
        wt_L(arr[0]);
        wt_L('\n');
        for(i=0;i<arr[0];i++){
          arr[i+1]++;
        }
        arr[0] = 0;
        for(i=0;i<99;i++){
          arr[i] = arr[i+1];
        }
      }
    }
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int H, W;
// 
// {
//   int i, j, k;
//   ll res = 0, p;
// 
//   rd(H,W);
//   W = abs(W);
//   if(W==0 || H==0){
//     wt(0);
//     return 0;
//   }
// 
//   res += H;
//   W--;
// 
//   k = H;
//   for(i=1;;i++){
//     if(k >= i && i <= W){
//       res += (ll) i * i;
//       k -= i;
//       W -= i;
//       continue;
//     }
// 
//     if(k >= i){
//       res += (ll) i * W;
//       break;
//     }
// 
//     p = (ll) k * i + (ll) (i - k) * (i - 1);
//     res += (W / i) * p;
//     W %= i;
// 
// //    wt(i,k,p);
// 
//     res += (ll) min(W, k) * i;
//     if(W > k) res += (ll) (W - k) * (i - 1);
//     break;
//   }
// 
//   wt(res);
// 
//   return 0;
//   {
//     int i, j, k, m;
//     int arr[100];
//     
//     for(H=1;H<15;H++){
//       rep(i,100) arr[i] = 0;
//       arr[0] = H;
//       wtF("H = {H}\n");
//       for(m=0;m<53;m++){
//         wt(m,arr[0]);
//         rep(i,arr[0]) arr[i+1]++;
//         arr[0] = 0;
//         rep(i,99) arr[i] = arr[i+1];
//       }
//     }
//   }
// 
//   return 0;
// }
0