Submission #830155

# Submission time Handle Problem Language Result Execution time Memory
830155 2023-08-18T20:26:28 Z NK_ Cryptography (NOI20_crypto) C++17
25 / 100
352 ms 20712 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;
 
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;

const int MOD = 1e9 + 7;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	

	int N; cin >> N;
	vi fact = {1}; for(int i = 1; i < N; i++) fact.pb((fact.back() * 1LL * i) % MOD);

	vi A(N); for(auto& x : A) cin >> x;

	vi X = A; sort(begin(X), end(X));
	for(auto& x : A) x = lower_bound(begin(X), end(X), x) - begin(X);

	iset<int> have; for(int i = 0; i < N; i++) have.insert(i);

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		int l = have.order_of_key(A[i]);
		// cout << l << endl;

		ans += (l * 1LL * fact[N - 1 - i]) % MOD;

		have.erase(A[i]);
	}

	cout << ans + 1 << nl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 334 ms 20712 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 314 ms 19876 KB Output is correct
3 Correct 324 ms 19812 KB Output is correct
4 Correct 310 ms 19764 KB Output is correct
5 Correct 320 ms 19812 KB Output is correct
6 Correct 320 ms 19820 KB Output is correct
7 Correct 311 ms 19876 KB Output is correct
8 Correct 316 ms 19844 KB Output is correct
9 Correct 333 ms 19860 KB Output is correct
10 Correct 319 ms 19884 KB Output is correct
11 Correct 321 ms 19860 KB Output is correct
12 Correct 324 ms 19816 KB Output is correct
13 Correct 352 ms 19968 KB Output is correct
14 Correct 322 ms 19764 KB Output is correct
15 Correct 317 ms 19872 KB Output is correct
16 Correct 317 ms 19844 KB Output is correct
17 Correct 330 ms 19844 KB Output is correct
18 Correct 312 ms 19940 KB Output is correct
19 Correct 323 ms 19804 KB Output is correct
20 Correct 313 ms 19904 KB Output is correct
21 Correct 341 ms 19768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 468 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Incorrect 2 ms 468 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 314 ms 19876 KB Output is correct
3 Correct 324 ms 19812 KB Output is correct
4 Correct 310 ms 19764 KB Output is correct
5 Correct 320 ms 19812 KB Output is correct
6 Correct 320 ms 19820 KB Output is correct
7 Correct 311 ms 19876 KB Output is correct
8 Correct 316 ms 19844 KB Output is correct
9 Correct 333 ms 19860 KB Output is correct
10 Correct 319 ms 19884 KB Output is correct
11 Correct 321 ms 19860 KB Output is correct
12 Correct 324 ms 19816 KB Output is correct
13 Correct 352 ms 19968 KB Output is correct
14 Correct 322 ms 19764 KB Output is correct
15 Correct 317 ms 19872 KB Output is correct
16 Correct 317 ms 19844 KB Output is correct
17 Correct 330 ms 19844 KB Output is correct
18 Correct 312 ms 19940 KB Output is correct
19 Correct 323 ms 19804 KB Output is correct
20 Correct 313 ms 19904 KB Output is correct
21 Correct 341 ms 19768 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 2 ms 468 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Incorrect 334 ms 20712 KB Output isn't correct
27 Halted 0 ms 0 KB -