답안 #6959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6959 2014-07-10T16:30:16 Z tncks0121 수열 (APIO14_sequence) C++
22 / 100
0 ms 84904 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <bits/stdc++.h>
#include <memory.h>
 
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef long double llf;
typedef unsigned int uint;
 
using namespace std;
 
const int N_ = 100500, K_ = 205;
int N, K, A[N_];
ll Table[2][N_], S[N_];
int opt[K_][N_];
 
void solve (int k, int i) {
    if(k == 1) return;
    solve(k - 1, opt[k][i] - 1);
    printf("%d ", opt[k][i] - 1);
}

ll *now, *prev;

void conq (int k, int l, int r, int optl, int optr) {
  int m = (l+r) >> 1;
  for(int j = optl; j <= optr; j++) {
    ll val = prev[j-1] + (S[m] - S[j-1]) * (S[N] - S[m]);
    if(val >= now[m]) now[m] = val, opt[k][m] = j;
  }
  if(l < r) {
  	conq (k, l, m-1, optl, opt[k][m]);
  	conq (k, m+1, r, opt[k][m], optr);
  }
}
 
int main() {
    scanf("%d%d", &N, &K);
    for(int i = 1; i <= N; i++) scanf("%d", A+i), S[i] = S[i-1] + A[i];
 
    for(int i = 1; i <= N; i++) Table[1][i] = S[i] * (S[N] - S[i]);
    for(int k = 2; k <= K+1; k++) {
        now = Table[k&1], prev = Table[~k&1];
        for(int i = 1; i <= N; i++) now[i] = -1, opt[k][i] = -1;
        conq(k, 1, N, k, N);
    }
 
    printf("%lld\n", Table[~K&1][N]);
    solve(K+1, N);
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 108 == 108
2 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 999 == 999
3 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 0 == 0
4 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1542524 == 1542524
5 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1 == 1
7 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1 == 1
8 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1 == 1
9 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 100400096 == 100400096
10 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 900320000 == 900320000
11 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 140072 == 140072
14 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 376041456 == 376041456
15 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 805 == 805
16 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 900189994 == 900189994
17 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 999919994 == 999919994
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1093956 == 1093956
2 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 302460000 == 302460000
3 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 933702 == 933702
7 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 687136 == 687136
9 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 29000419931 == 29000419931
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 610590000 == 610590000
2 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 311760000 == 311760000
3 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 0 ms 84904 KB Output is correct - contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 0 ms 84904 KB Output isn't correct - position 199 occurs twice in split scheme
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -