#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll d = 1e9 + 7;
map <ll,ll> mp;
ll ft(ll a, ll b) {
ll ans = 1;
for(ll i = a; i <= b; i++) {
ans *= i;
ans %= d;
}
return ans;
}
int main() {
ll n;
cin >> n;
vector <ll> v(n), v1;
for(ll i = 0; i < n; i++) {
cin >> v[i];
mp[v[i]]++;
}
v1 = v;
ll ans = 1;
sort(v1.begin(), v1.end());
if(v == v1) {
cout << 1;
return 0;
}
reverse(v1.begin(), v1.end());
if(v1 == v) {
cout << n;
return 0;
}
else reverse(v1.begin(), v1.end());
for(ll i = 0; i < v.size(); i++) {
for(ll j = 0; j < v1.size(); j++) {
if(v[i] == v1[j]) {
n--;
if(mp[v[i]] != 1) {
ll laa = (ft(2, n) / ft(2, mp[v[i]]));
if(laa != 1) ans += laa;
mp[v[i]]--;
ans %= d;
auto it = v1.begin() + j;
auto it1 = v.begin() + i;
v1.erase(it);
v.erase(it1);
i--;
j--;
break;
}
ans += ft(2, n) * j;
ans %= d;
auto it = v1.begin() + j;
auto it1 = v.begin() + i;
v1.erase(it);
v.erase(it1);
i--;
j--;
break;
}
}
}
cout << ans;
}
Compilation message
Crypto.cpp: In function 'int main()':
Crypto.cpp:35:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(ll i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
Crypto.cpp:36:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(ll j = 0; j < v1.size(); j++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
193 ms |
24268 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
24040 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
28 ms |
468 KB |
Output is correct |
3 |
Correct |
27 ms |
528 KB |
Output is correct |
4 |
Correct |
27 ms |
468 KB |
Output is correct |
5 |
Correct |
28 ms |
544 KB |
Output is correct |
6 |
Correct |
29 ms |
468 KB |
Output is correct |
7 |
Correct |
28 ms |
540 KB |
Output is correct |
8 |
Correct |
30 ms |
468 KB |
Output is correct |
9 |
Correct |
29 ms |
552 KB |
Output is correct |
10 |
Correct |
27 ms |
440 KB |
Output is correct |
11 |
Correct |
26 ms |
564 KB |
Output is correct |
12 |
Correct |
27 ms |
468 KB |
Output is correct |
13 |
Correct |
27 ms |
528 KB |
Output is correct |
14 |
Correct |
26 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
29 ms |
556 KB |
Output is correct |
17 |
Correct |
28 ms |
468 KB |
Output is correct |
18 |
Correct |
27 ms |
468 KB |
Output is correct |
19 |
Correct |
29 ms |
468 KB |
Output is correct |
20 |
Correct |
28 ms |
468 KB |
Output is correct |
21 |
Correct |
27 ms |
440 KB |
Output is correct |
22 |
Correct |
27 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
24040 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |