제출 #824963

#제출 시각아이디문제언어결과실행 시간메모리
824963becaido메기 농장 (IOI22_fish)C++17
0 / 100
1077 ms69620 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "fish.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const ll INF = 1e18; const int SIZE = 3005; int n, m; ll pre[SIZE][SIZE]; ll inc[2][SIZE], dek[2][SIZE], all[2], zero[2], fzero[2]; void chmax(ll &x, ll y) { x = max(x, y); } ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) { n = N; FOR (i, 0, M - 1) { X[i]++, Y[i]++; pre[X[i]][Y[i]] += W[i]; m = max(m, Y[i]); } all[0] = -INF; FOR (i, 1, m) inc[0][i] = dek[0][i] = -INF; FOR (i, 1, n) { FOR (j, 1, m) pre[i][j] += pre[i][j - 1]; int f = i & 1; all[f] = zero[f] = fzero[f] = -INF; FOR (j, 1, m) inc[f][j] = dek[f][j] = -INF; FOR (j, 1, m) inc[!f][j] -= pre[i - 1][j]; ll mx = zero[!f]; FOR (j, 1, m) { chmax(inc[f][j], mx + pre[i - 1][j]); chmax(mx, inc[!f][j]); } FOR (j, 1, m) dek[!f][j] += pre[i][j]; mx = all[!f] + pre[i][m]; for (int j = m; j >= 0; j--) { chmax(dek[f][j], mx - (j ? pre[i][j - 1] : 0)); chmax(mx, dek[!f][j]); } chmax(all[f], all[!f]); chmax(all[f], fzero[!f]); chmax(all[f], inc[f][m]); chmax(zero[f], zero[!f]); chmax(zero[f], fzero[!f]); chmax(fzero[f], dek[f][0]); } ll ans = 0; int f = n & 1; chmax(ans, zero[f]); chmax(ans, fzero[f]); chmax(ans, all[f]); return ans; } /* in1 5 4 0 2 5 1 1 2 4 4 1 3 3 3 out1 8 */ #ifdef WAIMAI int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); vector<int> X(M), Y(M), W(M); for (int i = 0; i < M; ++i) { assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i])); } long long result = max_weights(N, M, X, Y, W); printf("%lld\n", result); return 0; } #endif
#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...