답안 #955349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955349 2024-03-30T07:53:05 Z Gray 메기 농장 (IOI22_fish) C++17
0 / 100
1000 ms 2097152 KB
// #include <bits/stdc++.h>

// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#define M_PI 3.14159265358979323846
#define ll long long
using ld = double;
#define ff first
#define ss second
#define ln "\n"
#define gcd(x,y) __gcd(x,y)
using namespace std;

// const ll MOD = 1e9+7;
const ll INF = 2e18;
// const ll MAXN = 1e6+1;

ll max_weights(int n, int m, vector<int> cx, vector<int> cy, vector<int> cw){
    n++;
    vector<pair<pair<ll, ll>, ll>> fish(m);
    for (ll i=0; i<m; i++){
        fish[i] = {{cx[i], cy[i]+1}, cw[i]};
    }
    sort(fish.begin(), fish.end(), [](auto op1, auto op2)->bool{
        return op1.ff.ss<op2.ff.ss;
    });
    vector<vector<ll>> A(n, vector<ll>(n));
    for (ll i=0; i<m; i++){
        A[fish[i].ff.ff][fish[i].ff.ss]=fish[i].ss;
    }
    vector<vector<ll>> pref(n, vector<ll>(n,0));
    for (ll i=0; i<n; i++){
        for (ll j=0; j<n; j++){
            pref[i][j] = (j==0?A[i][j]:pref[i][j-1]+A[i][j]);
        }
    }
    // return 0;
    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(n, 0)));
    for (ll i=1; i<n; i++){
        for (ll j=0; j<n; j++){
            for (ll k=0; k<n; k++){
                if (j>k){
                    dp[i][j][k] = max(dp[i-1][k][n-1], dp[i-1][k][k]+pref[i-1][j]-pref[i-1][k]);
                }else dp[i][j][k] = dp[i-1][k][n-1]+pref[i][k]-pref[i][j];
                if (k)dp[i][j][k]=max(dp[i][j][k-1], dp[i][j][k]);
            }
        }
    }
    ll mx = 0;
    // for (ll i=0; i<n; i++){
    //     cout << i << ": \n";
    //     for (ll j=0; j<n; j++){
    //         for (ll k=0; k<n; k++){
    //             cout << dp[i][j][k] << " ";
    //         }
    //         cout << ln;
    //     }
    // }
    for (ll i=0; i<n; i++){
        mx = max(mx, dp[n-1][i][n-1]);
    }
    return mx;
}

// int main(){
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  ll t=1;
//  cin >> t;
//  // while (t--) solve();
// }


// int main() {
//   int N, M;
//   assert(2 == scanf("%d %d", &N, &M));

//   std::vector<int> X(M), Y(M), W(M);
//   for (long long i = 0; i < M; ++i) {
//     assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
//   }

//   long long result = max_weights(N, M, X, Y, W);
//   printf("%lld\n", result);
//   return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1146 ms 1882184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Runtime error 791 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 963 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '6066'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 963 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1146 ms 1882184 KB Time limit exceeded
2 Halted 0 ms 0 KB -