답안 #539389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539389 2022-03-18T19:49:29 Z singlabharat Cryptography (NOI20_crypto) C++17
100 / 100
481 ms 29132 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using si = set<int>;
using mii = map<int, int>;
template<typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(x) (int)size(x)
#define pb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define fr first
#define sc second
#define f(i, end) for (int i = 0; i < end; i++)
#define ff(i, start, end) for (int i = start; i < end; i++)
template<typename T, typename U> inline void domin(T &x, U y) {if (y < x) x = y;}
template<typename T, typename U> inline void domax(T &x, U y) {if (y > x) x = y;}
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &a) { os << '{'; string sep; for (const T &x : a) os << sep << x, sep = ", "; return os << '}';}
void debug() {cerr << endl;}
template <typename Head, typename... Tail> void debug(Head h, Tail... t) {cerr << h << ' '; debug(t...);}
#ifdef singlabharat
#define debug(...) cerr << "(" << #__VA_ARGS__ << ") : ", debug(__VA_ARGS__)
#else
#define debug(...)
#endif
#define endl '\n'
const int MX = 3e5 + 2, INF = 1e18, MOD = 1e9 + 7;

void solve() {

	vi fact(MX);
	fact[0] = 1;
	ff(i, 1, MX) fact[i] = (fact[i - 1] * i) % MOD;

	int n;
	cin >> n;
	vi a(n);
	f(i, n) cin >> a[i];

	pbds<int> os;
	vi dp(n + 1); //dp[i] -> #permutations of a[i..] <= a[i..]
	dp[n] = 1;
	for (int i = n - 1; i >= 0; i--) {
		dp[i] = os.order_of_key(a[i]) * fact[n - i - 1] + dp[i + 1];
		dp[i] %= MOD;
		os.insert(a[i]);
	}
	
	cout << dp[0];
}

int32_t main() {

#ifdef singlabharat
	freopen("error.txt", "w", stderr);
#endif

	cin.tie(0)->sync_with_stdio(0);

	int t = 1;
	// cin >> t;

	for (int tc = 0; tc < t; tc++) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2684 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
21 Correct 4 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 4 ms 2644 KB Output is correct
24 Correct 4 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 286 ms 29052 KB Output is correct
3 Correct 280 ms 29012 KB Output is correct
4 Correct 317 ms 29040 KB Output is correct
5 Correct 283 ms 29056 KB Output is correct
6 Correct 254 ms 28936 KB Output is correct
7 Correct 249 ms 28988 KB Output is correct
8 Correct 239 ms 29072 KB Output is correct
9 Correct 249 ms 28964 KB Output is correct
10 Correct 241 ms 28948 KB Output is correct
11 Correct 271 ms 29064 KB Output is correct
12 Correct 345 ms 28972 KB Output is correct
13 Correct 338 ms 28936 KB Output is correct
14 Correct 481 ms 28940 KB Output is correct
15 Correct 301 ms 28980 KB Output is correct
16 Correct 312 ms 28928 KB Output is correct
17 Correct 289 ms 29132 KB Output is correct
18 Correct 327 ms 29120 KB Output is correct
19 Correct 328 ms 29032 KB Output is correct
20 Correct 400 ms 28960 KB Output is correct
21 Correct 357 ms 28972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 294 ms 28056 KB Output is correct
3 Correct 326 ms 28244 KB Output is correct
4 Correct 260 ms 28120 KB Output is correct
5 Correct 238 ms 28092 KB Output is correct
6 Correct 316 ms 28044 KB Output is correct
7 Correct 290 ms 28064 KB Output is correct
8 Correct 231 ms 28184 KB Output is correct
9 Correct 256 ms 28064 KB Output is correct
10 Correct 315 ms 28084 KB Output is correct
11 Correct 281 ms 28128 KB Output is correct
12 Correct 283 ms 27984 KB Output is correct
13 Correct 237 ms 28016 KB Output is correct
14 Correct 293 ms 28064 KB Output is correct
15 Correct 379 ms 28016 KB Output is correct
16 Correct 315 ms 28048 KB Output is correct
17 Correct 284 ms 28080 KB Output is correct
18 Correct 297 ms 28012 KB Output is correct
19 Correct 293 ms 28092 KB Output is correct
20 Correct 291 ms 28056 KB Output is correct
21 Correct 322 ms 28040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 5 ms 2820 KB Output is correct
3 Correct 5 ms 2900 KB Output is correct
4 Correct 5 ms 2900 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 5 ms 2900 KB Output is correct
7 Correct 4 ms 2900 KB Output is correct
8 Correct 5 ms 2900 KB Output is correct
9 Correct 4 ms 2900 KB Output is correct
10 Correct 4 ms 2820 KB Output is correct
11 Correct 5 ms 2900 KB Output is correct
12 Correct 5 ms 2900 KB Output is correct
13 Correct 5 ms 2828 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 5 ms 2936 KB Output is correct
17 Correct 5 ms 2900 KB Output is correct
18 Correct 4 ms 2824 KB Output is correct
19 Correct 4 ms 2824 KB Output is correct
20 Correct 5 ms 2900 KB Output is correct
21 Correct 4 ms 2900 KB Output is correct
22 Correct 5 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2684 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
21 Correct 4 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 4 ms 2644 KB Output is correct
24 Correct 4 ms 2644 KB Output is correct
25 Correct 4 ms 2644 KB Output is correct
26 Correct 5 ms 2820 KB Output is correct
27 Correct 5 ms 2900 KB Output is correct
28 Correct 5 ms 2900 KB Output is correct
29 Correct 5 ms 2808 KB Output is correct
30 Correct 5 ms 2900 KB Output is correct
31 Correct 4 ms 2900 KB Output is correct
32 Correct 5 ms 2900 KB Output is correct
33 Correct 4 ms 2900 KB Output is correct
34 Correct 4 ms 2820 KB Output is correct
35 Correct 5 ms 2900 KB Output is correct
36 Correct 5 ms 2900 KB Output is correct
37 Correct 5 ms 2828 KB Output is correct
38 Correct 5 ms 2900 KB Output is correct
39 Correct 4 ms 2644 KB Output is correct
40 Correct 5 ms 2936 KB Output is correct
41 Correct 5 ms 2900 KB Output is correct
42 Correct 4 ms 2824 KB Output is correct
43 Correct 4 ms 2824 KB Output is correct
44 Correct 5 ms 2900 KB Output is correct
45 Correct 4 ms 2900 KB Output is correct
46 Correct 5 ms 2816 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 5 ms 2824 KB Output is correct
49 Correct 5 ms 2900 KB Output is correct
50 Correct 5 ms 2824 KB Output is correct
51 Correct 6 ms 2988 KB Output is correct
52 Correct 6 ms 2920 KB Output is correct
53 Correct 5 ms 2900 KB Output is correct
54 Correct 5 ms 2900 KB Output is correct
55 Correct 4 ms 2820 KB Output is correct
56 Correct 5 ms 2912 KB Output is correct
57 Correct 6 ms 2900 KB Output is correct
58 Correct 5 ms 2944 KB Output is correct
59 Correct 5 ms 2868 KB Output is correct
60 Correct 5 ms 2952 KB Output is correct
61 Correct 4 ms 2644 KB Output is correct
62 Correct 5 ms 2828 KB Output is correct
63 Correct 5 ms 2872 KB Output is correct
64 Correct 5 ms 2828 KB Output is correct
65 Correct 4 ms 2824 KB Output is correct
66 Correct 5 ms 2900 KB Output is correct
67 Correct 5 ms 2900 KB Output is correct
68 Correct 4 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 294 ms 28056 KB Output is correct
3 Correct 326 ms 28244 KB Output is correct
4 Correct 260 ms 28120 KB Output is correct
5 Correct 238 ms 28092 KB Output is correct
6 Correct 316 ms 28044 KB Output is correct
7 Correct 290 ms 28064 KB Output is correct
8 Correct 231 ms 28184 KB Output is correct
9 Correct 256 ms 28064 KB Output is correct
10 Correct 315 ms 28084 KB Output is correct
11 Correct 281 ms 28128 KB Output is correct
12 Correct 283 ms 27984 KB Output is correct
13 Correct 237 ms 28016 KB Output is correct
14 Correct 293 ms 28064 KB Output is correct
15 Correct 379 ms 28016 KB Output is correct
16 Correct 315 ms 28048 KB Output is correct
17 Correct 284 ms 28080 KB Output is correct
18 Correct 297 ms 28012 KB Output is correct
19 Correct 293 ms 28092 KB Output is correct
20 Correct 291 ms 28056 KB Output is correct
21 Correct 322 ms 28040 KB Output is correct
22 Correct 4 ms 2644 KB Output is correct
23 Correct 5 ms 2820 KB Output is correct
24 Correct 5 ms 2900 KB Output is correct
25 Correct 5 ms 2900 KB Output is correct
26 Correct 5 ms 2808 KB Output is correct
27 Correct 5 ms 2900 KB Output is correct
28 Correct 4 ms 2900 KB Output is correct
29 Correct 5 ms 2900 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 2820 KB Output is correct
32 Correct 5 ms 2900 KB Output is correct
33 Correct 5 ms 2900 KB Output is correct
34 Correct 5 ms 2828 KB Output is correct
35 Correct 5 ms 2900 KB Output is correct
36 Correct 4 ms 2644 KB Output is correct
37 Correct 5 ms 2936 KB Output is correct
38 Correct 5 ms 2900 KB Output is correct
39 Correct 4 ms 2824 KB Output is correct
40 Correct 4 ms 2824 KB Output is correct
41 Correct 5 ms 2900 KB Output is correct
42 Correct 4 ms 2900 KB Output is correct
43 Correct 5 ms 2816 KB Output is correct
44 Correct 4 ms 2644 KB Output is correct
45 Correct 267 ms 28056 KB Output is correct
46 Correct 247 ms 28044 KB Output is correct
47 Correct 251 ms 28128 KB Output is correct
48 Correct 243 ms 28084 KB Output is correct
49 Correct 262 ms 28088 KB Output is correct
50 Correct 293 ms 28056 KB Output is correct
51 Correct 248 ms 28076 KB Output is correct
52 Correct 260 ms 28084 KB Output is correct
53 Correct 246 ms 28072 KB Output is correct
54 Correct 242 ms 27976 KB Output is correct
55 Correct 248 ms 28048 KB Output is correct
56 Correct 247 ms 28096 KB Output is correct
57 Correct 250 ms 27980 KB Output is correct
58 Correct 3 ms 2644 KB Output is correct
59 Correct 299 ms 28076 KB Output is correct
60 Correct 247 ms 28000 KB Output is correct
61 Correct 242 ms 28092 KB Output is correct
62 Correct 246 ms 27980 KB Output is correct
63 Correct 248 ms 28008 KB Output is correct
64 Correct 252 ms 28044 KB Output is correct
65 Correct 242 ms 27980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 4 ms 2684 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 4 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
21 Correct 4 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 4 ms 2644 KB Output is correct
24 Correct 4 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 286 ms 29052 KB Output is correct
27 Correct 280 ms 29012 KB Output is correct
28 Correct 317 ms 29040 KB Output is correct
29 Correct 283 ms 29056 KB Output is correct
30 Correct 254 ms 28936 KB Output is correct
31 Correct 249 ms 28988 KB Output is correct
32 Correct 239 ms 29072 KB Output is correct
33 Correct 249 ms 28964 KB Output is correct
34 Correct 241 ms 28948 KB Output is correct
35 Correct 271 ms 29064 KB Output is correct
36 Correct 345 ms 28972 KB Output is correct
37 Correct 338 ms 28936 KB Output is correct
38 Correct 481 ms 28940 KB Output is correct
39 Correct 301 ms 28980 KB Output is correct
40 Correct 312 ms 28928 KB Output is correct
41 Correct 289 ms 29132 KB Output is correct
42 Correct 327 ms 29120 KB Output is correct
43 Correct 328 ms 29032 KB Output is correct
44 Correct 400 ms 28960 KB Output is correct
45 Correct 357 ms 28972 KB Output is correct
46 Correct 4 ms 2644 KB Output is correct
47 Correct 294 ms 28056 KB Output is correct
48 Correct 326 ms 28244 KB Output is correct
49 Correct 260 ms 28120 KB Output is correct
50 Correct 238 ms 28092 KB Output is correct
51 Correct 316 ms 28044 KB Output is correct
52 Correct 290 ms 28064 KB Output is correct
53 Correct 231 ms 28184 KB Output is correct
54 Correct 256 ms 28064 KB Output is correct
55 Correct 315 ms 28084 KB Output is correct
56 Correct 281 ms 28128 KB Output is correct
57 Correct 283 ms 27984 KB Output is correct
58 Correct 237 ms 28016 KB Output is correct
59 Correct 293 ms 28064 KB Output is correct
60 Correct 379 ms 28016 KB Output is correct
61 Correct 315 ms 28048 KB Output is correct
62 Correct 284 ms 28080 KB Output is correct
63 Correct 297 ms 28012 KB Output is correct
64 Correct 293 ms 28092 KB Output is correct
65 Correct 291 ms 28056 KB Output is correct
66 Correct 322 ms 28040 KB Output is correct
67 Correct 4 ms 2644 KB Output is correct
68 Correct 5 ms 2820 KB Output is correct
69 Correct 5 ms 2900 KB Output is correct
70 Correct 5 ms 2900 KB Output is correct
71 Correct 5 ms 2808 KB Output is correct
72 Correct 5 ms 2900 KB Output is correct
73 Correct 4 ms 2900 KB Output is correct
74 Correct 5 ms 2900 KB Output is correct
75 Correct 4 ms 2900 KB Output is correct
76 Correct 4 ms 2820 KB Output is correct
77 Correct 5 ms 2900 KB Output is correct
78 Correct 5 ms 2900 KB Output is correct
79 Correct 5 ms 2828 KB Output is correct
80 Correct 5 ms 2900 KB Output is correct
81 Correct 4 ms 2644 KB Output is correct
82 Correct 5 ms 2936 KB Output is correct
83 Correct 5 ms 2900 KB Output is correct
84 Correct 4 ms 2824 KB Output is correct
85 Correct 4 ms 2824 KB Output is correct
86 Correct 5 ms 2900 KB Output is correct
87 Correct 4 ms 2900 KB Output is correct
88 Correct 5 ms 2816 KB Output is correct
89 Correct 3 ms 2644 KB Output is correct
90 Correct 5 ms 2824 KB Output is correct
91 Correct 5 ms 2900 KB Output is correct
92 Correct 5 ms 2824 KB Output is correct
93 Correct 6 ms 2988 KB Output is correct
94 Correct 6 ms 2920 KB Output is correct
95 Correct 5 ms 2900 KB Output is correct
96 Correct 5 ms 2900 KB Output is correct
97 Correct 4 ms 2820 KB Output is correct
98 Correct 5 ms 2912 KB Output is correct
99 Correct 6 ms 2900 KB Output is correct
100 Correct 5 ms 2944 KB Output is correct
101 Correct 5 ms 2868 KB Output is correct
102 Correct 5 ms 2952 KB Output is correct
103 Correct 4 ms 2644 KB Output is correct
104 Correct 5 ms 2828 KB Output is correct
105 Correct 5 ms 2872 KB Output is correct
106 Correct 5 ms 2828 KB Output is correct
107 Correct 4 ms 2824 KB Output is correct
108 Correct 5 ms 2900 KB Output is correct
109 Correct 5 ms 2900 KB Output is correct
110 Correct 4 ms 2900 KB Output is correct
111 Correct 4 ms 2644 KB Output is correct
112 Correct 267 ms 28056 KB Output is correct
113 Correct 247 ms 28044 KB Output is correct
114 Correct 251 ms 28128 KB Output is correct
115 Correct 243 ms 28084 KB Output is correct
116 Correct 262 ms 28088 KB Output is correct
117 Correct 293 ms 28056 KB Output is correct
118 Correct 248 ms 28076 KB Output is correct
119 Correct 260 ms 28084 KB Output is correct
120 Correct 246 ms 28072 KB Output is correct
121 Correct 242 ms 27976 KB Output is correct
122 Correct 248 ms 28048 KB Output is correct
123 Correct 247 ms 28096 KB Output is correct
124 Correct 250 ms 27980 KB Output is correct
125 Correct 3 ms 2644 KB Output is correct
126 Correct 299 ms 28076 KB Output is correct
127 Correct 247 ms 28000 KB Output is correct
128 Correct 242 ms 28092 KB Output is correct
129 Correct 246 ms 27980 KB Output is correct
130 Correct 248 ms 28008 KB Output is correct
131 Correct 252 ms 28044 KB Output is correct
132 Correct 242 ms 27980 KB Output is correct
133 Correct 3 ms 2644 KB Output is correct
134 Correct 257 ms 29048 KB Output is correct
135 Correct 252 ms 28932 KB Output is correct
136 Correct 290 ms 28936 KB Output is correct
137 Correct 252 ms 29040 KB Output is correct
138 Correct 272 ms 29092 KB Output is correct
139 Correct 250 ms 28988 KB Output is correct
140 Correct 237 ms 28928 KB Output is correct
141 Correct 236 ms 29020 KB Output is correct
142 Correct 248 ms 29100 KB Output is correct
143 Correct 282 ms 28984 KB Output is correct
144 Correct 253 ms 28940 KB Output is correct
145 Correct 247 ms 29092 KB Output is correct
146 Correct 258 ms 29064 KB Output is correct
147 Correct 3 ms 2576 KB Output is correct
148 Correct 252 ms 29016 KB Output is correct
149 Correct 253 ms 29008 KB Output is correct
150 Correct 251 ms 29068 KB Output is correct
151 Correct 254 ms 28968 KB Output is correct
152 Correct 305 ms 29056 KB Output is correct
153 Correct 267 ms 28952 KB Output is correct
154 Correct 251 ms 28940 KB Output is correct