답안 #92088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92088 2019-01-01T12:52:54 Z kjain_1810 Kas (COCI17_kas) C++17
100 / 100
256 ms 99276 KB
#include <algorithm>
#include <cstdio>
#include <cstring>
 
using namespace std;
 
const int MAXN = 505;
const int MAXS = 100010; 
const int INF  = 1e9;
 
int n, sum, sol;
int c[MAXN], memo[MAXN][MAXS/2];
 
int rek(int pos, int diff) {
 
  if (diff > sum / 2) 
    return -INF;
 
  int& memo_ref = memo[pos][diff];
 
  if (memo_ref != -1)
    return memo_ref;
 
  if (pos == n)
    return memo_ref = (diff != 0) * (-INF);
 
  return memo_ref = max(rek(pos + 1, diff), 
                    max(rek(pos + 1, diff + c[pos]) + c[pos], 
                        rek(pos + 1, abs(diff - c[pos])) + max(0, c[pos] - diff)));
 
}
 
int main(void) {
 
  memset(memo, -1, sizeof memo);
 
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &c[i]);
    sum += c[i];
  }
 
  sol = rek(0, 0);
  sol += sum - 2 * sol;
 
  printf("%d\n", sol);
 
  return 0;
 
}

Compilation message

kas.cpp: In function 'int main()':
kas.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
kas.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &c[i]);
     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 99064 KB Output is correct
2 Correct 70 ms 99276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 99148 KB Output is correct
2 Correct 77 ms 99168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 99064 KB Output is correct
2 Correct 73 ms 99192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 99172 KB Output is correct
2 Correct 67 ms 99164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 99064 KB Output is correct
2 Correct 67 ms 99168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 99172 KB Output is correct
2 Correct 79 ms 99064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 99124 KB Output is correct
2 Correct 71 ms 99192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 99236 KB Output is correct
2 Correct 93 ms 99196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 99228 KB Output is correct
2 Correct 184 ms 99236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 99136 KB Output is correct
2 Correct 249 ms 99204 KB Output is correct