답안 #833610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833610 2023-08-22T07:07:28 Z ALeonidou 메기 농장 (IOI22_fish) C++17
0 / 100
81 ms 25692 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(vi &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;
    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){
        // 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 =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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7764 KB Output is correct
2 Correct 27 ms 8916 KB Output is correct
3 Correct 6 ms 6540 KB Output is correct
4 Correct 5 ms 6484 KB Output is correct
5 Runtime error 81 ms 25692 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 40 ms 9676 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40665029450929'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6484 KB Output is correct
2 Runtime error 10 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 7 ms 6484 KB Output is correct
2 Runtime error 10 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 8916 KB Output is correct
3 Correct 6 ms 6540 KB Output is correct
4 Correct 5 ms 6484 KB Output is correct
5 Runtime error 81 ms 25692 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -