이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
using namespace std;
int n;
int arr[10000000] = { 0 };
pair<int, int> c;
long long mod = 1000000007;
long long ans=1;
long long cal(int num, int a)
{
if (a == 1) return num;
else if (a == 2)
return num*num%mod;
int temp = cal(num, a / 2) % mod;
if ((a % 2) == 0) return temp*temp%mod;
return cal(num,a-1)*num%mod;
}
void go(int num, int sum)
{
if(arr[num]==0)
arr[num] = c.first;
int tsum = sum + arr[num];
if (tsum >= n)
{
ans*=cal(num, n - sum);
ans %= mod;
return;
}
//pop
c.second--;
ans *= cal(num, c.first);
ans %= mod;
arr[num] = c.first;
//push
if (c.second == 0)
{
c.first++;
c.second = arr[c.first];
}
go(num + 1, tsum);
}
int main()
{
cin >> n;
arr[1] = 1;
arr[2] = 2;
c.first = 1;
c.second = 1;
go(1, 0);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |