# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636684 | 2022-08-29T22:51:25 Z | abeker | Žarulje (COI15_zarulje) | C++17 | 1000 ms | 3900 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; int N, K; int a[MAXN]; int fact[MAXN], inv[MAXN]; void load() { scanf("%d%d", &N, &K); for (int i = 1; i <= N; i++) scanf("%d", a + i); } inline int mul(int x, int y) { return (long long)x * y % MOD; } int pot(int x, int y) { int res = 1; for (; y; y /= 2) { if (y % 2) res = mul(res, x); x = mul(x, x); } return res; } void solve() { fact[0] = inv[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = mul(fact[i - 1], i); inv[i] = pot(fact[i], MOD - 2); } while (K--) { int p; scanf("%d", &p); int ans = 1; int l = p - 1, r = p + 1; while (l >= 1 || r <= N) { int nxt_l = l, nxt_r = r; bool larger_left = a[l] >= a[r]; bool larger_right = a[r] >= a[l]; int equal_left = 0, equal_right = 0; if (larger_left) for (; a[nxt_l] >= a[l]; nxt_l--) equal_left += a[nxt_l] == a[l]; if (larger_right) for (; a[nxt_r] >= a[r]; nxt_r++) equal_right += a[nxt_r] == a[r]; if (larger_left && larger_right) ans = mul(ans, mul(fact[equal_left + equal_right], mul(inv[equal_left], inv[equal_right]))); l = nxt_l; r = nxt_r; } printf("%d ", ans); } puts(""); } int main() { load(); solve(); return 0; }
Compilation message
# | 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 | 4 ms | 340 KB | Output is correct |
4 | Correct | 4 ms | 320 KB | Output is correct |
5 | Correct | 3 ms | 316 KB | Output is correct |
6 | Correct | 4 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 1748 KB | Output is correct |
2 | Correct | 45 ms | 2976 KB | Output is correct |
3 | Correct | 45 ms | 3168 KB | Output is correct |
4 | Correct | 47 ms | 3276 KB | Output is correct |
5 | Correct | 47 ms | 3484 KB | Output is correct |
6 | Correct | 48 ms | 3728 KB | Output is correct |
7 | Correct | 50 ms | 3900 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 | 4 ms | 340 KB | Output is correct |
4 | Correct | 4 ms | 320 KB | Output is correct |
5 | Correct | 3 ms | 316 KB | Output is correct |
6 | Correct | 4 ms | 340 KB | Output is correct |
7 | Correct | 24 ms | 1748 KB | Output is correct |
8 | Correct | 45 ms | 2976 KB | Output is correct |
9 | Correct | 45 ms | 3168 KB | Output is correct |
10 | Correct | 47 ms | 3276 KB | Output is correct |
11 | Correct | 47 ms | 3484 KB | Output is correct |
12 | Correct | 48 ms | 3728 KB | Output is correct |
13 | Correct | 50 ms | 3900 KB | Output is correct |
14 | Correct | 73 ms | 584 KB | Output is correct |
15 | Execution timed out | 1079 ms | 2444 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |