結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー LayCurseLayCurse
提出日時 2021-01-15 22:19:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 868 ms / 2,000 ms
コード長 5,050 bytes
コンパイル時間 2,799 ms
コンパイル使用メモリ 221,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 17:36:11
合計ジャッジ時間 11,254 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 782 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 80 ms
4,380 KB
testcase_10 AC 829 ms
4,376 KB
testcase_11 AC 816 ms
4,376 KB
testcase_12 AC 697 ms
4,380 KB
testcase_13 AC 854 ms
4,380 KB
testcase_14 AC 808 ms
4,380 KB
testcase_15 AC 832 ms
4,376 KB
testcase_16 AC 868 ms
4,380 KB
testcase_17 AC 856 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2>*arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
template<class T1> void rsortA_L(int N, T1 a[], void *mem = wmem){
  sortA_L(N, a, mem);
  reverse(a, a+N);
}
template<class T1, class T2> void rsortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  sortA_L(N, a, b, mem);
  reverse(a, a+N);
  reverse(b, b+N);
}
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;
  }
}
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(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
long long M;
long long A[3000];
long long B[3000];
long long C[3000];
int main(){
  wmem = memarr;
  int i;
  int j;
  int k;
  long long res = -4611686016279904256LL;
  long long tmp;
  multiset<long long> s;
  multiset<long long>::iterator it;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
      rd(C[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    if(A[i] > C[i]){
      swap(A[i], C[i]);
    }
    ;
  }
  rsortA_L(N,A,C);
  sortA_L(N,B);
  for(k=(0);k<(N+1);k++){
    tmp = 0;
    s.clear();
    j = 0;
    for(i=(k)-1;i>=(0);i--){
      while(j < N && A[j] > B[i]){
        s.insert(C[j]);
        j++;
      }
      if(s.size() == 0){
        goto RZTsC2BF;
      }
      it = s.end();
      it--;
      tmp += *it;
      s.erase(it);
    }
    while(j < N){
      s.insert(C[j++]);
    }
    for(i=(k);i<(N);i++){
      it = s.begin();
      if(B[i] <= *it){
        goto RZTsC2BF;
      }
      s.erase(it);
      tmp += B[i];
    }
    chmax(res, tmp);
    RZTsC2BF:;
  }
  if(res == -4611686016279904256LL){
    wt_L("NO");
    wt_L('\n');
    return 0;
  }
  wt_L("YES");
  wt_L('\n');
  if(res >= M){
    wt_L("KADOMATSU!");
    wt_L('\n');
  }
  else{
    wt_L("NO");
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210103-1 [bug fixed 1]

// --- original code ---
// int N; ll M, A[3000], B[3000], C[3000];
// {
//   int i, j, k;
//   ll res = -ll_inf, tmp;
//   multiset<ll> s;
//   multiset<ll>::iterator it;
//   rd(N,M,(A,B,C)(N));
//   rep(i,N) sortE(A[i], C[i]);
//   rsortA(N,A,C);
//   sortA(N,B);
// 
//   rep(k,N+1){
//     tmp = 0;
//     s.clear();
//     j = 0;
//     rrep(i,k){
//       while(j < N && A[j] > B[i]){
//         s.insert(C[j]);
//         j++;
//       }
//       if(s.size() == 0) break_continue;
//       it = s.end();
//       it--;
//       tmp += *it;
//       s.erase(it);
//     }
//     while(j < N) s.insert(C[j++]);
//     rep(i,k,N){
//       it = s.begin();
//       if(B[i] <= *it) break_continue;
//       s.erase(it);
//       tmp += B[i];
//     }
//     res >?= tmp;
//   }
// 
//   if(res == -ll_inf) wt("NO"), return 0;
//   wt("YES");
//   wt(if[res >= M, "KADOMATSU!", "NO"]);
// }
0