# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121742 | rahidilbayramli | Calvinball championship (CEOI15_teams) | C++17 | 67 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define sz(v) (ll)(v.size())
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
const ll mod = 1e6+7;
void solve()
{
ll n, i, j, k, l, r, f, p;
cin >> n;
ll a[n+5], cnt = 0;
for(i = 1; i <= n; i++){
cin >> a[i];
if(a[i] == i)
cnt++;
}
vector<vl>vect;
vl v;
for(i = 1; i <= n; i++)
v.pb(1);
ll pos = n - 1, pos2 = n - 1;
vect.pb(v);
while(true)
{
while(pos2 && v[pos2]-v[pos2-1] == 1)
{
pos2--;
}
v[pos2]++;
k = v[pos2];
for(j = pos2+1; j < n; j++)
{
k--;
v[j] = max(1LL, k);
}
pos2 = n - 1;
if(v[0] > 1)
break;
vect.pb(v);
}
bool ok = true;
cnt = 0;
for(auto u : vect)
{
cnt++;
ok = true;
for(j = 0; j < n; j++)
{
if(u[j] == a[j+1])
continue;
ok = false;
}
if(ok)
{
cout << cnt % mod << "\n";
return;
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |