제출 #22317

#제출 시각아이디문제언어결과실행 시간메모리
22317크리콘 B번 문제는 그리디로 풀려요 (#40)Fully Generate (KRIII5_FG)C++98
7 / 7
263 ms130468 KiB
#include<stdio.h>

typedef long long lld;
const lld mx = 1000000000000;
const lld mod = 1000000007;

lld exp(lld a, lld b){
	lld g=1, a0=a, b0=b;
	while(b){
		if(b&1)g=g*a%mod;
		b>>=1, a=a*a%mod;
	}
	return g;
}

int poi[33010101], cnt;
lld sum, N, gop[52000];

int main(){
	poi[1]=1, gop[1]=1;
	poi[2]=poi[3]=2, gop[2]=6; cnt=4; sum=5;
	for(int i=3;; i++){
		gop[i]=1;
		for(int j=poi[i]; j--;){
			poi[cnt]=i;
			gop[i] = gop[i]*cnt % mod;
			cnt++, sum+=i;
		}
		if(sum > mx) break;
	}
	scanf("%lld", &N); lld dap=1;
	lld N2=N, lim=0, comp=0;
	for(int i=1; i<cnt; i++){
		if(N2 >= poi[i])lim++, N2 -= poi[i];
		else { dap = exp(i,N2)%mod; break; }
	}
	for(int i=1; i<cnt; i++){
		if(comp + poi[i] <= lim) dap = dap*exp(gop[i],i)%mod, comp += poi[i];
		else break;
	}
	for(lld i=comp+1; i<=lim; i++) dap = dap*exp(i,poi[i])%mod;
	printf("%lld", dap);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

FG.cpp: In function 'lld exp(lld, lld)':
FG.cpp:8:11: warning: unused variable 'a0' [-Wunused-variable]
  lld g=1, a0=a, b0=b;
           ^
FG.cpp:8:17: warning: unused variable 'b0' [-Wunused-variable]
  lld g=1, a0=a, b0=b;
                 ^
FG.cpp: In function 'int main()':
FG.cpp:31:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &N); lld dap=1;
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...