結果

問題 No.1872 Dictionary Order
ユーザー tailstails
提出日時 2022-03-15 23:30:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 36,060 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 22:37:35
合計ジャッジ時間 2,552 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 1 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 1 ms
4,372 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 1 ms
4,372 KB
testcase_25 AC 1 ms
4,372 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 1 ms
4,372 KB
testcase_31 AC 1 ms
4,372 KB
testcase_32 AC 1 ms
4,372 KB
testcase_33 AC 1 ms
4,372 KB
testcase_34 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:76:17: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   76 |                 write(1,wprev,wp-wprev);
      |                 ^~~~~
main.c:80:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   80 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

#define rd() ({ long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}v; })
#define wt(v) {ulong _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;}
#define wtrev(v) {ulong _z=v;do*--wprev=_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;
char wbuf[1<<25];

#define KPMAX 2000
#define KPLEN (KPMAX/64+2)
ulong kp[2001][KPLEN];

unsigned a[2000];
unsigned p[2000];

int main(){
	long n,m;
	{
		char*mmap();
		char*rp=mmap(0l,1l<<25,1,2,0,0ll);
		n=rd();
		m=rd();
		rep(i,n){
			a[i]=rd();
		}
		rep(i,n){
			p[rd()-1]=i;
		}
	}
	kp[n][1]=1;
	rrep(i,n){
		ulong x=a[i];
		ulong q=(x>>6)+1;
		ulong r=x&63;
		rep(j,q){
			kp[i][j]=kp[i+1][j];
		}
		if(r){
			rep(j,KPLEN-q){
				kp[i][j+q]=kp[i+1][j+q]|kp[i+1][j+1]<<r|kp[i+1][j]>>64-r;
			}
		}
		else{
			rep(j,KPLEN-q){
				kp[i][j+q]=kp[i+1][j+q]|kp[i+1][j+1];
			}
		}
	}
	if(kp[0][(m>>6)+1]&1l<<m){
		char*wp=wbuf+64;
		long z=0;
		long y=-1;
		while(m){
			rep(j,n){
				long i=p[j];
				if(i>y){
					long t=m-a[i];
					if(t>=0&&kp[i+1][(t>>6)+1]&1l<<t){
						wt(i+1);
						*wp++=' ';
						m=t;
						y=i;
						z+=1;
						break;
					}
				}
			}
		}
		char*wprev=wbuf+64;
		*--wprev='\n';
		wtrev(z);
		write(1,wprev,wp-wprev);
	}else{
		write(1,"-1",2);
	}
	_exit(0);
}
0