結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー LayCurseLayCurse
提出日時 2020-07-03 22:23:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,242 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 213,300 KB
実行使用メモリ 6,160 KB
最終ジャッジ日時 2023-10-17 04:32:13
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,972 KB
testcase_01 AC 3 ms
5,976 KB
testcase_02 AC 2 ms
5,980 KB
testcase_03 AC 3 ms
6,004 KB
testcase_04 AC 3 ms
6,144 KB
testcase_05 AC 3 ms
5,972 KB
testcase_06 AC 3 ms
5,972 KB
testcase_07 AC 2 ms
5,972 KB
testcase_08 AC 2 ms
5,976 KB
testcase_09 AC 2 ms
6,000 KB
testcase_10 AC 2 ms
6,004 KB
testcase_11 AC 2 ms
6,016 KB
testcase_12 AC 3 ms
6,032 KB
testcase_13 AC 3 ms
6,036 KB
testcase_14 AC 2 ms
6,052 KB
testcase_15 AC 3 ms
6,052 KB
testcase_16 AC 3 ms
6,052 KB
testcase_17 AC 3 ms
6,052 KB
testcase_18 AC 2 ms
6,052 KB
testcase_19 AC 3 ms
6,052 KB
testcase_20 AC 3 ms
6,076 KB
testcase_21 AC 3 ms
6,100 KB
testcase_22 AC 3 ms
6,112 KB
testcase_23 AC 3 ms
6,120 KB
testcase_24 AC 3 ms
6,124 KB
testcase_25 AC 3 ms
6,136 KB
testcase_26 AC 3 ms
6,148 KB
testcase_27 AC 3 ms
6,148 KB
testcase_28 AC 3 ms
6,144 KB
testcase_29 AC 3 ms
6,144 KB
testcase_30 AC 3 ms
6,156 KB
testcase_31 AC 3 ms
6,156 KB
testcase_32 AC 3 ms
6,148 KB
testcase_33 AC 3 ms
6,148 KB
testcase_34 AC 3 ms
6,148 KB
testcase_35 AC 3 ms
6,148 KB
testcase_36 AC 3 ms
6,148 KB
testcase_37 AC 3 ms
6,156 KB
testcase_38 AC 3 ms
6,152 KB
testcase_39 AC 3 ms
6,152 KB
testcase_40 AC 3 ms
6,152 KB
testcase_41 AC 3 ms
6,144 KB
testcase_42 AC 3 ms
6,144 KB
testcase_43 AC 3 ms
6,144 KB
testcase_44 AC 3 ms
6,144 KB
testcase_45 AC 3 ms
6,144 KB
testcase_46 AC 3 ms
6,148 KB
testcase_47 AC 3 ms
6,148 KB
testcase_48 AC 3 ms
6,156 KB
testcase_49 AC 3 ms
6,160 KB
testcase_50 AC 3 ms
6,152 KB
testcase_51 AC 3 ms
6,160 KB
testcase_52 AC 3 ms
6,156 KB
testcase_53 AC 3 ms
6,156 KB
testcase_54 AC 3 ms
6,152 KB
testcase_55 AC 3 ms
6,156 KB
testcase_56 AC 3 ms
6,152 KB
testcase_57 AC 3 ms
6,152 KB
testcase_58 AC 3 ms
6,152 KB
testcase_59 AC 3 ms
6,148 KB
testcase_60 AC 3 ms
6,148 KB
testcase_61 AC 3 ms
6,156 KB
testcase_62 AC 3 ms
6,148 KB
testcase_63 AC 3 ms
6,152 KB
testcase_64 AC 3 ms
6,152 KB
testcase_65 AC 3 ms
6,160 KB
testcase_66 AC 3 ms
6,160 KB
testcase_67 AC 3 ms
6,152 KB
testcase_68 AC 3 ms
6,160 KB
testcase_69 AC 3 ms
6,152 KB
testcase_70 AC 3 ms
6,152 KB
testcase_71 AC 3 ms
6,152 KB
testcase_72 AC 3 ms
6,152 KB
testcase_73 AC 3 ms
6,152 KB
testcase_74 AC 3 ms
6,144 KB
testcase_75 AC 3 ms
6,148 KB
testcase_76 AC 3 ms
6,156 KB
testcase_77 AC 3 ms
6,156 KB
testcase_78 AC 3 ms
6,156 KB
testcase_79 AC 3 ms
6,156 KB
testcase_80 AC 3 ms
6,156 KB
testcase_81 AC 3 ms
6,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
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){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T, class S, class U> inline void DigitF_L(T n, int sz, S res[], U b){
  int i;
  for(i=(0);i<(sz);i++){
    res[i] = n % b;
    n /= b;
  }
}
long long N;
int d = 30;
int s[30];
long long dp[31][2][3][200];
long long vis[31][2][3][200];
long long solve(int dep, int f, int m1, int sa){
  int i;
  if(dep == -1){
    if(m1-1 == 0 && sa == 100){
      return 1;
    }
    return 0;
  }
  int c;
  int nf;
  long long &res = dp[dep][f][m1][sa];
  if(vis[dep][f][m1][sa]){
    return res;
  }
  vis[dep][f][m1][sa] = 1;
  for(i=(-2);i<(3);i++){
    int j;
    for(j=(-1);j<(2);j++){
      c = i + 5 * (m1-1) - j;
      if(c < 0 || c >= 5){
        continue;
      }
      nf = f;
      if(f && c > s[dep]){
        continue;
      }
      if(c < s[dep]){
        nf = 0;
      }
      res += solve(dep-1, nf, j+1, sa + i);
    }
  }
  return res;
}
int main(){
  long long res;
  rd(N);
  DigitF_L(N, d, s, 5);
  res = solve(d-1, 1, 1, 100);
  wt_L(res-1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// ll N;
// int d = 30, s[30];
// 
// ll dp[31][2][3][200], vis[31][2][3][200];
// 
// ll solve(int dep, int f, int m1, int sa){
// //  wt(dep,f,m1,sa);
// 
//   if(dep == -1){
//     if(m1-1 == 0 && sa == 100) return 1;
//     return 0;
//   }
// 
//   int c, nf;
//   ll &res = dp[dep][f][m1][sa];
//   if(vis[dep][f][m1][sa]) return res;
//   vis[dep][f][m1][sa] = 1;
// 
//   rep(i, -2, 3) rep(j, -1, 2){
//     c = i + 5 * (m1-1) - j;
// 
//     if(c < 0 || c >= 5) continue;
// 
//     nf = f;
//     if(f && c > s[dep]) continue;
//     if(c < s[dep]) nf = 0;
// 
//     res += solve(dep-1, nf, j+1, sa + i);
//   }
// 
//   return res;
// }
// 
// {
//   ll res;
//   rd(N);
//   DigitF(N, d, s, 5);
//   res = solve(d-1, 1, 1, 100);
//   wt(res-1);
// }
0