Submission #1180557

#TimeUsernameProblemLanguageResultExecution timeMemory
1180557madamadam3Catfish Farm (IOI22_fish)C++20
0 / 100
45 ms7028 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; using vi = vector<int>; typedef long long ll; #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() #define pb push_back /* Time log: - first start: 1048am - 3/100: 1100am - first stop: 1128am - second start: 337pm - - second end: - overall time used: */ /* NxN grid of cells grid[c][r] = the cell at column c row r grid[0][r] is the westernmost point, and grid[N-1][r] is the easternmost point grid[c][0] = southernmost point, grid[c][N-1] northermost point M catfishes X[i], Y[i] for i < M are column and row of fish i W[i] = weight of fish i a catfish can be caught if grid[ci][ri] is empty and grid[ci-1][ri] or grid[ci+1][ri] has a pier tile a pier extends from grid[cP][0] to grid[cP][rP] */ int N, M; vi X, Y, W; bool cmp(int a, int b) { // compare two fish in the same col return Y[a] < Y[b]; } ll max_weights(int _N, int _M, vi _X, vi _Y, vi _W) { N = _N; M = _M; X = _X; Y = _Y; W = _W; // subtask 2: x[i] <= 1: either use everything in col0, or col1 (as using 1 means you cant use the other) ll c0 = 0, c1 = 0; vi f0, f1; for (int i = 0; i < M; i++) { // cout << "i: " << i << " x: " << X[i] << " y: " << Y[i] << " W: " << W[i] << "\n"; if (X[i] == 0) { c0 += W[i]; f0.pb(i); } else { c1 += W[i]; f1.pb(i); } } sort(all(f0), cmp); sort(all(f1), cmp); int Z = sz(f0), O = sz(f1); // cout << "Z: " << Z << " O: " << O << "\n"; int i = 0, j = 0; ll v = c1; ll ans = v; while (i < Z || j < O) { if (j >= O || ((i < Z) && Y[f0[i]] < Y[f1[j]])) { v += W[f0[i]]; ans = max(ans, v); i++; } if (i >= Z || ((j < O) && Y[f1[j]] < Y[f0[i]])) { v -= W[f1[j]]; j++; } else { break; } } return ans; }
#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...