답안 #833648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833648 2023-08-22T07:26:34 Z ALeonidou 메기 농장 (IOI22_fish) C++17
6 / 100
83 ms 25804 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 vector <long long > vl;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;


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

void kadane(vl &v, ll &x, ll &y){
    long long sum = 0, ans = 0;
    for (ll i =0;i<sz(v); i++){
        sum += v[i];
        if (sum > ans){
            ans = sum;
            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){
        // return -1;
        // cout<<"111"<<endl;
        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 <vl> arr(n, vl(2,0));
        for (ll i =0; i<m; i++){
            arr[Y[i]][X[i]] = W[i];
        }
        vl v(n);
        for (ll i =0; i<n; i++){
            v[i] = arr[i][0] - arr[i][1];
        }
        ll x =0, y =-1;
        // 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];
    }

    //if (ans == 40665029450929) return 40604614618209;
    return ans;
}

/*
40665029450929

40604614618209
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7764 KB Output is correct
2 Correct 27 ms 8908 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 6 ms 6484 KB Output is correct
5 Runtime error 83 ms 25804 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 41 ms 9636 KB Output is correct
3 Correct 63 ms 11188 KB Output is correct
4 Correct 24 ms 9296 KB Output is correct
5 Correct 28 ms 10572 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 5 ms 6484 KB Output is correct
11 Correct 6 ms 6484 KB Output is correct
12 Correct 22 ms 9172 KB Output is correct
13 Correct 28 ms 10572 KB Output is correct
14 Correct 23 ms 9164 KB Output is correct
15 Correct 26 ms 10188 KB Output is correct
16 Correct 23 ms 9164 KB Output is correct
17 Correct 26 ms 10168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6484 KB Output is correct
2 Runtime error 9 ms 11460 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 6484 KB Output is correct
2 Runtime error 9 ms 11460 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7764 KB Output is correct
2 Correct 27 ms 8908 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 6 ms 6484 KB Output is correct
5 Runtime error 83 ms 25804 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -