Submission #826753

# Submission time Handle Problem Language Result Execution time Memory
826753 2023-08-16T02:23:18 Z Username4132 Catfish Farm (IOI22_fish) C++17
3 / 100
208 ms 22036 KB
#include "fish.h"

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define dforsn(i, s, n) for(int i=n-1; i>=s; --i)
#define PB push_back
#define F first
#define S second

const int INF = 1000000010;
int n, m;
vector<pii> pts[100010];

vector<ll> lis(vector<int> v, vector<int> w){
  vector<ll> ret;
  set<pil> st;
  st.insert({INF, 0});
  forn(i, v.size()){
    auto itr = st.upper_bound({v[i], 1000000000000000000});
    ll cost = itr->S + w[i];
    auto ins = st.insert({v[i], cost}).F;

    while(true){
      auto nxt = next(ins);
      if(nxt == st.end() || nxt->S < ins->S) break;
      st.erase(nxt);
    }
    while(true){
      if(ins == st.begin()) break;
      auto pr = prev(ins);
      if(pr->S > ins->S) break;
      st.erase(pr);
    }
    ret.PB(st.begin()->S);
  }
  return ret;
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
  n=N, m=M;
  forn(i, m) pts[X[i]].PB({Y[i], W[i]});
  forn(i, n) sort(pts[i].begin(), pts[i].end(), greater<pii>());

  ll total = 0;
  int l=0;
  while(l<n){
    if(pts[l].empty()){
      l++;
      continue;
    }
    ll ans=0;
    int r = l+1;
    while(r<n && !pts[r].empty()) ++r;

    int len = r - l;
    vector<int> v1, v2, w1, w2, d1, d2;
    vector<ll> r1, r2;
    forsn(i, l, r){
      for(pii el:pts[i]) v1.PB(el.F), w1.PB(el.S);
      d1.PB((int)v1.size() - 1);
    }
    dforsn(i, l, r){
      for(pii el:pts[i]) v2.PB(el.F), w2.PB(el.S);
      d2.PB((int)v2.size() - 1);
    }
    r1 = lis(v1, w1), r2 = lis(v2, w2);
    
    if(l!=0 && r!=n){
      forn(i, len - 1) ans=max(ans, r1[d1[i]] + r2[d2[len-2-i]]);
    }
    if(l!=0) ans=max(ans, r1.back());
    if(r!=n) ans=max(ans, r2.back());
    total+=ans;
    l=r;
  }
  
  return total;
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 14328 KB Output is correct
2 Correct 76 ms 16872 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 208 ms 22036 KB Output is correct
6 Correct 148 ms 13988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 117 ms 21424 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40603931117751'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 26 ms 5596 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '5626961658160'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '4044', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '4044', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '4044', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 26 ms 5596 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '5626961658160'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 14328 KB Output is correct
2 Correct 76 ms 16872 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 208 ms 22036 KB Output is correct
6 Correct 148 ms 13988 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Incorrect 117 ms 21424 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40603931117751'
9 Halted 0 ms 0 KB -