Skip to content

Instantly share code, notes, and snippets.

@na-o-ys
Last active August 29, 2015 14:19
Show Gist options
  • Save na-o-ys/e9a1e04718c57d788605 to your computer and use it in GitHub Desktop.
Save na-o-ys/e9a1e04718c57d788605 to your computer and use it in GitHub Desktop.
TCO 2015 Round 1A Med
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
class Autogame
{
public:
int wayscnt(vector <int> a, int K) {
int N = a.size();
K = min(N, K);
vector<int> cnt(N);
loop (N, i) {
int p = i+1;
loop (K, j) p = a[p-1];
cnt[p-1]++;
}
ll ans = 1;
for (int v : cnt) {
ans *= v + 1;
ans %= MOD;
}
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment