# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
625561 |
2022-08-10T14:55:27 Z |
clams |
Catfish Farm (IOI22_fish) |
C++17 |
|
84 ms |
7284 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
bool issub1 = 1;
for (int i = 0; i < m; i++) {
if (x[i] & 1) {
issub1 = 0;
break;
}
}
if (issub1) {
// just sum up every thing
ll ans = accumulate(w.begin(), w.end(), 0LL);
return ans;
}
bool issub2 = 1;
for (int i = 0; i < m; i++) {
if (x[i] > 1) {
issub2 = 0;
break;
}
}
if (issub2) {
// there is only two columns, BUT be careful since n can be > 2
if (n == 1) {
// you can't choose anything
return 0;
}
if (n == 2) {
// only two columns
vector<ll> col(2);
for (int i = 0; i < m; i++) {
col[x[i]] += w[i];
}
return max(col[0], col[1]);
}
// prefix of col[0] and suffix of col[1]
// 2 pointer
vector<vector<pair<int, int>>> v(2);
for (int i = 0; i < m; i++) {
v[x[i]].push_back({y[i], w[i]});
}
for (int j = 0; j < 2; j++) {
sort(v[j].begin(), v[j].end());
}
ll all2 = 0;
for (auto i : v[1]) all2 += i.second;
ll ans = all2;
int j = 0;
ll cur1 = 0;
while (j < v[0].size() && v[0][j].first <= v[1][0].first) {
cur1 += v[0][j].second;
j++;
}
ans = max(ans, cur1 + all2);
for (int i = 0; i < v[1].size(); i++) {
all2 -= v[1][i].second;
while (j < v[0].size() && v[0][j].first <= v[1][i].first) {
cur1 += v[0][j].second;
j++;
}
ans = max(ans, all2 + cur1);
}
return ans;
}
return 0;
}
//int main() {
// int tmp = 2e9;
//// cout << max_weights(5, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
//// cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
// cout << max_weights(2, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
// cout << max_weights(1, 4, {0, 0, 0, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
// cout << max_weights(3, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {0, 0, tmp, tmp}) << '\n';
// cout << max_weights(3, 2, {0, 1}, {1, 2}, {1, 1}) << '\n';
//}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | while (j < v[0].size() && v[0][j].first <= v[1][0].first) {
| ~~^~~~~~~~~~~~~
fish.cpp:69:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = 0; i < v[1].size(); i++) {
| ~~^~~~~~~~~~~~~
fish.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while (j < v[0].size() && v[0][j].first <= v[1][i].first) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
26 ms |
2624 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
84 ms |
7268 KB |
Output is correct |
6 |
Correct |
84 ms |
7284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
60 ms |
5696 KB |
Output is correct |
3 |
Correct |
72 ms |
6740 KB |
Output is correct |
4 |
Correct |
21 ms |
2152 KB |
Output is correct |
5 |
Correct |
25 ms |
2616 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
40 ms |
3300 KB |
Output is correct |
13 |
Correct |
35 ms |
3788 KB |
Output is correct |
14 |
Correct |
31 ms |
3048 KB |
Output is correct |
15 |
Correct |
32 ms |
3408 KB |
Output is correct |
16 |
Correct |
28 ms |
3152 KB |
Output is correct |
17 |
Incorrect |
31 ms |
3272 KB |
1st lines differ - on the 1st token, expected: '45076987066882', found: '45077310326876' |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
26 ms |
2624 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
84 ms |
7268 KB |
Output is correct |
6 |
Correct |
84 ms |
7284 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
60 ms |
5696 KB |
Output is correct |
9 |
Correct |
72 ms |
6740 KB |
Output is correct |
10 |
Correct |
21 ms |
2152 KB |
Output is correct |
11 |
Correct |
25 ms |
2616 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
40 ms |
3300 KB |
Output is correct |
19 |
Correct |
35 ms |
3788 KB |
Output is correct |
20 |
Correct |
31 ms |
3048 KB |
Output is correct |
21 |
Correct |
32 ms |
3408 KB |
Output is correct |
22 |
Correct |
28 ms |
3152 KB |
Output is correct |
23 |
Incorrect |
31 ms |
3272 KB |
1st lines differ - on the 1st token, expected: '45076987066882', found: '45077310326876' |
24 |
Halted |
0 ms |
0 KB |
- |