# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799938 |
2023-08-01T08:38:17 Z |
LIF |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
116440 KB |
#include "fish.h"
#include <bits/stdc++.h>
#include <vector>
#include<unordered_map>
#pragma GCC optimize(3)
typedef long long int ll;
using namespace std;
long long int a[2][300005];
long long int mp[100005][10];
long long int dp[100005][10][10];
long long int s[100005][10];
vector<int> row[300005];
vector<pair<int,int> > vv[300005];
int find(int coll,int high)
{
int pe = 0;
for(int i=0;i<vv[coll].size();i++)
{
if(high >= vv[coll][i].first) pe += vv[coll][i].second;
}
return pe;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
//subtask1:
bool flag1 = true;
for(int i=0;i<X.size();i++)if(X[i] %2 != 0)flag1 = false;
if(flag1 == true)
{
long long int su = 0;
for(int i=0;i<W.size();i++)su += W[i];
return su;
}
//
//subtask2:
bool flag2 = true;
for(int i=0;i<X.size();i++)if(X[i] > 1)flag2 = false;
if(flag2 == true)
{
long long int maxn = -1;
long long int su = 0;
for(int i=0;i<X.size();i++)a[X[i]][Y[i]] = W[i];
if(N > 2)
{
for(int i=0;i<N;i++)su += a[1][i];
maxn = max(maxn,su);
for(int i=0;i<N;i++)
{
su -= a[1][i];
su += a[0][i];
maxn = max(maxn,su);
}
return maxn;
}
else
{
long long int su1 = 0;
long long int su2 = 0;
for(int i=0;i<N;i++)su1 += a[0][i];
for(int i=0;i<N;i++)su2 += a[1][i];
return max(su1,su2);
}
}
for(int i=0;i<X.size();i++)X[i] += 1;
for(int i=0;i<Y.size();i++)Y[i] += 1;
//subtask3:
bool flag34 = true;
for(int i=0;i<M;i++)
{
if(Y[i] > 10)flag34 = false;
}
long long int zero = 0;
if(flag34 == true)
{
for(int i=0;i<M;i++)mp[X[i]][Y[i]] = W[i];
for(int i=1;i<=N;i++)
{
for(int j=1;j<=9;j++)s[i][j] = s[i][j-1] + mp[i][j];
}
long long int maxn = -1;
for(int i=1;i<=N;i++)
{
for(int j=0;j<=min(N,9);j++)
{
for(int k=0;k<=min(N,9);k++)
{
for(int l=0;l<=min(N,9);l++)
{
if(i!=1)dp[i+1][l][j] = max(dp[i+1][l][j],dp[i][j][k] + max(s[i][max(k,l)] - s[i][j],zero));
else dp[i+1][l][j] = max(dp[i+1][l][j],dp[i][j][k] + max(s[i][l] - s[i][j],zero));
}
}
}
if(i!=1)
{
for(int j=0;j<=min(N,9);j++)
{
for(int k=0;k<=min(N,9);k++)
{
for(int pp=0;pp<=min(N,9);pp++)
{
dp[i][j][k] = max(dp[i][j][k],dp[i-1][k][pp] + max(s[i][k] - s[i][j],zero));
}
}
}
}
}
for(int i=1;i<=N;i++)
{
for(int j=0;j<=min(N,9);j++)
{
for(int k=0;k<=min(N,9);k++)
{
maxn = max(maxn,dp[i][j][k]);
}
}
}
return maxn;
}
else
{
for(int i=0;i<X.size();i++)vv[X[i]].push_back(make_pair(Y[i],W[i]));
for(int i=0;i<X.size();i++)
{
row[X[i]-1].push_back(Y[i]);
row[X[i]+1].push_back(Y[i]);
}
for(int i=1;i<=N;i++)
{
row[i].push_back(0);
sort(row[i].begin(),row[i].end());
sort(vv[i].begin(),vv[i].end());
}
for(int i=1;i<=N;i++)
{
for(int j=0;j<row[i].size();j++)
{
for(int k=0;k<row[i-1].size();k++)
{
for(int l=0;l<row[i+1].size();l++)
{
int maxcol = row[i+1][l];
if(i!=1)maxcol = max(row[i-1][k],maxcol);
int del = find(i,row[i][j]);
int ad = find(i,maxcol);
dp[i+1][l][j] = max(dp[i+1][l][j],dp[i][j][k] + max(ad-del,0));
}
}
}
if(i!=1)
{
for(int j=0;j<row[i].size();j++)
{
for(int k=0;k<row[i-1].size();k++)
{
for(int p=0;p<row[i-2].size();p++)
{
int ad = find(i,row[i-1][k]);
int del = find(i,row[i][j]);
dp[i][j][k] = max(dp[i][j][k],dp[i-1][k][p] + max(ad-del,0));
}
}
}
}
}
long long int maxn = -1;
for(int i=1;i<=N;i++)
{
for(int j=0;j<row[i].size();j++)
{
for(int k=0;k<row[i-1].size();k++)
{
maxn = max(maxn,dp[i][j][k]);
}
}
}
return maxn;
}
//
return 0;
}
Compilation message
fish.cpp: In function 'int find(int, int)':
fish.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<vv[coll].size();i++)
| ~^~~~~~~~~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0;i<X.size();i++)if(X[i] %2 != 0)flag1 = false;
| ~^~~~~~~~~
fish.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<W.size();i++)su += W[i];
| ~^~~~~~~~~
fish.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<X.size();i++)if(X[i] > 1)flag2 = false;
| ~^~~~~~~~~
fish.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0;i<X.size();i++)a[X[i]][Y[i]] = W[i];
| ~^~~~~~~~~
fish.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<X.size();i++)X[i] += 1;
| ~^~~~~~~~~
fish.cpp:66:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<Y.size();i++)Y[i] += 1;
| ~^~~~~~~~~
fish.cpp:123:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(int i=0;i<X.size();i++)vv[X[i]].push_back(make_pair(Y[i],W[i]));
| ~^~~~~~~~~
fish.cpp:124:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int i=0;i<X.size();i++)
| ~^~~~~~~~~
fish.cpp:137:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for(int j=0;j<row[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:139:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int k=0;k<row[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:141:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int l=0;l<row[i+1].size();l++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:156:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
156 | for(int j=0;j<row[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:158:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | for(int k=0;k<row[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:160:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
160 | for(int p=0;p<row[i-2].size();p++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:173:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
173 | for(int j=0;j<row[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:175:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
175 | for(int k=0;k<row[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
17636 KB |
Output is correct |
2 |
Correct |
29 ms |
18368 KB |
Output is correct |
3 |
Correct |
10 ms |
14312 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
76 ms |
27748 KB |
Output is correct |
6 |
Correct |
80 ms |
28136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
44 ms |
22428 KB |
Output is correct |
3 |
Correct |
56 ms |
24036 KB |
Output is correct |
4 |
Correct |
25 ms |
17640 KB |
Output is correct |
5 |
Correct |
28 ms |
18456 KB |
Output is correct |
6 |
Correct |
8 ms |
14292 KB |
Output is correct |
7 |
Correct |
6 ms |
14420 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
6 ms |
14396 KB |
Output is correct |
10 |
Correct |
7 ms |
14400 KB |
Output is correct |
11 |
Correct |
7 ms |
14292 KB |
Output is correct |
12 |
Correct |
25 ms |
18368 KB |
Output is correct |
13 |
Correct |
30 ms |
19148 KB |
Output is correct |
14 |
Correct |
27 ms |
18420 KB |
Output is correct |
15 |
Correct |
29 ms |
18896 KB |
Output is correct |
16 |
Correct |
27 ms |
18416 KB |
Output is correct |
17 |
Correct |
29 ms |
18780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
294 ms |
100424 KB |
Output is correct |
3 |
Correct |
275 ms |
98876 KB |
Output is correct |
4 |
Correct |
302 ms |
106692 KB |
Output is correct |
5 |
Correct |
322 ms |
112264 KB |
Output is correct |
6 |
Correct |
310 ms |
111564 KB |
Output is correct |
7 |
Correct |
316 ms |
112236 KB |
Output is correct |
8 |
Correct |
320 ms |
112188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14396 KB |
Output is correct |
3 |
Correct |
7 ms |
14348 KB |
Output is correct |
4 |
Correct |
6 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
9 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14292 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14548 KB |
Output is correct |
10 |
Correct |
9 ms |
14676 KB |
Output is correct |
11 |
Correct |
7 ms |
14548 KB |
Output is correct |
12 |
Correct |
8 ms |
14676 KB |
Output is correct |
13 |
Correct |
7 ms |
14400 KB |
Output is correct |
14 |
Correct |
8 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14396 KB |
Output is correct |
3 |
Correct |
7 ms |
14348 KB |
Output is correct |
4 |
Correct |
6 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
9 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14292 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14548 KB |
Output is correct |
10 |
Correct |
9 ms |
14676 KB |
Output is correct |
11 |
Correct |
7 ms |
14548 KB |
Output is correct |
12 |
Correct |
8 ms |
14676 KB |
Output is correct |
13 |
Correct |
7 ms |
14400 KB |
Output is correct |
14 |
Correct |
8 ms |
14676 KB |
Output is correct |
15 |
Correct |
7 ms |
14676 KB |
Output is correct |
16 |
Execution timed out |
1091 ms |
14568 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14396 KB |
Output is correct |
3 |
Correct |
7 ms |
14348 KB |
Output is correct |
4 |
Correct |
6 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
9 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14292 KB |
Output is correct |
8 |
Correct |
7 ms |
14420 KB |
Output is correct |
9 |
Correct |
8 ms |
14548 KB |
Output is correct |
10 |
Correct |
9 ms |
14676 KB |
Output is correct |
11 |
Correct |
7 ms |
14548 KB |
Output is correct |
12 |
Correct |
8 ms |
14676 KB |
Output is correct |
13 |
Correct |
7 ms |
14400 KB |
Output is correct |
14 |
Correct |
8 ms |
14676 KB |
Output is correct |
15 |
Correct |
7 ms |
14676 KB |
Output is correct |
16 |
Execution timed out |
1091 ms |
14568 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
294 ms |
100424 KB |
Output is correct |
3 |
Correct |
275 ms |
98876 KB |
Output is correct |
4 |
Correct |
302 ms |
106692 KB |
Output is correct |
5 |
Correct |
322 ms |
112264 KB |
Output is correct |
6 |
Correct |
310 ms |
111564 KB |
Output is correct |
7 |
Correct |
316 ms |
112236 KB |
Output is correct |
8 |
Correct |
320 ms |
112188 KB |
Output is correct |
9 |
Correct |
128 ms |
102612 KB |
Output is correct |
10 |
Correct |
191 ms |
65452 KB |
Output is correct |
11 |
Correct |
339 ms |
116440 KB |
Output is correct |
12 |
Correct |
7 ms |
14404 KB |
Output is correct |
13 |
Correct |
7 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
7 ms |
14408 KB |
Output is correct |
16 |
Correct |
7 ms |
14292 KB |
Output is correct |
17 |
Correct |
8 ms |
14404 KB |
Output is correct |
18 |
Correct |
7 ms |
14284 KB |
Output is correct |
19 |
Correct |
8 ms |
14408 KB |
Output is correct |
20 |
Correct |
294 ms |
100400 KB |
Output is correct |
21 |
Correct |
50 ms |
95796 KB |
Output is correct |
22 |
Correct |
169 ms |
102468 KB |
Output is correct |
23 |
Correct |
362 ms |
116440 KB |
Output is correct |
24 |
Correct |
318 ms |
110292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
17636 KB |
Output is correct |
2 |
Correct |
29 ms |
18368 KB |
Output is correct |
3 |
Correct |
10 ms |
14312 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
76 ms |
27748 KB |
Output is correct |
6 |
Correct |
80 ms |
28136 KB |
Output is correct |
7 |
Correct |
7 ms |
14292 KB |
Output is correct |
8 |
Correct |
44 ms |
22428 KB |
Output is correct |
9 |
Correct |
56 ms |
24036 KB |
Output is correct |
10 |
Correct |
25 ms |
17640 KB |
Output is correct |
11 |
Correct |
28 ms |
18456 KB |
Output is correct |
12 |
Correct |
8 ms |
14292 KB |
Output is correct |
13 |
Correct |
6 ms |
14420 KB |
Output is correct |
14 |
Correct |
7 ms |
14420 KB |
Output is correct |
15 |
Correct |
6 ms |
14396 KB |
Output is correct |
16 |
Correct |
7 ms |
14400 KB |
Output is correct |
17 |
Correct |
7 ms |
14292 KB |
Output is correct |
18 |
Correct |
25 ms |
18368 KB |
Output is correct |
19 |
Correct |
30 ms |
19148 KB |
Output is correct |
20 |
Correct |
27 ms |
18420 KB |
Output is correct |
21 |
Correct |
29 ms |
18896 KB |
Output is correct |
22 |
Correct |
27 ms |
18416 KB |
Output is correct |
23 |
Correct |
29 ms |
18780 KB |
Output is correct |
24 |
Correct |
7 ms |
14292 KB |
Output is correct |
25 |
Correct |
294 ms |
100424 KB |
Output is correct |
26 |
Correct |
275 ms |
98876 KB |
Output is correct |
27 |
Correct |
302 ms |
106692 KB |
Output is correct |
28 |
Correct |
322 ms |
112264 KB |
Output is correct |
29 |
Correct |
310 ms |
111564 KB |
Output is correct |
30 |
Correct |
316 ms |
112236 KB |
Output is correct |
31 |
Correct |
320 ms |
112188 KB |
Output is correct |
32 |
Correct |
7 ms |
14420 KB |
Output is correct |
33 |
Correct |
7 ms |
14396 KB |
Output is correct |
34 |
Correct |
7 ms |
14348 KB |
Output is correct |
35 |
Correct |
6 ms |
14380 KB |
Output is correct |
36 |
Correct |
8 ms |
14420 KB |
Output is correct |
37 |
Correct |
9 ms |
14420 KB |
Output is correct |
38 |
Correct |
8 ms |
14292 KB |
Output is correct |
39 |
Correct |
7 ms |
14420 KB |
Output is correct |
40 |
Correct |
8 ms |
14548 KB |
Output is correct |
41 |
Correct |
9 ms |
14676 KB |
Output is correct |
42 |
Correct |
7 ms |
14548 KB |
Output is correct |
43 |
Correct |
8 ms |
14676 KB |
Output is correct |
44 |
Correct |
7 ms |
14400 KB |
Output is correct |
45 |
Correct |
8 ms |
14676 KB |
Output is correct |
46 |
Correct |
7 ms |
14676 KB |
Output is correct |
47 |
Execution timed out |
1091 ms |
14568 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |