제출 #751686

#제출 시각아이디문제언어결과실행 시간메모리
751686He_Huanglu메기 농장 (IOI22_fish)C++17
100 / 100
386 ms40608 KiB
#include <bits/stdc++.h> #define ii pair<int, int> #define fi first #define se second using namespace std; const int N = 1e5 + 5; long long f[3][2][2], g[3][2][2], res; ii p[3][2][2], t[3][3]; vector <long long> col[N], pref[N], _h[N]; ii check(int i, int j, int k) { ii ret = t[0][i]; if(!ret.fi) ret.fi = t[1][j].fi; else if(ret.fi == 2 && j) return {1e9, 1e9}; if(!ret.se) ret.se = t[2][k].se; else if(ret.se == 1 && k) return {1e9, 1e9}; return ret; } long long cal(int c, int h) { if(c < 0 || col[c].empty()) return 0; int it = lower_bound(_h[c].begin(), _h[c].end(), h) - _h[c].begin(); return pref[c][it]; } long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) { t[0][2] = {1, 2}; t[0][0].fi = 2; t[0][1].se = 1; t[1][1].fi = 1; t[2][1].se = 2; for(int i = 0; i < m; i++) col[x[i]].push_back(i); for(int c = 0; c < n; c++) { col[c].push_back(m); y.push_back(n), w.push_back(0); m++; sort(col[c].begin(), col[c].end(), [&] (int i, int j) { return y[i] < y[j]; }); pref[c].push_back(0); for(int i : col[c]) { pref[c].push_back(pref[c].back() + w[i]); _h[c].push_back(y[i]); } } for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) p[x1][x2][x3] = check(x1, x2, x3); for(int c = 0; c < n; c++) { for(int i : col[c]) { long long v1 = cal(c - 1, y[i]), v2 = cal(c, y[i]), v3 = cal(c + 1, y[i]); for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) { long long v = v1 * x2 + v3 * x3 - v2 * (x1 < 2); for(int y1 = 0; y1 < 3; y1++) for(int y2 = 0; y2 < 2; y2++) for(int y3 = 0; y3 < 2; y3++) { if(p[x1][x2][x3].fi == 1e9 || p[y1][y2][y3].se == 1e9) continue; if(p[x1][x2][x3].fi && p[x1][x2][x3].fi != p[y1][y2][y3].se) continue ; if(x2 != (y1 % 2))continue ; if((y3 == 1 && x1 != 0) || (y3 == 0 && x1 == 0)) continue; f[x1][x2][x3] = max(f[x1][x2][x3], g[y1][y2][y3] + v); } } } for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) g[x1][x2][x3] = f[x1][x2][x3], f[x1][x2][x3] = 0; } for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) res = max(res, g[x1][x2][x3]); return res; } //main () { // cin.tie(0)->sync_with_stdio(0); // if(fopen("task.inp", "r")) { // freopen("task.inp", "r", stdin); // freopen("wa.out", "w", stdout); // } // int n, m; cin >> n >> m; // vector <int> x(m), y(m), w(m); // for(int i = 0; i < m; i++) cin >> x[i] >> y[i] >> w[i]; // cout << max_weights(n, m, x, y, w) << "\n"; //}
#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...