# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
501874 |
2022-01-04T17:49:47 Z |
600Mihnea |
Fish (IOI08_fish) |
C++17 |
|
3000 ms |
41156 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Fish {
int sz;
int tp;
};
bool operator < (Fish a, Fish b) {
return a.sz < b.sz;
}
const int N = (int) 5e5 + 7;
int n, k, mod;
Fish a[N];
vector<int> aux[N], oftp[N];
int caneat(int f, int s) {
int low = 0, high = (int) oftp[s].size() - 1, sol = 0;
while (low <= high) {
int mid = (low + high) / 2;
if (a[oftp[f].back()].sz >= 2 * a[oftp[s][mid]].sz) {
sol = mid + 1;
low = mid + 1;
} else {
high = mid - 1;
}
}
return sol;
}
int aux_order[N];
bool cmp(int i, int j) {
return aux[i].back() < aux[j].back();
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> mod;
for (int i = 1; i <= n; i++) {
cin >> a[i].sz >> a[i].tp;
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
aux[a[i].tp].push_back(i);
}
n = k;
for (int i = 1; i <= n; i++) {
aux_order[i] = i;
}
sort(aux_order + 1, aux_order + n + 1, cmp);
for (int i = 1; i <= n; i++) oftp[i] = aux[aux_order[i]];
for (int i = 1; i <= n; i++) aux[i] = oftp[i];
/**
0 0 0
1 0 1
1 1 1
type 1 can eat :
type 2 can eat : 1 3
type 3 can eat : 1 2 3
**/
int print = 0;
for (int i = n; i >= 1; i--) {
/**
count all new representations that can be eaten by the fish i
aka all representations that can be eaten by fish i and not by a fish bigger than him
let's look at what restrictions the other fish impose on fish j
only the bigger fish than him impose restrictions
**/
int full = 1, semi = caneat(i, i);
for (int j = i + 1; j <= n; j++) {
if (caneat(j, i) >= caneat(i, i) + 1) {
/// I can eat only 0 j
break;
}
/// I can eat 0 j (available always)
/// I can eat any amount of fish j if I ...
full = full * (ll) (caneat(i, j) + 1) % mod;
/// assert(caneat(j, i) == caneat(i, i));
}
int sol = 1;
for (int j = 1; j < i; j++) {
sol = sol * (ll) (caneat(i, j) + 1) % mod;
}
full = full * (ll) sol % mod;
semi = semi * (ll) sol % mod;
print = (print + full) % mod;
print = (print + semi) % mod;
}
cout << print << "\n";
return 0;
}
/**
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23720 KB |
Output is correct |
2 |
Correct |
129 ms |
31996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
27408 KB |
Output is correct |
2 |
Correct |
82 ms |
28408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
23884 KB |
Output is correct |
2 |
Correct |
33 ms |
23952 KB |
Output is correct |
3 |
Correct |
39 ms |
23980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
29484 KB |
Output is correct |
2 |
Correct |
413 ms |
32592 KB |
Output is correct |
3 |
Correct |
405 ms |
33412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
230 ms |
32656 KB |
Output is correct |
2 |
Correct |
484 ms |
32920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
29460 KB |
Output is correct |
2 |
Correct |
2453 ms |
33028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3086 ms |
32320 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3088 ms |
33376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3092 ms |
32152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3084 ms |
37700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3074 ms |
40560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
41156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |