답안 #240912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240912 2020-06-21T12:49:22 Z SamAnd Kas (COCI17_kas) C++17
100 / 100
295 ms 196472 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 502, M = 100005, INF = 1000000009;

int n;
int a[N];

int dp[N][M];

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n + 1; ++i)
    {
        for (int j = 0; j < M; ++j)
        {
            dp[i][j] = -INF;
        }
    }
    dp[n + 1][0] = 0;
    for (int i = n; i >= 1; --i)
    {
        for (int j = 0; j < M; ++j)
        {
            dp[i][j] = max(dp[i][j], dp[i + 1][j]);
            if (j + a[i] < M)
                dp[i][j] = max(dp[i][j], dp[i + 1][j + a[i]] + a[i]);
            if (abs(j - a[i]) < M)
                dp[i][j] = max(dp[i][j], dp[i + 1][abs(j - a[i])] + a[i]);
        }
    }
    int ans = dp[1][0] / 2;
    int s = 0;
    for (int i = 1; i <= n; ++i)
        s += a[i];
    printf("%d\n", ans + s - ans * 2);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

kas.cpp: In function 'void solv()':
kas.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
kas.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4608 KB Output is correct
2 Correct 11 ms 4736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4736 KB Output is correct
2 Correct 11 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4608 KB Output is correct
2 Correct 11 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5504 KB Output is correct
2 Correct 14 ms 5760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5888 KB Output is correct
2 Correct 14 ms 5760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 14388 KB Output is correct
2 Correct 27 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 18304 KB Output is correct
2 Correct 48 ms 20344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 78968 KB Output is correct
2 Correct 151 ms 98712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 118240 KB Output is correct
2 Correct 228 ms 157368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 176888 KB Output is correct
2 Correct 295 ms 196472 KB Output is correct