結果

問題 No.2221 Set X
コンテスト
ユーザー 👑 tails
提出日時 2023-02-23 04:27:42
言語 C90
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,278 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 114 ms
コンパイル使用メモリ 26,420 KB
最終ジャッジ日時 2026-02-24 01:12:33
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'main':
main.c:7:18: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    7 | #define rep(v,e) for(long v=0;v<e;++v)
      |                  ^~~
main.c:23:17: note: in expansion of macro 'rep'
   23 |                 rep(i,n){
      |                 ^~~
main.c:7:18: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
    7 | #define rep(v,e) for(long v=0;v<e;++v)
      |                  ^~~
main.c:23:17: note: in expansion of macro 'rep'
   23 |                 rep(i,n){
      |                 ^~~
main.c:8:19: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    8 | #define rrep(v,e) for(long v=e;v--;)
      |                   ^~~
main.c:29:9: note: in expansion of macro 'rrep'
   29 |         rrep(i,n-1){
      |         ^~~~
main.c:7:18: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    7 | #define rep(v,e) for(long v=0;v<e;++v)
      |                  ^~~
main.c:37:17: note: in expansion of macro 'rep'
   37 |                 rep(j,200001){
      |                 ^~~
main.c:41:14: error: redefinition of 'i'
   41 |         rrep(i,n-1){
      |              ^
main.c:8:28: note: in definition of macro 'rrep'
    8 | #define rrep(v,e) for(long v=e;v--;)
      |                            ^
main.c:29:14: note: previous definition of 'i' with type 'long int'
   29 |         rrep(i,n-1){
      |              ^
main.c:8:28: note: in definition of macro 'rrep'
    8 | #define rrep(v,e) for(long v=e;v--;)
      |                            ^
main.c:8:19: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    8 | #define rrep(v,e) for(long v=e;v--;)
      |                   ^~~
main.c:41:9: note: in expansion of macro 'rrep'
   41 |         rrep(i,n-1){
      |         ^~~~
main.c:52:17: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   52 |                 for(int x=1;++x<bf-

ソースコード

diff #
raw source code

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

#define getrp() ({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) ({ulong _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define rep(v,e) for(long v=0;v<e;++v)
#define rrep(v,e) for(long v=e;v--;)

typedef unsigned long ulong;

int a[100000];
int ls[100000],rs[100000];
int es[100000],en[200001];

int main(){
	int bx;
	int bf;
	long n;
	{
		char*rp=getrp();
		n=rd();
		rep(i,n){
			a[i]=rd();
			ls[i]=i;
			rs[i]=i;
		}
	}
	rrep(i,n-1){
		int d=a[i+1]-a[i];
		if(d<200000){
			++en[d];
		}
	}
	{
		int t=0;
		rep(j,200001){
			en[j]=t+=en[j];
		}
	}
	rrep(i,n-1){
		int d=a[i+1]-a[i];
		if(d<200000){
			es[--en[d]]=i;
		}
	}

	bx=1;
	bf=n*2;
	{
		int ei=0;
		for(int x=1;++x<bf-1;){
			while(ei<en[x+1]){
				int i=es[ei++];
				int l=ls[i];
				int r=rs[i+1];
				rs[l]=r;
				ls[r]=l;
			}
			int f=0;
			int o=(bf+x)/(x+1);
			for(int i=0;i<n;){
				int r=rs[i];
				f+=a[r]/x-a[i]/x+1;
				if(f>=o){
					goto hoge;
				}
				i=r+1;
			}
			f*=x+1;
			if(bf>f){
				bf=f;
				bx=x;
			}
			hoge:;
		}
	}
	{
		char wbuf[64],*wp=wbuf+sizeof wbuf;
		*--wp='\n';
		wt(bf);
		*--wp='\n';
		wt(bx);
		write(1,wp,wbuf+sizeof wbuf-wp);
	}
	_exit(0);
}
0