結果

問題 No.14 最小公倍数ソート
ユーザー tailstails
提出日時 2024-04-25 11:38:58
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,158 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 27,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 11:39:00
合計ジャッジ時間 1,641 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘f2’:
main.c:68:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   68 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c: In function ‘main’:
main.c:75:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   75 |         _exit(0);
      |         ^~~~~
main.c:75:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

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,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define reps(v,s,e) for(typeof(e) v=s;v<e;++v)
#define repst(v,s,e,t) for(typeof(e) v=s;v<e;v+=t)

char wbuf[1<<25];
int n;
int x;
int cs[10001];
int dn[10001];
short ds[10001][64];
int ps[10001];

void f0(){
	reps(i,2,10001){
		repst(j,i,10001,i){
			ds[j][dn[j]++]=i;
		}
	}
	rep(i,10001){
		ps[i]=1;
	}
}

void f1(){
	rd_init();
	n=rd();
	x=rd();
	rep(i,n-1){
		cs[rd()]+=1;
	}
}

void f2(){
	char*wp=wbuf;
	wt(x);
	rep(i,n-1){
		while(!cs[ps[1]]){
			ps[1]+=1;
		}
		int b=x*ps[1];
		int y=ps[1];
		rep(j,dn[x]){
			int d=ds[x][j];
			int k=d*ps[d];
			while(k<=10000){
				if(cs[k]){
					if(b>x*ps[d]){
						b=x*ps[d];
						y=k;
					}
					break;
				}
				ps[d]+=1;
				k+=d;
			}
		}
		*wp++=' ';
		wt(y);
		x=y;
		cs[x]-=1;
	}
	write(1,wbuf,wp-wbuf);
}

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