#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
ll levoo(int i, vector<ll> &levo, int n) {
if (i < 0 || i >= n)
return 0;
return levo[i];
}
ll desnoo(int i, vector<ll> &desno, int n) {
if (i < 0 || i >= n)
return 0;
return desno[i];
}
ll dpp(int i, int j, vector<vector<ll> > &dp, int n) {
if (i < 0 || i >= n)
return 0;
return dp[i][j];
}
ll vall(int i, vector<ll> &val, int n) {
if (i < 0 || i >= n)
return 0;
return val[i];
}
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector<ll> val(n, 0);
vector<set<pair<ll, ll> > > visine(n);
vector<ll> desno(n, 0), levo(n, 0);
for (int i = 0; i < m; ++i) {
visine[x[i]].insert({y[i], i});
val[x[i]] += (ll)w[i];
}
ll sigurno = 0;
for (int i = 0; i < n; ++i) {
ll cnt = 0;
if (i - 1 >= 0 && !visine[i - 1].empty()) {
for (auto u : visine[i]) {
if (y[u.second] >= (*(visine[i - 1].begin())).first)
break;
cnt += (ll)w[u.second];
}
levo[i] = cnt;
}
if (i + 1 < n && !visine[i + 1].empty()) {
cnt = 0;
for (auto u : visine[i]) {
if (y[u.second] >= (*(visine[i + 1].begin())).first)
break;
cnt += (ll)w[u.second];
}
desno[i] = cnt;
}
}
if (n == 1)
return 0;
if (n == 2) {
return max(val[0], val[1]);
}
if (n >= 3) {
return max({val[0], val[1] + desno[0]});
}
vector<vector<ll> > dp(n, vector<ll>(3, 0));
for (int i = 0; i < n; ++i) {
dp[i][0] = max({vall(i - 1, val, n) + max({dpp(i - 2, 2, dp, n), desnoo(i - 2, desno, n) + dpp(i - 2, 1, dp, n), dpp(i - 2, 0, dp, n)}), dpp(i - 1, 2, dp, n), dpp(i - 1, 0, dp, n)});
dp[i][1] = max(dpp(i - 1, 1, dp, n), dpp(i - 1, 2, dp, n));
dp[i][2] = ((i - 1 >= 0) ? val[i] : 0) + dpp(i - 1, 0, dp, n);
}
ll jos = 0;
if (n >= 3) {
jos = dp[n - 2][2] + levo[n - 1];
}
if (n == 1)
return 0;
if (n == 2) {
return max(val[0], val[1]);
}
if (n >= 3) {
return max({val[0], val[1] + desno[0]});
}
return max({dp[n - 1][0], dp[n - 1][2], jos});
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:73:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
73 | if (n == 1)
| ^~
fish.cpp:75:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
75 | if (n == 2) {
| ^~
fish.cpp:93:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
93 | if (n == 1)
| ^~
fish.cpp:95:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
95 | if (n == 2) {
| ^~
fish.cpp:51:6: warning: unused variable 'sigurno' [-Wunused-variable]
51 | ll sigurno = 0;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
13648 KB |
Output is correct |
2 |
Correct |
59 ms |
15952 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7260 KB |
Output is correct |
5 |
Incorrect |
245 ms |
33088 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '0' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
104 ms |
20576 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '40479197388443' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7260 KB |
Output is correct |
2 |
Incorrect |
2 ms |
7260 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7260 KB |
Output is correct |
2 |
Incorrect |
2 ms |
7260 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
13648 KB |
Output is correct |
2 |
Correct |
59 ms |
15952 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7260 KB |
Output is correct |
5 |
Incorrect |
245 ms |
33088 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '0' |
6 |
Halted |
0 ms |
0 KB |
- |