Submission #19059644


Source Code Expand

#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(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
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);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N = 4;
char S[4][6];
double dp[70000];
int main(){
  int i;
  int j;
  int ni;
  int nj;
  int nij;
  int mask;
  int dm;
  double tmp;
  int dx[5] = {0, 1, -1, 0, 0};
  int dy[5] = {0, 0, 0, 1, -1};
  for(mask=(1);mask<(1<<16);mask++){
    dp[mask] = 1e150;
    for(i=(0);i<(N);i++){
      for(j=(0);j<(N);j++){
        int d;
        dm = 5;
        tmp = 0;
        for(d=(0);d<(5);d++){
          {
            auto WYIGIcGE = (i + dx[d]);
            auto t_ynMSdg = ( j + dy[d]);
            ni = WYIGIcGE;
            nj = t_ynMSdg;
          }
          nij = ni * N + nj;
          if(ni < 0 || nj < 0 || ni >= N || nj >= N || !((mask) &(1<<(nij)))){
            continue;
          }
          tmp += dp[mask ^(1<<(nij))];
          dm--;
        }
        if(dm==5){
          continue;
        }
        chmin(dp[mask], (tmp + 5) / (5 - dm));
      }
    }
  }
  {
    int KrdatlYV;
    for(KrdatlYV=(0);KrdatlYV<(N);KrdatlYV++){
      rd(S[KrdatlYV]);
    }
  }
  mask = 0;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      if(S[i][j]=='#'){
        mask |=(1<<(i*4+j));
      }
    }
  }
  wt_L(dp[mask]);
  wt_L('\n');
  return 0;
}
// cLay version 20201229-1

// --- original code ---
// int N = 4;
// char S[4][6];
// double dp[7d4];
// {
//   int i, j, ni, nj, nij;
//   int mask, dm;
//   double tmp;
//   int dx[5] = {0, 1, -1, 0, 0};
//   int dy[5] = {0, 0, 0, 1, -1};
//   rep(mask,1,1<<16){
//     dp[mask] = double_inf;
//     rep(i,N) rep(j,N){
//       dm = 5;
//       tmp = 0;
//       rep(d,5){
//         (ni, nj) = (i + dx[d], j + dy[d]);
//         nij = ni * N + nj;
//         if(ni < 0 || nj < 0 || ni >= N || nj >= N || !BIT_ith(mask, nij)) continue;
//         tmp += dp[mask ^ BIT_ith(nij)];
//         dm--;
//       }
//       if(dm==5) continue;
//       dp[mask] <?= (tmp + 5) / (5 - dm);
//     }
//   }
//   rd(S(N));
//   mask = 0;
//   rep(i,N) rep(j,N) if(S[i][j]=='#') mask |= BIT_ith(i*4+j);
//   wt(dp[mask]);
// }

Submission Info

Submission Time
Task K - Pitching
User LayCurse
Language C++ (GCC 9.2.1)
Score 6
Code Size 4396 Byte
Status AC
Exec Time 29 ms
Memory 4540 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 4
AC × 44
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All max.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
max.txt AC 21 ms 4320 KiB
random_01.txt AC 28 ms 4384 KiB
random_02.txt AC 24 ms 4516 KiB
random_03.txt AC 19 ms 4320 KiB
random_04.txt AC 24 ms 4316 KiB
random_05.txt AC 23 ms 4320 KiB
random_06.txt AC 21 ms 4376 KiB
random_07.txt AC 19 ms 4484 KiB
random_08.txt AC 22 ms 4380 KiB
random_09.txt AC 25 ms 4380 KiB
random_10.txt AC 22 ms 4500 KiB
random_11.txt AC 26 ms 4300 KiB
random_12.txt AC 29 ms 4376 KiB
random_13.txt AC 19 ms 4516 KiB
random_14.txt AC 26 ms 4380 KiB
random_15.txt AC 24 ms 4512 KiB
random_16.txt AC 21 ms 4320 KiB
random_17.txt AC 20 ms 4244 KiB
random_18.txt AC 23 ms 4320 KiB
random_19.txt AC 21 ms 4388 KiB
random_20.txt AC 19 ms 4400 KiB
random_21.txt AC 19 ms 4500 KiB
random_22.txt AC 23 ms 4324 KiB
random_23.txt AC 25 ms 4504 KiB
random_24.txt AC 20 ms 4540 KiB
random_25.txt AC 24 ms 4500 KiB
random_26.txt AC 19 ms 4300 KiB
random_27.txt AC 20 ms 4500 KiB
random_28.txt AC 25 ms 4404 KiB
random_29.txt AC 23 ms 4388 KiB
random_30.txt AC 19 ms 4244 KiB
random_31.txt AC 19 ms 4384 KiB
random_32.txt AC 24 ms 4488 KiB
random_33.txt AC 21 ms 4380 KiB
random_34.txt AC 27 ms 4380 KiB
random_35.txt AC 24 ms 4444 KiB
random_36.txt AC 20 ms 4388 KiB
random_37.txt AC 21 ms 4324 KiB
random_38.txt AC 20 ms 4484 KiB
random_39.txt AC 23 ms 4240 KiB
sample_01.txt AC 23 ms 4500 KiB
sample_02.txt AC 26 ms 4240 KiB
sample_03.txt AC 19 ms 4512 KiB
sample_04.txt AC 21 ms 4320 KiB