제출 #955342

#제출 시각아이디문제언어결과실행 시간메모리
955342Gray메기 농장 (IOI22_fish)C++17
0 / 100
1171 ms2097152 KiB
// #include <bits/stdc++.h> // #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma") #include <algorithm> #include <cassert> #include <iostream> #include <vector> #define M_PI 3.14159265358979323846 #define ll long long using ld = double; #define ff first #define ss second #define ln "\n" #define gcd(x,y) __gcd(x,y) using namespace std; // const ll MOD = 1e9+7; const ll INF = 2e18; // const ll MAXN = 1e6+1; ll max_weights(int n, int m, vector<int> cx, vector<int> cy, vector<int> cw){ n++; vector<pair<pair<ll, ll>, ll>> fish(m); for (ll i=0; i<m; i++){ fish[i] = {{cx[i], cy[i]+1}, cw[i]}; } sort(fish.begin(), fish.end(), [](auto op1, auto op2)->bool{ return op1.ff.ss<op2.ff.ss; }); vector<vector<ll>> A(n, vector<ll>(n)); for (ll i=0; i<m; i++){ A[fish[i].ff.ff][fish[i].ff.ss]=fish[i].ss; } vector<vector<ll>> pref(n, vector<ll>(n,0)); for (ll i=0; i<n; i++){ for (ll j=0; j<n; j++){ pref[i][j] = (j==0?A[i][j]:pref[i][j-1]+A[i][j]); } } // return 0; vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(n, 0))); for (ll i=1; i<n; i++){ for (ll j=0; j<n; j++){ for (ll k=0; k<n; k++){ if (j>k){ dp[i][j][k] = max(dp[i-1][k][n-1], dp[i-1][k][k]+pref[i-1][n-1]-pref[i-1][k]); }else dp[i][j][k] = dp[i-1][k][n-1]+pref[i][k]-pref[i][j]; if (k)dp[i][j][k]=max(dp[i][j][k-1], dp[i][j][k]); } } } ll mx = 0; for (ll i=0; i<n; i++){ mx = max(mx, dp[n-1][i][n-1]); } return mx; } // int main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); // ll t=1; // cin >> t; // // while (t--) solve(); // } // int main() { // long long N, M; // assert(2 == scanf("%lld %lld", &N, &M)); // std::vector<long long> X(M), Y(M), W(M); // for (long long i = 0; i < M; ++i) { // assert(3 == scanf("%lld %lld %lld", &X[i], &Y[i], &W[i])); // } // long long result = max_weights(N, M, X, Y, W); // printf("%lld\n", result); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...