結果

問題 No.1017 Reiwa Sequence
ユーザー tailstails
提出日時 2020-11-01 03:55:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,502 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 33,280 KB
実行使用メモリ 11,936 KB
最終ジャッジ日時 2024-07-22 05:38:34
合計ジャッジ時間 30,341 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
7,248 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 7 ms
8,932 KB
testcase_13 AC 5 ms
7,740 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 5 ms
8,616 KB
testcase_20 AC 7 ms
9,564 KB
testcase_21 AC 6 ms
9,428 KB
testcase_22 AC 7 ms
9,672 KB
testcase_23 AC 7 ms
9,696 KB
testcase_24 AC 4 ms
7,524 KB
testcase_25 AC 5 ms
8,288 KB
testcase_26 AC 3 ms
6,948 KB
testcase_27 AC 6 ms
9,436 KB
testcase_28 AC 6 ms
8,332 KB
testcase_29 AC 5 ms
8,264 KB
testcase_30 AC 4 ms
9,124 KB
testcase_31 AC 6 ms
7,896 KB
testcase_32 AC 5 ms
7,860 KB
testcase_33 AC 3 ms
6,944 KB
testcase_34 AC 5 ms
10,480 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 AC 5 ms
9,544 KB
testcase_38 AC 2 ms
6,948 KB
testcase_39 AC 4 ms
7,916 KB
testcase_40 AC 9 ms
11,288 KB
testcase_41 AC 8 ms
10,908 KB
testcase_42 AC 10 ms
11,936 KB
testcase_43 AC 9 ms
10,964 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 8 ms
9,900 KB
testcase_46 AC 6 ms
8,820 KB
testcase_47 AC 4 ms
6,940 KB
testcase_48 AC 7 ms
10,632 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 1 ms
6,944 KB
testcase_51 AC 1 ms
6,944 KB
testcase_52 AC 6 ms
9,296 KB
testcase_53 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'yes1':
main.c:10:13: warning: implicit declaration of function 'sprintf' [-Wimplicit-function-declaration]
   10 |         wp+=sprintf(wp,"Yes\n");
      |             ^~~~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'sprintf'
  +++ |+#include <stdio.h>
    1 | #pragma GCC optimize("Ofast")
main.c:10:13: warning: incompatible implicit declaration of built-in function 'sprintf' [-Wbuiltin-declaration-mismatch]
   10 |         wp+=sprintf(wp,"Yes\n");
      |             ^~~~~~~
main.c:10:13: note: include '<stdio.h>' or provide a declaration of 'sprintf'
main.c:21:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   21 |         write(1,&v,wp-(char*)&v);
      |         ^~~~~
main.c:22:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   22 |         _exit(0);
      |         ^~~~~
      |         _Exit
main.c: In function 'yes2':
main.c:27:13: warning: incompatible implicit declaration of built-in function 'sprintf' [-Wbuiltin-declaration-mismatch]
   27 |         wp+=sprintf(wp,"Yes\n");
      |             ^~~~~~~
main.c:27:13: note: include '<stdio.h>' or provide a declaration of 'sprintf'
main.c: At top level:
main.c:67:1: warning: return type defaults to 'int' [-Wimplicit-int]
   67 | main(){
      | ^~~~
main.c: In function 'main':
main.c:68:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   68 |         scanf("%d",&n);
      |         ^~~~~
main.c:68:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:68:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
main.c:68:9: note: include '<stdio.h>' or provide a declaration of 'scanf'

ソースコード

diff #

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

#define OFFS (150000*11+1)
int n,m,m1,a[22];
int v[OFFS*2];

void yes1(int p1,int p2){
	char*wp=(char*)&v;
	wp+=sprintf(wp,"Yes\n");
	for(int i=0;i<m1;++i){
		int b=a[i]*((p1&1?1:p1&2?-1:0)-(p2&1?1:p2&2?-1:0));
		wp+=sprintf(wp,"%d ",b);
		p1>>=2;
		p2>>=2;
	}
	n-=m1;
	while((long)wp&7) *wp++=32;
	while(n>=4) *(long*)wp=0x2030203020302030l, wp+=8, n-=4;
	while(n) *(short*)wp=0x2030, wp+=2, --n;
	write(1,&v,wp-(char*)&v);
	_exit(0);
}

void yes2(int p1,int p2){
	char*wp=(char*)&v;
	wp+=sprintf(wp,"Yes\n");
	if(p1<0) p1=0;
	for(int i=0;i<m;++i){
		if(i==m1) p1=p2;
		wp+=sprintf(wp,"%d ",a[i]*(p1&1?1:p1&2?-1:0));
		p1>>=2;
	}
	n-=m;
	while((long)wp&7) *wp++=32;
	while(n>=4) *(long*)wp=0x2030203020302030l, wp+=8, n-=4;
	while(n) *(short*)wp=0x2030, wp+=2, --n;
	write(1,&v,wp-(char*)&v);
	_exit(0);
}

void f1(int i,int p,int s){
	if(i==m1) return;
	f1(i+1,p,s);
	int s1=s+a[i];
	int p1=p|1<<i*2;
	if(v[s1]&&!((v[s1]&p1>>1|v[s1]>>1&p1)&0x155555)) yes1(v[s1],p1);
	f1(i+1,v[s1]=p1,s1);
	int s2=s-a[i];
	int p2=p|2<<i*2;
	f1(i+1,v[s2]=p2,s2);
}

void f2(int i,int p,int s){
	if(i==m) return;
	f2(i+1,p,s);
	int s1=s-a[i];
	int p1=p|1<<(i-m1)*2;
	if(v[s1]) yes2(v[s1],p1);
	f2(i+1,p1,s1);
	int s2=s+a[i];
	int p2=p|2<<(i-m1)*2;
	if(v[s2]) yes2(v[s2],p2);
	f2(i+1,p2,s2);
}

main(){
	scanf("%d",&n);
	m=n<22?n:22;
	m1=m>>1;
	for(int i=0;i<m;++i) scanf("%d",&a[i]);
	f1(0,0,OFFS);
	v[OFFS]=-1;
	f2(m1,0,OFFS);
	write(1,"No\n",3);
	_exit(0);
}
0