/**
* Author : Nguyen Tuan Vu
* Created : 01.01.2023
**/
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1ll)<<(x))
#define BIT(x, i) (((x)>>(i))&(1))
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define db(val) "["#val" = "<<(val)<<"] "
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
using namespace std;
mt19937 jdg(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {return l + jdg() % (r - l + 1);}
const int N = 1e5 + 5;
namespace sub1 {
bool check(int m, vector <array <int, 3>> fishes) {
REP(i, m) {
if (fishes[i][0] & 1) return false;
}
return true;
}
long long solve(int m, vector <array <int, 3>> fishes) {
//assert(1 == 0);
long long ans = 0;
REP(i, m) ans += fishes[i][2];
return ans;
}
}
namespace sub2 {
bool check(int m, vector <array <int, 3>> fishes) {
REP(i, m) if (fishes[i][0] > 1) return false;
return true;
}
long long solve(int n, int m, vector <array <int, 3>> fishes) {
//assert(1 == 0);
if (n == 2) {
long long ans[2] = {0};
REP(i, m) ans[fishes[i][0]] += fishes[i][2];
return max(ans[0], ans[1]);
}
vector <long long> sum[2];
REP(i, 2) sum[i].resize(n + 7, 0);
REP(i, m) sum[fishes[i][0]][fishes[i][1]] += fishes[i][2];
FOR(i, 1, n - 1) REP(j, 2) sum[j][i] = sum[j][i - 1] + sum[j][i];
long long ans = sum[1][n - 1];
REP(i, n) maximize(ans, sum[0][i] + sum[1][n - 1] - sum[1][i]);
return ans;
}
}
namespace sub3 {
bool check(int m, vector <array <int, 3>> fishes) {
REP(i, m) if (fishes[i][1] != 0) return false;
return true;
}
long long dp[N][2][2];
int cost[N];
long long solve(int n, int m, vector <array <int, 3>> fishes) {
REP(i, m) cost[fishes[i][0]] = fishes[i][2];
memset(dp, -1, sizeof dp);
dp[0][0][0] = 0;
dp[0][1][1] = 0;
REP(i, n - 1) {
REP(j, 2) REP(k, 2) if (dp[i][j][k] != -1) {
if (j == 0) {
if (k == 0) {
maximize(dp[i + 1][0][0], dp[i][j][k]);
maximize(dp[i + 1][1][1], dp[i][j][k] + cost[i]);
}
else {
maximize(dp[i + 1][0][0], dp[i][j][k]);
maximize(dp[i + 1][1][1], dp[i][j][k]);
}
}
else {
maximize(dp[i + 1][1][1], dp[i][j][k]);
maximize(dp[i + 1][0][1], dp[i][j][k] + cost[i + 1]);
}
}
}
long long ans = 0;
REP(j, 2) REP(k, 2) maximize(ans, dp[n - 1][j][k]);
return ans;
}
}
long long max_weights(int n, int m, vector <int> X, vector <int> Y, vector <int> W) {
vector <array <int, 3>> fishes;
fishes.resize(m + 7);
REP(i, m) fishes[i] = {X[i], Y[i], W[i]};
if (sub1::check(m, fishes)) return sub1::solve(m, fishes);
else if (sub2::check(m, fishes)) return sub2::solve(n, m, fishes);
else if (sub3::check(m, fishes)) return sub3::solve(n, m, fishes);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
4052 KB |
Output is correct |
2 |
Correct |
27 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
89 ms |
14380 KB |
Output is correct |
6 |
Correct |
89 ms |
14352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
47 ms |
9308 KB |
Output is correct |
3 |
Correct |
58 ms |
11188 KB |
Output is correct |
4 |
Correct |
22 ms |
4052 KB |
Output is correct |
5 |
Correct |
28 ms |
5072 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
24 ms |
5444 KB |
Output is correct |
13 |
Correct |
31 ms |
6456 KB |
Output is correct |
14 |
Correct |
25 ms |
5532 KB |
Output is correct |
15 |
Correct |
29 ms |
6108 KB |
Output is correct |
16 |
Correct |
24 ms |
5444 KB |
Output is correct |
17 |
Correct |
26 ms |
6068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
6220 KB |
Output is correct |
4 |
Correct |
13 ms |
5944 KB |
Output is correct |
5 |
Correct |
29 ms |
10048 KB |
Output is correct |
6 |
Correct |
26 ms |
9388 KB |
Output is correct |
7 |
Correct |
30 ms |
10020 KB |
Output is correct |
8 |
Correct |
29 ms |
10032 KB |
Output is correct |
# |
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 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
6220 KB |
Output is correct |
4 |
Correct |
13 ms |
5944 KB |
Output is correct |
5 |
Correct |
29 ms |
10048 KB |
Output is correct |
6 |
Correct |
26 ms |
9388 KB |
Output is correct |
7 |
Correct |
30 ms |
10020 KB |
Output is correct |
8 |
Correct |
29 ms |
10032 KB |
Output is correct |
9 |
Incorrect |
25 ms |
6336 KB |
1st lines differ - on the 1st token, expected: '99999', found: '0' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
4052 KB |
Output is correct |
2 |
Correct |
27 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
89 ms |
14380 KB |
Output is correct |
6 |
Correct |
89 ms |
14352 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
47 ms |
9308 KB |
Output is correct |
9 |
Correct |
58 ms |
11188 KB |
Output is correct |
10 |
Correct |
22 ms |
4052 KB |
Output is correct |
11 |
Correct |
28 ms |
5072 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
24 ms |
5444 KB |
Output is correct |
19 |
Correct |
31 ms |
6456 KB |
Output is correct |
20 |
Correct |
25 ms |
5532 KB |
Output is correct |
21 |
Correct |
29 ms |
6108 KB |
Output is correct |
22 |
Correct |
24 ms |
5444 KB |
Output is correct |
23 |
Correct |
26 ms |
6068 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
3412 KB |
Output is correct |
26 |
Correct |
17 ms |
6220 KB |
Output is correct |
27 |
Correct |
13 ms |
5944 KB |
Output is correct |
28 |
Correct |
29 ms |
10048 KB |
Output is correct |
29 |
Correct |
26 ms |
9388 KB |
Output is correct |
30 |
Correct |
30 ms |
10020 KB |
Output is correct |
31 |
Correct |
29 ms |
10032 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
33 |
Halted |
0 ms |
0 KB |
- |