제출 #1180578

#제출 시각아이디문제언어결과실행 시간메모리
1180578madamadam3메기 농장 (IOI22_fish)C++20
6 / 100
57 ms14008 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; vector<ll> 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; for (int i = 0; i < M; i++) W.pb(ll(_W[i]));

  // subtask 2: x[i] <= 1: either use everything in col0, or col1 (as using 1 means you cant use the other)
  ll c1 = 0;
  ll pc0 = 0;
  ll fish[2][N];
  for (int i = 0; i < N; i++) fish[0][i] = fish[1][i] = 0LL;

  for (int i = 0; i < M; i++) {
    // cout << "i: " << i << " x: " << X[i] << " y: " << Y[i] << " W: " << W[i] << "\n";
    if (X[i] == 1) {
      c1 += W[i];
      fish[1][Y[i]] = W[i];
    } else if (X[i] == 0) {
      pc0 += W[i];
      fish[0][Y[i]] = W[i];
    }
  }

  if (N >= 3) {
    ll c0 = 0;
    ll ans = c1;

    for (int i = 0; i < N; i++) {
      c1 -= fish[1][i];
      c0 += fish[0][i];
      ans = max(ans, c0 + c1);
    }

    return max(ans, c1);
  } else if (N == 2) {
    return max(c1, pc0);
  }
}

컴파일 시 표준 에러 (stderr) 메시지

fish.cpp: In function 'll max_weights(int, int, vi, vi, vi)':
fish.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      | ^
#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...