답안 #1058959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058959 2024-08-14T15:22:17 Z underwaterkillerwhale 메기 농장 (IOI22_fish) C++17
0 / 100
1000 ms 743744 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e5 + 7;
const int Mod = 1e9 + 7;
const ll INF = 2e9 + 7;
const ll BASE = 137;
const int szBL = 320;

void inline maximize (ll &A, ll B) { if (A < B) A = B; }

struct Fish {
    int fs, se;
    ll W;
};

int n, m;
vector<int> pcur[N], Left[N], Right[N];
vector<ll> dp[N], fsuf[N], fpre[N];
vector<int> high[N];
Fish a[(int)3e5 + 7];
vector<pll> vec[N];
bool dd[N];

ll premx[N], sufmx[N];

void init (int j, int m) {
    pcur[j].resize(m + 2, 0);
    Left[j].resize(m + 2, 0);
    Right[j].resize(m + 2, 0);
    fpre[j].resize(m + 2, 0);
    fsuf[j].resize(m + 2, 0);
    dp[j].resize(m + 2, 0); ///sửa ik
}

//void solution () {
ll max_weights(int _n, int _m, vector<int> X, vector<int> Y, vector<int> W) {
//    cin >> n >> m;
//    n = 1e5;
//    m = min(1LL * n * n - Rand(1, n * n), (ll)3e5);
    n = _n;
    m = _m;
//    vector<pii> val;
//    rep (i, 1, n)
//    rep (j, 1, n) {
//        static int tme = 0;
//        ++tme;
//        if (tme >= m) break;
//        val.pb(MP(i, j));
//    }
//    random_shuffle(ALL(val));
    rep (j, 0, n) high[j] = {0};
    rep (i, 1, m) {
//        cin >> a[i].fs >> a[i].se >> a[i].W;
//        a[i].fs = val[i - 1].fs;
//        a[i].se = val[i - 1].se;
//        a[i].W = Rand(1, 100000);
        a[i].fs = X[i - 1];
        a[i].se = Y[i - 1];
        a[i].W = W[i - 1];
        ++a[i].fs;
        ++a[i].se;
        vec[a[i].fs].pb(MP(a[i].se, a[i].W));
        high[a[i].fs].pb(a[i].se);
    }
    init(0, 5);
    rep (j, 1, n) {
//        static vector<int> vec; vector<int> ().swap(vec);
        iter (&id, high[j + 1])
        high[j].pb(id);
        iter (&id, high[j - 1])
        high[j].pb(id);
        sort (ALL(high[j]));
        high[j].resize(unique(ALL(high[j])) - high[j].begin());
        int m = SZ(high[j]);
        init(j, m);
        iter (&id, vec[j]) pcur[j][lower_bound(ALL(high[j]), id.fs) - high[j].begin()] = id.se;
        rep (i, 1, m - 1){
            pcur[j][i] += pcur[j][i - 1];
        }
        rep (i, 1, m - 1) {
            int pos = lower_bound(ALL(high[j - 1]), high[j][i]) - high[j - 1].begin();
            Left[j][i] = pcur[j - 1][pos];
        }
    }
    rep (j, 1, n - 1) {
        int m = SZ(high[j]);
        rep (i, 1, m - 1) {
            int pos = lower_bound(ALL(high[j + 1]), high[j][i]) - high[j + 1].begin();
            Right[j][i] = pcur[j + 1][pos];
        }
    }
//    return;
    rep (j, 1, n) {
        int m = SZ(high[j]);
        vector<int> &ch = high[j];
        if (j >= 2) {
            rep (i, 1, m - 1) {
                int pos = upper_bound(ALL(high[j - 1]), ch[i]) - high[j - 1].begin();
                maximize(dp[j][i], fpre[j - 1][pos - 1] + Left[j][i]);
                maximize(dp[j][i], fsuf[j - 1][pos] - pcur[j][i]);
            }
            if (j == 2) {
                rep (i, 1, m - 1) maximize(dp[j][i], Left[j][i]);
            }
        }
        if (j >= 3) {
            rep (i, 1, m - 1) {
                maximize(dp[j][i], dp[j - 2][0] + Left[j][i]);
            }
        }
        fpre[j][0] = dp[j][0];
        rep (i, 1, m - 1) {
            fpre[j][i] = max(fpre[j][i - 1], dp[j][i] - pcur[j][i]);
        }
        reb (i, m - 1, 0) {
            fsuf[j][i] = max(fsuf[j][i + 1], dp[j][i] + Right[j][i]);
        }
//        rep (i, 1, m - 1) {
//            cout << j <<  " "<<high[j][i].fs <<" "<< dp[j][i] <<"\n";
//        }
    }
//    cout << *max_element(dp[n].begin(), dp[n].end()) <<"\n";
    return *max_element(dp[n].begin(), dp[n].end());
}

//#define file(name) freopen(name".inp","r",stdin); \
//freopen(name".out","w",stdout);
//int main () {
////    file("c");
////    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    int num_Test = 1;
////    cin >> num_Test;
//    while (num_Test--)
//        solution();
////        cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3});
//}
/*
no bug challenge +2
2 + 8 * 2 - 9
5 4
0 2 5
1 1 2
4 4 1
3 3 3

*/

Compilation message

fish.cpp:144:1: warning: multi-line comment [-Wcomment]
  144 | //#define file(name) freopen(name".inp","r",stdin); \
      | ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 741828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 19036 KB Output is correct
2 Execution timed out 1075 ms 743744 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 45664 KB Output is correct
2 Incorrect 33 ms 41052 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 7 ms 19036 KB Output is correct
3 Correct 6 ms 19036 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Incorrect 6 ms 19036 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 7 ms 19036 KB Output is correct
3 Correct 6 ms 19036 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Incorrect 6 ms 19036 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 19036 KB Output is correct
2 Correct 7 ms 19036 KB Output is correct
3 Correct 6 ms 19036 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Incorrect 6 ms 19036 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 45664 KB Output is correct
2 Incorrect 33 ms 41052 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 741828 KB Time limit exceeded
2 Halted 0 ms 0 KB -