結果

問題 No.54 Happy Hallowe'en
ユーザー LayCurse
提出日時 2015-02-02 03:21:44
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,476 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 163,452 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 17:11:04
合計ジャッジ時間 1,975 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
#define ll long long
#define ull unsigned ll
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x
    =(*x)*10+k-'0';}if(m)(*x)=-(*x);}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
void writer(int x, char c){int s=0,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)mypc('-');while(s--)mypc(f[s]+'0'
    );mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T1, class T2> void sort(int N, T1 a[], T2 b[], void *mem){int i;pair<T1,T2> *r=(pair<T1, T2>*)mem;rep(i,N)r[i].first=a[i],r[i].second
    =b[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second;}
template<class T1, class T2, class T3> void sort(int N, T1 a[], T2 b[], T3 c[], void *mem){int i;pair<T1,pair<T2,T3> > *r=(pair<T1,pair<T2,T3> >*)mem
    ;rep(i,N)r[i].first=a[i],r[i].second.first=b[i],r[i].second.second=c[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second.first,c[i]=r[i]
    .second.second;}
void bitOR(ull a[], ull b[], int stA, int stB, int len){int i,B,E,R,Y,X,G,Z;static ull p[65],q[65];static int f=0;if(!f){f=1;p[0]=0;rep(i,64)p[i+1]
    =(p[i]<<1)|1ULL;rep(i,65)q[i]=p[64]^p[i];}B=stA/64;E=stA%64;R=(stA+len)/64;Y=(stA+len)%64;X=stA-stB;G=X/64;Z=X%64;if(Z<0)Z+=64,G--;if(stA>stB){if
    (B==R){if(Z)b[B-G-1]|=(a[B]&p[Y]&q[E])<<(64-Z);b[B-G]|=(a[B]&p[Y]&q[E])>>Z;}else{if(Z)b[B-G-1]|=(a[B]&q[E])<<(64-Z);b[B-G]|=(a[B]&q[E])>>Z;REP(i,B
    +1,R){if(Z)b[i-G-1]|=a[i]<<(64-Z);b[i-G]|=a[i]>>Z;}if(Z)b[R-G-1]|=(a[R]&p[Y])<<(64-Z);b[R-G]|=(a[R]&p[Y])>>Z;}}else{if(B==R){b[B-G]|
    =(a[B]&p[Y]&q[E])>>Z;if(Z)b[B-G-1]|=(a[B]&p[Y]&q[E])<<(64-Z);}else{b[R-G]|=(a[R]&p[Y])>>Z;if(Z)b[R-G-1]|=(a[R]&p[Y])<<(64-Z);for(i=R-1;i>B;i
    --){b[i-G]|=a[i]>>Z;if(Z)b[i-G-1]|=a[i]<<(64-Z);}b[B-G]|=(a[B]&q[E])>>Z;if(Z)b[B-G-1]|=(a[B]&q[E])<<(64-Z);}}}
char memarr[77000000]; void *mem = memarr;
int N, V[20000], T[20000], val[20000];
ull dp[400];
int main(){
int i, j, k, loop;
int res=0, tmp;
reader(&N);
rep(i,N) reader(V+i, T+i);
rep(i,N) val[i] = T[i]+V[i];
sort(N, val, T, V, mem);
rep(i,400) dp[i] = 0;
dp[0] = 1;
rep(k,N) bitOR(dp, dp, 0, V[k], T[k]);
for(i=20000;i>=0;i--) if(dp[i/64]&(1ULL<<(i%64))) { res = i; break; }
writerLn(res);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2