結果

問題 No.1715 Dinner 2
ユーザー 👑Zack Ni👑Zack Ni
提出日時 2021-10-22 22:19:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,938 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 188,776 KB
実行使用メモリ 7,708 KB
最終ジャッジ日時 2023-10-24 13:33:44
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,708 KB
testcase_01 WA -
testcase_02 AC 2 ms
7,708 KB
testcase_03 AC 2 ms
7,708 KB
testcase_04 AC 3 ms
7,708 KB
testcase_05 AC 3 ms
7,708 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
7,708 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 3 ms
7,708 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
7,708 KB
testcase_19 AC 3 ms
7,708 KB
testcase_20 AC 2 ms
7,708 KB
testcase_21 AC 3 ms
7,708 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  int i;
  pair<T1, pair<T2, T3> >*arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second.first = b[i];
    arr[i].second.second = c[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second.first;
    c[i] = arr[i].second.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);
}
template<class T1, class T2, class T3> void rsortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  sortA_L(N, a, b, c, mem);
  reverse(a, a+N);
  reverse(b, b+N);
  reverse(c, c+N);
}
inline int my_getchar(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread(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();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar();
    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(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite(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(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('-');
  }
  while(s--){
    my_putchar(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int M;
int X[1000+10];
int Y[1000+10];
int Z[1000+10];
int main(){
  int i;
  wmem = memarr;
  rd(N);
  rd(M);
  {
    int PiIOrLma;
    for(PiIOrLma=(0);PiIOrLma<(N);PiIOrLma++){
      rd(X[PiIOrLma]);
      rd(Y[PiIOrLma]);
    }
  }
  rsortA_L(N, X, Y);
  for(i=(0);i<(N);i++){
    Z[i] = Y[i] - X[i];
  }
  for(i=(0);i<(N);i++){
    X[i] = -X[i];
  }
  rsortA_L(N, Z, X, Y);
  for(i=(0);i<(N);i++){
    X[i] = -X[i];
  }
  int ans = -1073709056;
  if(Z[0] >= 0 && Z[1] >= 0){
    int tmp = 0;
    int o = 1073709056;
    tmp -= X[0];
    chmin(o, tmp);
    tmp += Y[0];
    tmp -= X[1];
    chmin(o, tmp);
    chmax(ans, o);
  }
  else{
    int tmp = 0;
    int o = 1073709056;
    for(i=(0);i<(M);i++){
      tmp -= X[i%2];
      chmin(o, tmp);
      tmp += Y[i%2];
      chmin(o, tmp);
    }
    chmax(ans, o);
  }
  wt_L(ans);
  wt_L('\n');
  return 0;
}
// cLay version 20210405-1

// --- original code ---
// //no-unlocked
// int N, M, X[1d3+10], Y[], Z[];
// 
// { 
//     rd(N, M, (X, Y)(N));
//     rsortA(N, X, Y);
//     rep(i, N){
//         Z[i] = Y[i] - X[i];
//     }
//     rep(i, N) X[i] = -X[i];
//     rsortA(N, Z, X, Y);
//     rep(i, N) X[i] = -X[i];
//     int ans = -int_inf;
//     if(Z[0] >= 0 && Z[1] >= 0){
//         int tmp = 0;
//         int o = int_inf;
//         tmp -= X[0];
//         o <?= tmp;
//         tmp += Y[0];
//         tmp -= X[1];
//         o <?= tmp;
//         ans >?= o;
//     }else{
//         int tmp = 0;
//         int o = int_inf;
//         rep(i, M){
//             tmp -= X[i%2];
//             o <?= tmp;
//             tmp += Y[i%2];
//             o <?= tmp;
//         }
//         ans >?= o;
//     }
//     wt(ans);
// }
0