답안 #857122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857122 2023-10-05T11:58:32 Z hariaakas646 Kas (COCI17_kas) C++17
70 / 100
176 ms 197608 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int main() {
    // usaco();
    int n;
    scd(n);
    vi vec(n+1);
    int tot = 0;
    forr(i, 1, n+1) {
        scd(vec[i]);
        tot += vec[i];
    }
    vector<vi> dp(n+1, vi(1e5+1, -1e9));

    dp[0][0] = 0;
    forr(i, 1, n+1) {
        frange(j, 1e5+1) {
            dp[i][j] = dp[i-1][j];
            if(j - vec[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i-1][j-vec[i]] + vec[i]);
            }
            if(j + vec[i] <= 1e5) {
                dp[i][j] = max(dp[i][j], dp[i-1][j+vec[i]] + vec[i]);
            }
        }
    }

    int ma = dp[n][0];
    printf("%d", ma / 2 + (tot - ma));
}

Compilation message

kas.cpp: In function 'void usaco()':
kas.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kas.cpp: In function 'int main()':
kas.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
kas.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
kas.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
kas.cpp:41:9: note: in expansion of macro 'scd'
   41 |         scd(vec[i]);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4956 KB Output is correct
2 Incorrect 4 ms 5040 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4956 KB Output is correct
2 Incorrect 4 ms 5300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5724 KB Output is correct
2 Correct 5 ms 6236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6236 KB Output is correct
2 Correct 5 ms 6236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14936 KB Output is correct
2 Correct 15 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 18776 KB Output is correct
2 Correct 17 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 79708 KB Output is correct
2 Correct 85 ms 99388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 118788 KB Output is correct
2 Correct 135 ms 158292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 177912 KB Output is correct
2 Correct 176 ms 197608 KB Output is correct