結果

問題 No.1419 Power Moves
ユーザー tailstails
提出日時 2021-03-11 12:35:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,395 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 33,696 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-13 01:37:45
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 1 ms
6,820 KB
testcase_05 AC 1 ms
6,820 KB
testcase_06 AC 1 ms
6,816 KB
testcase_07 AC 1 ms
6,816 KB
testcase_08 AC 1 ms
6,816 KB
testcase_09 AC 2 ms
6,816 KB
testcase_10 AC 1 ms
6,820 KB
testcase_11 AC 1 ms
6,816 KB
testcase_12 AC 2 ms
6,820 KB
testcase_13 AC 2 ms
6,820 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 AC 2 ms
6,816 KB
testcase_16 AC 2 ms
6,816 KB
testcase_17 AC 1 ms
6,820 KB
testcase_18 AC 1 ms
6,820 KB
testcase_19 AC 1 ms
6,816 KB
testcase_20 AC 1 ms
6,816 KB
testcase_21 AC 2 ms
6,816 KB
testcase_22 AC 2 ms
6,816 KB
testcase_23 AC 2 ms
6,816 KB
testcase_24 AC 2 ms
6,820 KB
testcase_25 AC 1 ms
6,816 KB
testcase_26 AC 2 ms
6,816 KB
testcase_27 AC 1 ms
6,820 KB
testcase_28 AC 2 ms
6,816 KB
testcase_29 AC 2 ms
6,816 KB
testcase_30 AC 2 ms
6,816 KB
testcase_31 AC 2 ms
6,820 KB
testcase_32 AC 2 ms
6,816 KB
testcase_33 AC 2 ms
6,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:41:1: warning: return type defaults to 'int' [-Wimplicit-int]
   41 | main(){
      | ^~~~
main.c: In function 'main':
main.c:60:25: warning: implicit declaration of function 'sprintf' [-Wimplicit-function-declaration]
   60 |                         sprintf(&b,"%11d\n%11d\n",q1,q0);
      |                         ^~~~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'sprintf'
  +++ |+#include <stdio.h>
    1 | #pragma GCC optimize("Ofast")
main.c:60:25: warning: incompatible implicit declaration of built-in function 'sprintf' [-Wbuiltin-declaration-mismatch]
   60 |                         sprintf(&b,"%11d\n%11d\n",q1,q0);
      |                         ^~~~~~~
main.c:60:25: note: include '<stdio.h>' or provide a declaration of 'sprintf'
main.c:60:33: warning: passing argument 1 of 'sprintf' from incompatible pointer type [-Wincompatible-pointer-types]
   60 |                         sprintf(&b,"%11d\n%11d\n",q1,q0);
      |                                 ^~
      |                                 |
      |                                 struct <anonymous> *
main.c:60:33: note: expected 'char *' but argument is of type 'struct <anonymous> *'
main.c:65:33: warning: passing argument 1 of 'sprintf' from incompatible pointer type [-Wincompatible-pointer-types]
   65 |                         sprintf(&b,"%11d\n%11d\n",q0,q0);
      |                                 ^~
      |                                 |
      |                                 struct <anonymous> *
main.c:65:33: note: expected 'char *' but argument is of type 'struct <anonymous> *'
main.c:70:33: warning: passing argument 1 of 'sprintf' from incompatible pointer type [-Wincompatible-pointer-types]
   70 |                         sprintf(&b,"%11d\n%11d\n",q1,q1);
      |                                 ^~
      |                                 |
      |                                 struct <anonymous> *
main.c:70:33: note: expected 'char *' but argument is of type 'st

ソースコード

diff #

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

char*mmap();
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

int wbuf[1<<26];

struct BufI4 { int a[4]; };
struct BufI6 { int a[6]; };

#define MD 1000000007

long modpow(long a, long b, long m){
  long r=1;
  while(b){
    if(b&1){
      r=r*a%m;
    }
    b>>=1;
    a=a*a%m;
  }
  return r;
}

int inverse(int a){
  int b=MD;
  int u=1;
  int v=0;
  while(b){
    int q=a/b,t;
	t=b, b=a-q*b, a=t;
	t=v, v=u-q*v, u=t;
  }
  if(u<0){
    u+=MD;
  }
  return u;
}

main(){
	char*rp=mmap(0l,1l<<28,1,2,0,0ll);
	RD(n);
	RD(k);
	int r=modpow(2,k-1,n);
	int q=(modpow(2,k-1,MD)-r+MD)%MD*inverse(n)*(n&1?2:4)%MD;
	int d=modpow((MD+1)/2,k,MD);
	q=1l*q*d%MD;
	r*=2;
	int*wp=wbuf;
	if(n&1){
		struct{ struct BufI6 b; int z; }b;
		if(n<r){
			r-=n;
			q=(q+d)%MD;
			int q0=q;
			int q1=(q+d)%MD;
			int e=r<n-r?r:n-r;
			int i=0;
			sprintf(&b,"%11d\n%11d\n",q1,q0);
			for(;i<e;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q0,q0);
			for(;i<n-r;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q1,q1);
			for(;i<r;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q0,q1);
			for(;i<n;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
		}else{
			int q0=q;
			int q1=(q+d)%MD;
			int e=r<n-r?r:n-r;
			int i=0;
			sprintf(&b,"%11d\n%11d\n",q0,q1);
			for(;i<e;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q0,q0);
			for(;i<n-r;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q1,q1);
			for(;i<r;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
			sprintf(&b,"%11d\n%11d\n",q1,q0);
			for(;i<n;i+=2){
				*(struct BufI6*)wp=b.b;
				wp+=6;
			}
		}
		wp-=3;
	}else{
		struct{ struct BufI4 b; int z; }b;
		if(n<r){
			r-=n;
			q=(q+d)%MD;
			q=(q+d)%MD;
		}
		int q0=q;
		int q1=(q0+d)%MD;
		int q2=(q1+d)%MD;
		int e=r<n-r?r:n-r;
		int i=0;
		sprintf(&b,"  0\n%11d\n",q1);
		for(;i<e;i+=2){
			*(struct BufI4*)wp=b.b;
			wp+=4;
		}
		sprintf(&b,"  0\n%11d\n",q0);
		for(;i<n-r;i+=2){
			*(struct BufI4*)wp=b.b;
			wp+=4;
		}
		sprintf(&b,"  0\n%11d\n",q2);
		for(;i<r;i+=2){
			*(struct BufI4*)wp=b.b;
			wp+=4;
		}
		sprintf(&b,"  0\n%11d\n",q1);
		for(;i<n;i+=2){
			*(struct BufI4*)wp=b.b;
			wp+=4;
		}
	}
	write(1,wbuf,(wp-wbuf)*sizeof*wbuf);
	_exit(0);
}
0