답안 #22436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22436 2017-04-30T04:40:14 Z 예제는 나오는데 왜 틀리죠??(#895, baactree) Fully Generate (KRIII5_FG) C++14
0 / 7
500 ms 788532 KB
// =====================================================================================
// 
//       Filename:  fg.cpp
//        Created:  2017년 04월 30일 12시 39분 09초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  [email protected]
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
typedef long long ll;
ll _pow(ll a, ll b){
	if(b==0)
		return 1;
	ll temp=_pow(a, b/2);
	temp=(temp*temp)%mod;
	if(b&1)
		return (temp*a)%mod;
	return temp;
}
int main(){
	int idx=1;
	vector<pair<int, int> > arr;
	arr.push_back({0, 1});
	arr.push_back({1, 1});
	arr.push_back({2, 1});
	arr.push_back({2, 1});
	for(int i=3;i<60000;i++){
		for(int j=0;j<arr[i].first;j++)
			arr.push_back({i, 1});
	}
	for(int i=arr.size()-1;i>=0;i--)
		if(arr[i].first==arr[i+1].first)
			arr[i].second=arr[i+1].second+1;
	long long n;
	scanf("%lld", &n);
	int k;
	long long sum=0;
	for(int i=1;i<arr.size();i++){
		sum+=arr[i].first;
		if(sum>n){
			k=i;
			break;
		}
	}
	ll ans=1;
	for(int i=1;i<k;){
		ll cnt=arr[i].second;
		if(i+cnt>k)
			cnt=1;
		ll now=1;
		for(int j=i;j<i+cnt;j++)
			now=(now*j)%mod;
		ans=(ans*_pow(now, arr[i].first))%mod;
		n-=arr[i].first*cnt;
		i+=cnt;
	}
	ans=(ans*_pow(k, n))%mod;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

FG.cpp: In function 'int main()':
FG.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<arr.size();i++){
               ^
FG.cpp:25:6: warning: unused variable 'idx' [-Wunused-variable]
  int idx=1;
      ^
FG.cpp:39:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
                   ^
FG.cpp:50:15: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for(int i=1;i<k;){
               ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 500 ms 788532 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 500 ms 788532 KB Execution timed out
2 Halted 0 ms 0 KB -