結果
問題 | No.127 門松もどき |
ユーザー | LayCurse |
提出日時 | 2015-01-14 00:30:38 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,948 bytes |
コンパイル時間 | 1,705 ms |
コンパイル使用メモリ | 171,652 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 11:17:39 |
合計ジャッジ時間 | 2,645 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
ソースコード
#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);} void reader(ll *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);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);} template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} 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);} void writer(ll x, char c){int s=0,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)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template<class T> void writerLn(T x){writer(x,'\n');} template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} template<class T> void sort(int N, T a[], void *mem = NULL){sort(a,a+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;} template<class T1, class T2, class T3, class T4> void sort(int N, T1 a[], T2 b[], T3 c[], T4 d[], void *mem){int i;pair<pair<T1,T2>,pair<T3,T4> > *r=(pair<pair<T1,T2>,pair<T3,T4> >*)mem;rep(i,N)r[i].first.first=a[i],r[i].first.second=b[i],r[i].second.first=c[i],r[i].second.second=d[i];sort(r,r+N);rep(i,N)a[i]=r[i].first.first,b[i]=r[i].first.second,c[i]=r[i].second.first,d[i]=r[i].second.second;} template<class T> struct segtreeMinVal{ int size, mem; T *val, *minVal; void malloc(int N){mem=N;val=(T*)std::malloc(sizeof(T)*N);minVal=(T*)std::malloc(sizeof(T)*N*4);} void free(void){mem=0;std::free(val);std::free(minVal);} void init_sub(int node, int left, int right){int sz=right-left,n1=node*2+1,n2=node*2+2;if(sz==1)minVal[node]=val[left];else {init_sub(n1,left,left+sz/2);init_sub(n2,left+sz/2,right);minVal[node]=min(minVal[n1], minVal[n2]);}} void init(int N, int zerofill = 0){int i;size=N;if(zerofill)rep(i,N)val[i]=0;init_sub(0,0,N);} void change_sub(int node, int left, int right, int n){int sz=right-left,n1=node*2+1,n2=node*2+2;if(n<left||n>=right)return;if(sz==1)minVal[node]=val[left];else {change_sub(n1,left,left+sz/2,n);change_sub(n2,left+sz/2,right,n);minVal[node]=min(minVal[n1],minVal[n2]);}} void change(int n, T v){if(val[n]==v)return;val[n]=v;change_sub(0,0,size,n);} T get_minVal_sub(int node, int left, int right, int a, int b){int sz=right-left,n1=node*2+1,n2=node*2+2;if(a<left)a=left;if(b>right)b=right;if(a>=b)return numeric_limits<T>::max();if(a==left&&b==right)return minVal[node];return min(get_minVal_sub(n1,left,left+sz/2,a,b), get_minVal_sub(n2,left+sz/2,right,a,b));} T get_minVal(int a, int b){return get_minVal_sub(0,0,size,a,b);} }; int N, A[4000], ind[4000]; int d1[4000], d2[4000]; int main(){ int i, j, k, mx; int res = 0, tmp; void *mem = malloc(10000000); segtreeMinVal<int> t1, t2; reader(&N); rep(i,N) reader(A+i); t1.malloc(N+10); t2.malloc(N+10); rep(i,N) ind[i] = i, A[i] *= -1; sort(N, A, ind, mem); t1.init(N+10, 1); t2.init(N+10, 1); rep(k,N){ i = ind[k]; if(k && A[k] != A[k-1]){ for(j=k-1;j>=0;j--){ if(A[j]!=A[k-1]) break; t1.change(ind[j], -d1[ind[j]]); t2.change(ind[j], -d2[ind[j]]); } } d1[i] = -t2.get_minVal(0,i) + 1; d2[i] = -t1.get_minVal(i+1,N) + 1; } rep(i,N) res = max(res, max(d1[i],d2[i])); writerLn(res); return 0; }