# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873620 |
2023-11-15T11:42:28 Z |
Nonoze |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
208168 KB |
#include "fish.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define int long long
unordered_map<int, unordered_map<int, unordered_map<int,int>>> memo;
vector<vector<pair<int, int>>> values;
int n;
int mini=0;
int dp(int empl, int take, int pretake) {
if (empl>=n) return 0;
if (memo[empl][take].count(pretake)) return memo[empl][take][pretake];
int ans=dp(empl+1, 0, take);
int sum=0;
int empl1=0, empl2=0, empl3=0;
int sz1=(empl?values[empl-1].size():0), sz2=values[empl].size(), sz3=(empl+1<n?values[empl+1].size():0);
while (empl1<sz1 || empl2<sz2 || empl3<sz3) {
int i=LLONG_MAX, indice=1;
if (empl2<sz2 && values[empl][empl2].first<i) {
i=values[empl][empl2].first;
indice=2;
}
if (empl1<sz1 && values[empl-1][empl1].first<i) {
i=values[empl-1][empl1].first;
indice=1;
}
if (empl3<sz3 && values[empl+1][empl3].first<i) {
i=values[empl+1][empl3].first;
indice=3;
}
if (indice==1) {
if (pretake<i+1 && take<i+1) {
sum+=values[empl-1][empl1].second;
}
empl1++;
} else if (indice==2) {
if (take>=i+1) {
sum-=values[empl][empl2].second;
}
empl2++;
} else {
sum+=values[empl+1][empl3].second;
empl3++;
}
ans=max(ans, dp(empl+1, i+1, take)+sum);
}
return memo[empl][take][pretake]=ans;
}
#undef int
long long max_weights(int N, int m, vector<int> x, vector<int> y, vector<int> w) {
#define int long long
n=N;
bool tacha=true, tachb=true;
for (int i = 0; i < m; ++i)
{
if (x[i]%2) tacha=false;
if (x[i]>1) tachb=false;
}
if (tacha)
{
int ans=0;
for (int i = 0; i < m; ++i) ans+=w[i];
return ans;
}
if (tachb)
{
vector<vector<int>> farm(2, vector<int> (n, 0));
for (int i=0; i<m; i++) {
farm[x[i]][y[i]]=w[i];
}
vector<int> suml, sumr;
suml.push_back(farm[0][0]);
sumr.push_back(farm[1][0]);
for (int i=1; i<n; i++) {
suml.push_back(suml.back()+farm[0][i]);
sumr.push_back(sumr.back()+farm[1][i]);
}
if (n==2) return max(suml.back(), sumr.back());
int ans=sumr.back();
for (int i=0; i<n; i++) {
ans=max(ans, suml[i]+sumr.back()-sumr[i]);
}
return ans;
}
mini=0;
for (int i=0; i<m; i++) {
mini=max(mini, (long long) y[i]);
}
mini++;
values.resize(n);
for (int i=0; i<m; i++) {
values[x[i]].push_back({y[i], w[i]});
}
for (int i=0; i<n; i++) {
sort(values[i].begin(), values[i].end());
}
return dp(0, 0, 0);
#undef int
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2140 KB |
Output is correct |
2 |
Correct |
23 ms |
4420 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
73 ms |
13920 KB |
Output is correct |
6 |
Correct |
68 ms |
14060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
38 ms |
8036 KB |
Output is correct |
3 |
Correct |
46 ms |
13120 KB |
Output is correct |
4 |
Correct |
18 ms |
3688 KB |
Output is correct |
5 |
Correct |
22 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
20 ms |
7408 KB |
Output is correct |
13 |
Correct |
25 ms |
9024 KB |
Output is correct |
14 |
Correct |
20 ms |
7576 KB |
Output is correct |
15 |
Correct |
23 ms |
8644 KB |
Output is correct |
16 |
Correct |
20 ms |
7580 KB |
Output is correct |
17 |
Correct |
34 ms |
8640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
63 ms |
57228 KB |
Output is correct |
3 |
Correct |
133 ms |
71368 KB |
Output is correct |
4 |
Correct |
124 ms |
71624 KB |
Output is correct |
5 |
Correct |
207 ms |
90960 KB |
Output is correct |
6 |
Correct |
210 ms |
90948 KB |
Output is correct |
7 |
Correct |
199 ms |
90824 KB |
Output is correct |
8 |
Correct |
209 ms |
90820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
30 ms |
1768 KB |
Output is correct |
11 |
Correct |
10 ms |
988 KB |
Output is correct |
12 |
Correct |
15 ms |
1452 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
30 ms |
1768 KB |
Output is correct |
11 |
Correct |
10 ms |
988 KB |
Output is correct |
12 |
Correct |
15 ms |
1452 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Execution timed out |
1065 ms |
7740 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
30 ms |
1768 KB |
Output is correct |
11 |
Correct |
10 ms |
988 KB |
Output is correct |
12 |
Correct |
15 ms |
1452 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Execution timed out |
1065 ms |
7740 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
63 ms |
57228 KB |
Output is correct |
3 |
Correct |
133 ms |
71368 KB |
Output is correct |
4 |
Correct |
124 ms |
71624 KB |
Output is correct |
5 |
Correct |
207 ms |
90960 KB |
Output is correct |
6 |
Correct |
210 ms |
90948 KB |
Output is correct |
7 |
Correct |
199 ms |
90824 KB |
Output is correct |
8 |
Correct |
209 ms |
90820 KB |
Output is correct |
9 |
Correct |
575 ms |
165976 KB |
Output is correct |
10 |
Correct |
252 ms |
64868 KB |
Output is correct |
11 |
Correct |
480 ms |
129412 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
71 ms |
57236 KB |
Output is correct |
21 |
Correct |
69 ms |
57320 KB |
Output is correct |
22 |
Correct |
739 ms |
169580 KB |
Output is correct |
23 |
Execution timed out |
1074 ms |
208168 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2140 KB |
Output is correct |
2 |
Correct |
23 ms |
4420 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
73 ms |
13920 KB |
Output is correct |
6 |
Correct |
68 ms |
14060 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
38 ms |
8036 KB |
Output is correct |
9 |
Correct |
46 ms |
13120 KB |
Output is correct |
10 |
Correct |
18 ms |
3688 KB |
Output is correct |
11 |
Correct |
22 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
508 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
436 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
20 ms |
7408 KB |
Output is correct |
19 |
Correct |
25 ms |
9024 KB |
Output is correct |
20 |
Correct |
20 ms |
7576 KB |
Output is correct |
21 |
Correct |
23 ms |
8644 KB |
Output is correct |
22 |
Correct |
20 ms |
7580 KB |
Output is correct |
23 |
Correct |
34 ms |
8640 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
63 ms |
57228 KB |
Output is correct |
26 |
Correct |
133 ms |
71368 KB |
Output is correct |
27 |
Correct |
124 ms |
71624 KB |
Output is correct |
28 |
Correct |
207 ms |
90960 KB |
Output is correct |
29 |
Correct |
210 ms |
90948 KB |
Output is correct |
30 |
Correct |
199 ms |
90824 KB |
Output is correct |
31 |
Correct |
209 ms |
90820 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
604 KB |
Output is correct |
41 |
Correct |
30 ms |
1768 KB |
Output is correct |
42 |
Correct |
10 ms |
988 KB |
Output is correct |
43 |
Correct |
15 ms |
1452 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
7 ms |
1116 KB |
Output is correct |
46 |
Correct |
2 ms |
860 KB |
Output is correct |
47 |
Execution timed out |
1065 ms |
7740 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |