#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll p2(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector<int> a(n,0), b(n,0);
ll sum=0;
for (int i=0; i<m; ++i) {
if (x[i]==0) a[y[i]]=w[i];
else b[y[i]]=w[i];
sum+=w[i];
}
ll ans=0;
for (int i=0; i<n; ++i) ans+=b[i];
if (n==2) return max(ans,sum-ans);
ll cnt=ans;
for (int i=0; i<n; ++i) {
cnt+=1ll*a[i]-1ll*b[i];
ans=max(ans,cnt);
}
return ans;
}
ll p3(int n, int m, vector<int> x, vector<int> w) {
vector<int> a(n,0);
vector<pair<int,int>> b(n);
for (int i=0; i<n; ++i) b[i]={0,i};
for (int i=0; i<m; ++i) {
b[x[i]]={w[i],x[i]};
a[x[i]]=w[i];
}
sort(b.begin(), b.end());
vector<int> vis(n,0);
ll ans=0;
for (int i=0; i<n; ++i) {
auto it=b[i];
int j=it.second, w=it.first;
//for (auto x:a) cout<<x<<' '; cout<<'\n';
//for (auto x:vis) cout<<x<<' '; cout<<'\n';
//cout<<j<<' '<<w<<'\n';
if ((j?(vis[j-1]?0:a[j-1]):0) + ((j<n-1)?(vis[j+1]?0:a[j+1]):0) > a[j]) {
ans+=(j?(vis[j-1]?0:a[j-1]):0) + ((j<n-1)?(vis[j+1]?0:a[j+1]):0) - a[j];
//cout<<(j?(vis[j-1]?0:a[j-1]):0)<<' '<<((j<n-1)?(vis[j+1]?0:a[j+1]):0)<<' '<<ans<<'\n';
a[j]=0;
if (j) vis[j-1]=1;
if (j<n-1) vis[j+1]=1;
}
}
return ans;
}
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
int _p1=1, _p2=1, _p3=1;
ll sum=0;
for (int i=0; i<m; ++i) {
_p1&=!(x[i]&1);
_p2&=(x[i]<=1);
_p3&=(y[i]==0);
sum+=w[i];
}
if (_p1) return sum;
if (_p2) return p2(n,m,x,y,w);
if (_p3) return p3(n,m,x,w);
}
Compilation message
fish.cpp: In function 'll p3(int, int, std::vector<int>, std::vector<int>)':
fish.cpp:42:22: warning: unused variable 'w' [-Wunused-variable]
42 | int j=it.second, w=it.first;
| ^
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
74 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
2628 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
83 ms |
7244 KB |
Output is correct |
6 |
Correct |
82 ms |
7268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
49 ms |
6732 KB |
Output is correct |
3 |
Correct |
54 ms |
8032 KB |
Output is correct |
4 |
Correct |
21 ms |
2144 KB |
Output is correct |
5 |
Correct |
25 ms |
2628 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
23 ms |
5164 KB |
Output is correct |
13 |
Correct |
27 ms |
6068 KB |
Output is correct |
14 |
Correct |
23 ms |
5220 KB |
Output is correct |
15 |
Correct |
27 ms |
5708 KB |
Output is correct |
16 |
Correct |
24 ms |
5216 KB |
Output is correct |
17 |
Correct |
26 ms |
5684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
1876 KB |
Output is correct |
3 |
Incorrect |
21 ms |
3412 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16876766837917' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
1876 KB |
Output is correct |
3 |
Incorrect |
21 ms |
3412 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16876766837917' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
2628 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
83 ms |
7244 KB |
Output is correct |
6 |
Correct |
82 ms |
7268 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
49 ms |
6732 KB |
Output is correct |
9 |
Correct |
54 ms |
8032 KB |
Output is correct |
10 |
Correct |
21 ms |
2144 KB |
Output is correct |
11 |
Correct |
25 ms |
2628 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
300 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
23 ms |
5164 KB |
Output is correct |
19 |
Correct |
27 ms |
6068 KB |
Output is correct |
20 |
Correct |
23 ms |
5220 KB |
Output is correct |
21 |
Correct |
27 ms |
5708 KB |
Output is correct |
22 |
Correct |
24 ms |
5216 KB |
Output is correct |
23 |
Correct |
26 ms |
5684 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
1876 KB |
Output is correct |
26 |
Incorrect |
21 ms |
3412 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16876766837917' |
27 |
Halted |
0 ms |
0 KB |
- |