제출 #625508

#제출 시각아이디문제언어결과실행 시간메모리
625508I_love_Hoang_Yen메기 농장 (IOI22_fish)C++17
18 / 100
98 ms19788 KiB
#include "bits/stdc++.h" using namespace std; #define int long long struct Fish { int col, row; int weight; }; bool operator < (const Fish& a, const Fish& b) { if (a.col != b.col) return a.col < b.col; return a.row < b.row; } // fishes are on even columns -> build piers on odd columns // & catch all fishes int sub1(const std::vector<Fish>& fishes) { int res = 0; for (const auto& fish : fishes) { res += fish.weight; } return res; } // fishes are on first 2 columns int sub2(int n, const std::vector<Fish>& fishes) { std::vector<int> zeroes(n); // prefix sum of fish weights at column == 0 std::vector<int> ones(n); // prefix sum of fish weights at column == 1 for (const auto& fish : fishes) { if (fish.col == 0) zeroes[fish.row] += fish.weight; if (fish.col == 1) ones[fish.row] += fish.weight; } std::partial_sum(zeroes.begin(), zeroes.end(), zeroes.begin()); std::partial_sum(ones.begin(), ones.end(), ones.begin()); int res = ones.back(); // init: only catch fishes at column == 1 for (int i = 0; i < n; ++i) { // build pier until at column 1, row 0-i if (n == 2) res = std::max(res, zeroes[i]); else res = std::max(res, zeroes[i] + ones.back() - ones[i]); } return res; } // all fishes are on row == 0 int sub3(int n, const std::vector<Fish>& fishes) { std::vector<int> weights(n); // weights[i] = weight of fish at column i for (const auto& fish : fishes) { weights[fish.col] += fish.weight; } // f[i] = best strategy if we BUILD PIER AT i, only considering col 0..i // i-4 i-3 i-2 i-1 i std::vector<int> f(n); f[0] = 0; for (int i = 1; i < n; ++i) { f[i] = std::max(f[i-1], weights[i-1]); if (i >= 2) { f[i] = std::max(f[i], f[i-2] + weights[i-1]); } if (i >= 3) { f[i] = std::max(f[i], f[i-3] + weights[i-2] + weights[i-1]); } } int res = 0; for (int i = 0; i < n; ++i) { int cur = f[i]; if (i + 1 < n) cur += weights[i+1]; res = std::max(res, cur); } return res; } #undef int long long max_weights( int n, int nFish, std::vector<int> xs, std::vector<int> ys, std::vector<int> ws) { std::vector<Fish> fishes; for (int i = 0; i < nFish; ++i) { fishes.push_back({xs[i], ys[i], ws[i]}); } if (std::all_of(xs.begin(), xs.end(), [] (int x) { return x % 2 == 0; })) { return sub1(fishes); } if (*std::max_element(xs.begin(), xs.end()) <= 1) { return sub2(n, fishes); } if (*std::max_element(ys.begin(), ys.end()) == 0) { return sub3(n, fishes); } 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...