結果

問題 No.1726 [Cherry 3rd Tune B] ジャマイカビアポン
ユーザー LayCurseLayCurse
提出日時 2021-10-29 22:06:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 3,000 ms
コード長 7,759 bytes
コンパイル時間 3,948 ms
コンパイル使用メモリ 220,520 KB
実行使用メモリ 16,896 KB
最終ジャッジ日時 2024-04-16 14:58:28
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 23 ms
6,784 KB
testcase_15 AC 104 ms
16,640 KB
testcase_16 AC 142 ms
16,640 KB
testcase_17 AC 98 ms
16,640 KB
testcase_18 AC 58 ms
9,856 KB
testcase_19 AC 133 ms
16,768 KB
testcase_20 AC 30 ms
6,528 KB
testcase_21 AC 127 ms
16,640 KB
testcase_22 AC 41 ms
9,856 KB
testcase_23 AC 44 ms
9,856 KB
testcase_24 AC 202 ms
16,768 KB
testcase_25 AC 202 ms
16,640 KB
testcase_26 AC 213 ms
16,896 KB
testcase_27 AC 217 ms
16,896 KB
testcase_28 AC 218 ms
16,896 KB
testcase_29 AC 213 ms
16,640 KB
testcase_30 AC 213 ms
16,640 KB
testcase_31 AC 207 ms
16,640 KB
testcase_32 AC 207 ms
16,768 KB
testcase_33 AC 213 ms
16,768 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 43 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
struct Rand{
  unsigned x;
  unsigned y;
  unsigned z;
  unsigned w;
  Rand(void){
    x=123456789;
    y=362436069;
    z=521288629;
    w=(unsigned)time(NULL);
  }
  Rand(unsigned seed){
    x=123456789;
    y=362436069;
    z=521288629;
    w=seed;
  }
  inline unsigned get(void){
    unsigned t;
    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;
    w = (w^(w>>19))^(t^(t>>8));
    return w;
  }
  inline double getUni(void){
    return get()/4294967296.0;
  }
  inline int get(int a){
    return (int)(a*getUni());
  }
  inline int get(int a, int b){
    return a+(int)((b-a+1)*getUni());
  }
  inline long long get(long long a){
    return(long long)(a*getUni());
  }
  inline long long get(long long a, long long b){
    return a+(long long)((b-a+1)*getUni());
  }
  inline double get(double a, double b){
    return a+(b-a)*getUni();
  }
  inline int getExp(int a){
    return(int)(exp(getUni()*log(a+1.0))-1.0);
  }
  inline int getExp(int a, int b){
    return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  }
}
;
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(int &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(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){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
unsigned long long HashMap_ullP_L[4];
template<class KEY, class VAL> struct HashMap{
  char*used;
  KEY*key;
  VAL*val;
  int mem;
  int n;
  int mask;
  int init_flag;
  VAL init_val;
  HashMap(){
    mem = 0;
    init_flag = 0;
  }
  ~HashMap(){
    free();
  }
  void expand(int nn){
    if(mem >= nn){
      return;
    }
    if(mem){
      free();
    }
    mem = nn;
    used = new char[nn];
    key = new KEY[nn];
    val = new VAL[nn];
  }
  void free(){
    if(mem){
      mem = 0;
      delete[] used;
      delete[] key;
      delete[] val;
    }
  }
  void init(int nn){
    int i;
    n = 1;
    nn = nn + (nn + 1) / 2;
    while(n < nn){
      n *= 2;
    }
    mask = n - 1;
    expand(n);
    for(i=(0);i<(n);i++){
      used[i] = 0;
    }
    init_flag = 0;
  }
  void init(int nn, VAL ini){
    int i;
    n = 1;
    nn = nn + (nn + 1) / 2;
    while(n < nn){
      n *= 2;
    }
    mask = n - 1;
    expand(n);
    for(i=(0);i<(n);i++){
      used[i] = 0;
    }
    init_flag = 1;
    init_val = ini;
  }
  inline int getHash(const int a){
    unsigned long long d = a;
    d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
    return d;
  }
  inline int getHash(const unsigned a){
    unsigned long long d = a;
    d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
    return d;
  }
  inline int getHash(const long long a){
    unsigned long long d = a;
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline int getHash(const unsigned long long a){
    unsigned long long d = a;
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline int getHash(const pair<int,int> a){
    unsigned long long d = (((unsigned long long)a.first) << 32) + ((unsigned long long)a.second);
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline VAL& operator[](const KEY a){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        break;
      }
      if(used[k]==0){
        used[k] = 1;
        key[k] = a;
        if(init_flag){
          val[k] = init_val;
        }
        break;
      }
      k = (k+1) & mask;
    }
    return val[k];
  }
  inline bool exist(const KEY a){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        return true;
      }
      if(used[k]==0){
        break;
      }
      k = (k+1) & mask;
    }
    return false;
  }
  template<class S> inline bool exist(const KEY a, S &res){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        res = val[k];
        return true;
      }
      if(used[k]==0){
        break;
      }
      k = (k+1) & mask;
    }
    return false;
  }
}
;
int main(){
  int mask;
  {
    int i;
    int j;
    int k;
    Rand rnd;
    for(i=(0);i<(20);i++){
      rnd.get(2);
    }
    for(i=(0);i<(4);i++){
      for(j=(0);j<(32);j++){
        k = rnd.get(1,62);
        HashMap_ullP_L[i] |= (1ULL << k);
      }
      HashMap_ullP_L[i] |= (1ULL << 0);
      HashMap_ullP_L[i] |= (1ULL << 63);
    }
  }
  int N;
  int M;
  int P[1000];
  int A[1000];
  int B[1000];
  int C[1000];
  int D[1000];
  int dx;
  int dy;
  HashMap<pair<int,int>,int> hs;
  int res = 0;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(N);e98WHCEY++){
      rd(A[e98WHCEY]);
      rd(B[e98WHCEY]);
    }
  }
  {
    int FmcKpFmN;
    for(FmcKpFmN=(0);FmcKpFmN<(M);FmcKpFmN++){
      rd(C[FmcKpFmN]);
      rd(D[FmcKpFmN]);
    }
  }
  for(mask=(0);mask<(4);mask++){
    int i;
    if(mask==1){
      int i;
      for(i=(0);i<(M);i++){
        C[i] = -C[i];
      }
    }
    if(mask==2){
      int i;
      for(i=(0);i<(M);i++){
        D[i] = -D[i];
      }
    }
    if(mask==3){
      int i;
      for(i=(0);i<(M);i++){
        C[i] = -C[i];
      }
    }
    hs.init(N*M, 0);
    for(i=(0);i<(N);i++){
      int j;
      for(j=(0);j<(M);j++){
        auto iMWUTgY_ = ((A[i] - C[j]));
        auto AlM5nNnR = (( B[i] - D[j]));
        dx=iMWUTgY_;
        dy=AlM5nNnR;
        hs[{dx,dy}] += P[i];
      }
    }
    for(i=(0);i<(N);i++){
      int j;
      for(j=(0);j<(M);j++){
        auto GgkpftXM = ((A[i] - C[j]));
        auto gEg5UqEA = (( B[i] - D[j]));
        dx=GgkpftXM;
        dy=gEg5UqEA;
        chmax(res, hs[{dx,dy}]);
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20211024-1

// --- original code ---
// int N, M, P[1000], A[], B[], C[], D[], dx, dy;
// HashMap<pair<int,int>,int> hs;
// int res = 0;
// rd(N,M,P(N),(A,B)(N),(C,D)(M));
// rep(mask,4){
//   if(mask==1) rep(i,M) C[i] = -C[i];
//   if(mask==2) rep(i,M) D[i] = -D[i];
//   if(mask==3) rep(i,M) C[i] = -C[i];
// 
//   hs.init(N*M, 0);
//   rep(i,N) rep(j,M){
//     (dx, dy) = (A[i] - C[j], B[i] - D[j]);
//     hs[{dx,dy}] += P[i];
//   }
//   rep(i,N) rep(j,M){
//     (dx, dy) = (A[i] - C[j], B[i] - D[j]);
//     res >?= hs[{dx,dy}];
//   }
// }
// wt(res);
0