답안 #867444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867444 2023-10-28T11:53:34 Z JoksimKaktus 수열 (APIO14_sequence) C++17
0 / 100
7 ms 2140 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n;
    long double k;
    cin >> n >> k;
    vector <ll> pre(n+1);
    pre[0]=0;
    vector <int> v(n+1);
    for(int i = 1;i <= n;i++){
        cin >> v[i];
        pre[i] = pre[i-1]+v[i];
    }
    long double limit = (pre[n]/(k+1));
    ll cur = 0;
    long double dif = 0;
    int l = 0;
    ll res = 0;
    vector <int> ind;
    for(int i = 1;i <=n && ind.size() < k;i++){
        if(cur == 0){
            cur += v[i];
            continue;
        }
        if(cur + v[i] >= limit){
            if(abs((cur + v[i])-limit) == abs(cur-limit)){
                if(dif > 0){
                    res += (pre[i-1] - pre[l])*(pre[n] - pre[i-1]);
                    l = i-1;
                    dif += cur - limit;
                    cur = v[i];
                    ind.push_back(i-1);
                }else{
                    res += (pre[i] - pre[l])*(pre[n] - pre[i]);
                    l = i;
                    dif += (cur + v[i])-limit;
                    cur = 0;
                    ind.push_back(i);
                }
            }else if(abs((cur + v[i])-limit) > abs(cur-limit)){
                res += (pre[i-1] - pre[l])*(pre[n] - pre[i-1]);
                l = i-1;
                dif += cur - limit;
                cur = v[i];
                ind.push_back(i-1);
            }else{
                res += (pre[i] - pre[l])*(pre[n] - pre[i]);
                l = i;
                dif += (cur + v[i])-limit;
                cur = 0;
                ind.push_back(i);
            }
        }else{
            cur += v[i];
        }
    }
    cout << res << "\n";
    for(int i : ind){
        cout << i << " ";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB contestant found the optimal answer: 108 == 108
2 Correct 0 ms 344 KB contestant found the optimal answer: 999 == 999
3 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 0 ms 344 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 1 ms 348 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 348 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB contestant didn't find the optimal answer: 1788154876 < 1818678304
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1664 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 6 ms 1628 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Incorrect 7 ms 2140 KB contestant didn't find the optimal answer: 497312974087253978 < 497313449256899208
4 Halted 0 ms 0 KB -