結果

問題 No.9 モンスターのレベル上げ
ユーザー tails
提出日時 2024-12-13 10:51:38
言語 C90
(gcc 12.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,393 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 27,776 KB
最終ジャッジ日時 2025-03-28 11:19:09
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'sort_aux':
main.c:18:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   18 |         for(int i=0;i<256;++i){
      |         ^~~
main.c:18:9: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
main.c:21:17: error: redefinition of 'i'
   21 |         for(int i=0;i<n;++i){
      |                 ^
main.c:18:17: note: previous definition of 'i' with type 'int'
   18 |         for(int i=0;i<256;++i){
      |                 ^
main.c:21:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   21 |         for(int i=0;i<n;++i){
      |         ^~~
main.c:25:17: error: redefinition of 'i'
   25 |         for(int i=0;i<256;++i){
      |                 ^
main.c:21:17: note: previous definition of 'i' with type 'int'
   21 |         for(int i=0;i<n;++i){
      |                 ^
main.c:25:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   25 |         for(int i=0;i<256;++i){
      |         ^~~
main.c:30:17: error: redefinition of 'i'
   30 |         for(int i=0;i<n;++i){
      |                 ^
main.c:25:17: note: previous definition of 'i' with type 'int'
   25 |         for(int i=0;i<256;++i){
      |                 ^
main.c:30:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   30 |         for(int i=0;i<n;++i){
      |         ^~~
main.c: In function 'f1':
main.c:38:13: error: expected ';' before 'i'
   38 |         rep(i,n){
      |             ^
main.c:8:31: note: in definition of macro 'rep'
    8 | #define rep(v,e) for(typeof(e)v=0;v<e;++v)
      |                               ^
main.c:38:13: error: 'i' undeclared (first use in this function)
   38 |         rep(i,n){
      |             ^
main.c:8:35: note: in definition of macro 'rep'
    8 | #define rep(v,e) for(typeof(e)v=0;v<e;++v)
      |                                   ^
main.c:38:13: note: each undeclared identifier is reported o

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({unsigned _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
#define rep(v,e) for(typeof(e)v=0;v<e;++v)
#define chmax(v,a) (v=v>=(a)?v:(a))

int n;
unsigned a[1500];
unsigned q[1501];
unsigned b[1500];

void sort_aux(unsigned*a,unsigned*b){
	int c[256];
	for(int i=0;i<256;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&255];
	}
	int t=0;
	for(int i=0;i<256;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		b[c[a[i]&255]++]=a[i]>>8|a[i]<<24;
	}
}

void f1(){
	rd_init();
	n=rd();
	rep(i,n){
		a[i]=rd()<<16;
	}
	rep(i,n){
		b[i]=rd()>>1<<16|1;
	}
}

void f2(){
	sort_aux(a,q);
	sort_aux(q,a);
	sort_aux(a,q);
	sort_aux(q,a);
	q[n]=~0;
}

void f3(){
	int z=n;
	rep(h,n){
		rep(i,n){
			q[i]=a[i];
		}
		int w=0;
		rep(i,n){
			int j=h+i;
			j-=j>=n?n:0;
			unsigned t=q[0]+b[j];
			unsigned y=t&0xffff;
			if(y>=z){
				goto hoge;
			}
			chmax(w,y);
			int k=0;
			while(k*2<n-1){
				int c=q[k*2+1]<q[k*2+2]?k*2+1:k*2+2;
				if(t<=q[c]){
					break;
				}
				q[k]=q[c];
				k=c;
			}
			q[k]=t;
		}
		z=w;
		hoge:;
	}
	wt1(z);
}

int main(){
	f1();
	f2();
	f3();
	_exit(0);
}
0