This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
vector<pair<long long, long long> > x;
unsigned long long res = 1;
priority_queue<long long > q;
vector<vector<long long> > v;
vector<long long> t;
int main() {
int n, s; long long res = 0;
long long m;
unsigned long long temp;
pair<long long, long long> p;
scanf("%d %d", &s, &n);
t.push_back(1);
v.push_back(t);
t.pop_back();
p.first = s;
p.second = 1;
x.push_back(p);
for (int i = 2; i <= n; i++) {
t = v.back(); v.pop_back();
for (int j = 1; j < i; j++) {
q.push(t[j - 1]);
if (j == 1 && i % 2 == 0)
continue;
t[j - 1]++;
}
if (i == 2) t.push_back(i);
else t.push_back(i - 1);
v.push_back(t);
}
long long re = (q.empty())? s : q.top(); int y = 2;
while(re--) {
p.first = (p.first % 1000000007) * (s % 1000000007) % 1000000007;
p.second = y++;
x.push_back(p);
} long long a = 0; t = v[0]; int d = 0;
while (d < v[0].size()) {
a += (x[t[d]-1].first);
d++;
}printf("%lld", a);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |