Submission #833592

# Submission time Handle Problem Language Result Execution time Memory
833592 2023-08-22T07:02:23 Z ALeonidou Catfish Farm (IOI22_fish) C++17
0 / 100
87 ms 29968 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;
#define ll int
#define sz(x) (ll)x.size()
#define F first
#define S second
#define pb push_back
#define MID ((l+r)/2)
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;

typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;

void printVct(vi &v, string s = ""){
    cout<<s<<": ";
    for (ll i=0; i<sz(v); i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}

void kadane(vi &v, ll &x, ll &y){
    long long sum = 0, ans = 0;
    ll cur_x = 0;
    for (ll i =0;i<sz(v); i++){
        sum += v[i];
        if (sum < 0){
            sum = 0;
            cur_x = i+1;
        }
        if (sum > ans){
            ans = sum;
            x = cur_x;
            y = i;
        }
    }
}

ll n,m;
long long max_weights(int N, int M, vi X, vi Y, vi W) {
    n= N, m =M;
    long long ans = 0;
    
    //subtask 2
    if (n == 2){
        long long a = 0,b = 0;
        for (ll i= 0;i<m; i++){
            if (X[i] == 0) a += W[i];
            else b+= W[i];
        }
        ans = max(a,b);
    }
    else{
        vector <vi> arr(n, vi(2,0));
        for (ll i =0; i<m; i++){
            arr[Y[i]][X[i]] = W[i];
        }
        vi v(n);
        for (ll i =0; i<n; i++){
            ll dif = arr[i][0] - arr[i][1];
            v[i] = dif;
        }
        ll x =0, y =0;
        // printVct(v,"v");
        kadane(v, x, y);
        // dbg3(x,y,ans);
        for (ll i =0; i<x; i++) ans += arr[i][1];
        for (ll i=x; i<=y; i++) ans += arr[i][0];
        for (ll i=y+1; i<n; i++) ans += arr[i][1];
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8776 KB Output is correct
2 Correct 29 ms 10244 KB Output is correct
3 Correct 5 ms 6100 KB Output is correct
4 Correct 8 ms 6060 KB Output is correct
5 Runtime error 87 ms 29968 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 43 ms 12164 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40665029450929'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6060 KB Output is correct
2 Runtime error 9 ms 11496 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6060 KB Output is correct
2 Runtime error 9 ms 11496 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8776 KB Output is correct
2 Correct 29 ms 10244 KB Output is correct
3 Correct 5 ms 6100 KB Output is correct
4 Correct 8 ms 6060 KB Output is correct
5 Runtime error 87 ms 29968 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -