#include "fish.h"
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define printclock cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll B) { return (unsigned ll)rng() % B;}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void chmax(ll &a, ll b){
a = max(a, b);
}
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector<vector<int>> adj(n);
for(int i = 0; i < m; i++){
adj[x[i]].pb(y[i]);
}
map<pair<int, int>, ll> score;
for(int i = 0; i < m; i++){
score[{x[i], y[i]}] = w[i];
}
map<ll, ll> L, R, S;
L[-1] = R[-1] = 0;
S[-1] = 0;
for(int i = 0; i < n; i++){
set<int> nys, nyx;
nys.insert(-1);
for(auto u : adj[i]){
nys.insert(u);
}
nyx = nys;
if(i) {
for(auto [a, b] : L){
nys.insert(a);
}
for(auto u : adj[i - 1]){
nyx.insert(u);
}
}
if(i + 1 < n){
for(auto u : adj[i + 1]){
nys.insert(u);
nyx.insert(u);
}
}
vector<int> ny;
for(auto u : nys) ny.pb(u);
map<ll, ll> nL, nR, nS, nSS;
for(auto u : ny){
nS[u] += score[{i, u}];
nSS[u] = S[u];
}
int p = -1;
nSS = S;
ll mmx = 0;
for(auto [a, b] : nS){
chmax(mmx, nSS[a]);
if(p != -1){
nS[a] += nS[p];
nSS[a] = mmx;
}
p = a;
}
S = nSS;
{
//Case 1.1
ll mx = -INF;
for(auto j : ny){
if(i){
chmax(mx, L[j]);
}
chmax(nL[j], mx);
}
}
{
//Case 1.2
ll mx = -INF;
for(int k = ny.size() - 1; k >= 0; k--){
int j = ny[k];
chmax(nL[j], mx - nS[j]);
if(i){
chmax(mx, L[j] + nS[j]);
}
}
}
{
//Case 2.1
ll mx = -INF;
for(auto j : ny){
if(i){
chmax(mx, R[j] - S[j]);
}
chmax(nL[j], mx + S[j]);
}
}
{
//Case 2.2
ll mx = -INF;
for(int k = ny.size() - 1; k >= 0; k--){
int j = ny[k];
chmax(nL[j], mx - nS[j]);
if(i){
chmax(mx, R[j] + nS[j]);
}
}
}
{
//Case 3.1
ll mx = -INF;
for(auto j : ny){
chmax(mx, L[j]);
}
for(auto j : ny){
chmax(nR[j], mx);
}
}
{
//Case 4.1
ll mx = -INF;
for(auto j : ny){
chmax(mx, R[j] - S[j]);
chmax(nR[j], mx + S[j]);
}
}
{
//Case 4.2
ll mx = -INF;
for(int k = ny.size() - 1; k >= 0; k--){
int j = ny[k];
chmax(nR[j], mx);
chmax(mx, R[j]);
}
}
map<ll,ll> nnL, nnR, nnS;
for(auto u : nyx){
nnL[u] = nL[u];
nnR[u] = nR[u];
nnS[u] = nS[u];
}
swap(L, nnL);
swap(R, nnR);
swap(S, nnS);
// cout << i << " $$$$$$$$$$$$$$$$$$$$$" << endl;
// for(auto [a, b] : L){
// cout << a << " : " << b << " " << R[a] << endl;
// }
}
ll ans = 0;
for(auto [a, b] : L){
chmax(ans, b);
// cout << a << " : " << b << endl;
chmax(ans, R[a]);
}
return ans;
}
Compilation message
fish.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization ("O3")
|
fish.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
7 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
73752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
82576 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
8840 KB |
Output is correct |
2 |
Correct |
72 ms |
8796 KB |
Output is correct |
3 |
Correct |
138 ms |
14672 KB |
Output is correct |
4 |
Correct |
137 ms |
13836 KB |
Output is correct |
5 |
Correct |
227 ms |
20556 KB |
Output is correct |
6 |
Correct |
203 ms |
20600 KB |
Output is correct |
7 |
Correct |
225 ms |
20700 KB |
Output is correct |
8 |
Correct |
223 ms |
20548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
596 KB |
Output is correct |
17 |
Correct |
177 ms |
5744 KB |
Output is correct |
18 |
Correct |
164 ms |
5188 KB |
Output is correct |
19 |
Correct |
167 ms |
5540 KB |
Output is correct |
20 |
Correct |
119 ms |
4768 KB |
Output is correct |
21 |
Correct |
116 ms |
4624 KB |
Output is correct |
22 |
Correct |
335 ms |
9036 KB |
Output is correct |
23 |
Correct |
72 ms |
2508 KB |
Output is correct |
24 |
Correct |
181 ms |
5764 KB |
Output is correct |
25 |
Correct |
5 ms |
468 KB |
Output is correct |
26 |
Correct |
56 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
7 ms |
596 KB |
Output is correct |
17 |
Correct |
177 ms |
5744 KB |
Output is correct |
18 |
Correct |
164 ms |
5188 KB |
Output is correct |
19 |
Correct |
167 ms |
5540 KB |
Output is correct |
20 |
Correct |
119 ms |
4768 KB |
Output is correct |
21 |
Correct |
116 ms |
4624 KB |
Output is correct |
22 |
Correct |
335 ms |
9036 KB |
Output is correct |
23 |
Correct |
72 ms |
2508 KB |
Output is correct |
24 |
Correct |
181 ms |
5764 KB |
Output is correct |
25 |
Correct |
5 ms |
468 KB |
Output is correct |
26 |
Correct |
56 ms |
2132 KB |
Output is correct |
27 |
Correct |
17 ms |
1428 KB |
Output is correct |
28 |
Correct |
930 ms |
24588 KB |
Output is correct |
29 |
Execution timed out |
1090 ms |
38552 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
8840 KB |
Output is correct |
2 |
Correct |
72 ms |
8796 KB |
Output is correct |
3 |
Correct |
138 ms |
14672 KB |
Output is correct |
4 |
Correct |
137 ms |
13836 KB |
Output is correct |
5 |
Correct |
227 ms |
20556 KB |
Output is correct |
6 |
Correct |
203 ms |
20600 KB |
Output is correct |
7 |
Correct |
225 ms |
20700 KB |
Output is correct |
8 |
Correct |
223 ms |
20548 KB |
Output is correct |
9 |
Correct |
471 ms |
39320 KB |
Output is correct |
10 |
Correct |
190 ms |
14840 KB |
Output is correct |
11 |
Correct |
449 ms |
29272 KB |
Output is correct |
12 |
Correct |
0 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 |
83 ms |
8876 KB |
Output is correct |
19 |
Correct |
74 ms |
8884 KB |
Output is correct |
20 |
Correct |
72 ms |
8780 KB |
Output is correct |
21 |
Correct |
74 ms |
8780 KB |
Output is correct |
22 |
Correct |
608 ms |
38236 KB |
Output is correct |
23 |
Correct |
725 ms |
45272 KB |
Output is correct |
24 |
Correct |
751 ms |
49392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
73752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |