結果
問題 | No.972 選び方のスコア |
ユーザー | LayCurse |
提出日時 | 2020-01-17 21:52:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 4,828 bytes |
コンパイル時間 | 3,242 ms |
コンパイル使用メモリ | 221,276 KB |
実行使用メモリ | 6,784 KB |
最終ジャッジ日時 | 2024-06-25 19:38:14 |
合計ジャッジ時間 | 4,889 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
6,528 KB |
testcase_01 | AC | 27 ms
6,656 KB |
testcase_02 | AC | 26 ms
6,400 KB |
testcase_03 | AC | 15 ms
5,376 KB |
testcase_04 | AC | 28 ms
6,656 KB |
testcase_05 | AC | 27 ms
6,784 KB |
testcase_06 | AC | 28 ms
6,656 KB |
testcase_07 | AC | 21 ms
5,760 KB |
testcase_08 | AC | 27 ms
6,656 KB |
testcase_09 | AC | 26 ms
6,528 KB |
testcase_10 | AC | 26 ms
6,528 KB |
testcase_11 | AC | 26 ms
6,656 KB |
testcase_12 | AC | 28 ms
6,656 KB |
testcase_13 | AC | 26 ms
6,656 KB |
testcase_14 | AC | 26 ms
6,656 KB |
testcase_15 | AC | 28 ms
6,656 KB |
testcase_16 | AC | 28 ms
6,656 KB |
testcase_17 | AC | 28 ms
6,656 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 28 ms
6,656 KB |
testcase_20 | AC | 27 ms
6,656 KB |
testcase_21 | AC | 27 ms
6,656 KB |
testcase_22 | AC | 27 ms
6,656 KB |
testcase_23 | AC | 27 ms
6,528 KB |
testcase_24 | AC | 27 ms
6,656 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void *wmem; char memarr[96000000]; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } 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); } void sortF_L(int N, unsigned A[], void *mem = wmem){ int i; int m; int bt; unsigned *arr; unsigned c; int *sz; if(N < 256){ sort(A, A+N); return; } bt = sizeof(unsigned) * 8; walloc1d(&arr, N, &mem); walloc1d(&sz, N, &mem); for(m=0;m<bt;m+=8){ for(i=(0);i<(257);i++){ sz[i] = 0; } for(i=(0);i<(N);i++){ sz[ 1+((A[i]>>m)&255u) ]++; } for(i=(1);i<(257);i++){ sz[i] += sz[i-1]; } for(i=(0);i<(N);i++){ c = ((A[i]>>m)&255u); arr[sz[c]++] = A[i]; } swap(A, arr); } } void sortF_L(int N, int A[], void *mem = wmem){ int i; int x; int y; int z; int *arr; unsigned *send; if(N < 256){ sort(A, A+N); return; } send = (unsigned*)A; sortF_L(N, send, mem); if(A[0] < 0 || A[N-1] >= 0){ return; } x = 0; y = N; while(x < y){ z = (x+y) / 2; if(A[z] < 0){ y = z; } else{ x = z+1; } } walloc1d(&arr, N, &mem); z = 0; for(i=(x);i<(N);i++){ arr[z++] = A[i]; } for(i=(0);i<(x);i++){ arr[z++] = A[i]; } for(i=(0);i<(N);i++){ A[i] = arr[i]; } } void sortF_L(int N, unsigned long long A[], void *mem = wmem){ int i; int m; int bt; unsigned long long *arr; unsigned c; int *sz; if(N < 512){ sort(A, A+N); return; } bt = sizeof(unsigned long long) * 8; walloc1d(&arr, N, &mem); walloc1d(&sz, N, &mem); for(m=0;m<bt;m+=8){ for(i=(0);i<(257);i++){ sz[i] = 0; } for(i=(0);i<(N);i++){ sz[ 1+((A[i]>>m)&255u) ]++; } for(i=(1);i<(257);i++){ sz[i] += sz[i-1]; } for(i=(0);i<(N);i++){ c = ((A[i]>>m)&255u); arr[sz[c]++] = A[i]; } swap(A, arr); } } void sortF_L(int N, long long A[], void *mem = wmem){ int i; int x; int y; int z; long long *arr; unsigned long long *send; if(N < 512){ sort(A, A+N); return; } send = (unsigned long long*)A; sortF_L(N, send, mem); if(A[0] < 0 || A[N-1] >= 0){ return; } x = 0; y = N; while(x < y){ z = (x+y) / 2; if(A[z] < 0){ y = z; } else{ x = z+1; } } walloc1d(&arr, N, &mem); z = 0; for(i=(x);i<(N);i++){ arr[z++] = A[i]; } for(i=(0);i<(x);i++){ arr[z++] = A[i]; } for(i=(0);i<(N);i++){ A[i] = arr[i]; } } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ 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){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template<class S, class T> inline S chmax(S &a, T b){ if(a<b){ a=b; } return a; } int N; int A[200000]; long long s[200000+1]; int main(){ wmem = memarr; int i; int j; int k; int m; long long res = 0; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } sortF_L(N,A); for(i=(0);i<(N);i++){ s[i+1] = s[i] + A[i]; } for(i=(0);i<(N);i++){ k =min_L(i, N-1-i); int WYIGIcGE; int t_ynMSdg; int KrdatlYV; WYIGIcGE = 0; t_ynMSdg = k; while(WYIGIcGE < t_ynMSdg){ if((WYIGIcGE + t_ynMSdg)%2==0){ KrdatlYV = (WYIGIcGE + t_ynMSdg) / 2; } else{ KrdatlYV = (WYIGIcGE + t_ynMSdg + 1) / 2; } if(A[i-KrdatlYV]+A[N-KrdatlYV] >= 2*A[i]){ WYIGIcGE = KrdatlYV; } else{ t_ynMSdg = KrdatlYV - 1; } } m =t_ynMSdg; chmax(res, (s[N] - s[N-m]) + (s[i] - s[i-m]) - 2LL * m * A[i]); } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200112-1 // --- original code --- // int N, A[2d5]; // ll s[2d5+1]; // { // int i, j, k, m; // ll res = 0; // rd(N,A(N)); // sortF(N,A); // rep(i,N) s[i+1] = s[i] + A[i]; // rep(i,N){ // k = min(i, N-1-i); // m = bsearch_max[int,m,0,k](A[i-m]+A[N-m] >= 2A[i]); // res >?= (s[N] - s[N-m]) + (s[i] - s[i-m]) - 2LL * m * A[i]; // } // wt(res); // }