Submission #736166

#TimeUsernameProblemLanguageResultExecution timeMemory
736166marvinthangKas (COCI17_kas)C++17
100 / 100
176 ms197956 KiB
/****************************** * author : @marvinthang * * date : 09 / 02 / 2022 * ******************************/ #include <bits/stdc++.h> using namespace std; #define superspeed ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } template <class U, class V> ostream & operator << (ostream& out, const pair<U, V> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template <class T> ostream & operator << (ostream &out, const vector<T> &vt) { out << '{'; for (size_t i = 0; i + 1 < vt.size(); i++) out << vt[i] << ", "; if (!vt.empty()) out << vt.back(); return out << '}'; } const int MOD = 1e9 + 7; const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0); const int dir[] = {0, 1, 0, -1, 0}; // {0, 1, 1, -1, -1, 1, 0, -1, 0}; const long long oo = 1e18; const int MAX = 1e5 + 5; inline void minimize(int &a, int b) { if (a > b) a = b; } int N, F[505][MAX], C[505]; int main(void) { file("coci1617_r4_kas"); scanf("%d", &N); int sumVal = 0; for (int i = 1; i <= N; ++i) scanf("%d", C + i), sumVal += C[i]; memset(F, 0x3f, sizeof(F)); F[0][0] = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= sumVal; ++j) { if (j + C[i] <= sumVal) minimize(F[i][j], F[i - 1][j + C[i]]); minimize(F[i][j], F[i - 1][abs(j - C[i])]); minimize(F[i][j], F[i - 1][j] + C[i]); } } cout << (sumVal - F[N][0]) / 2 + F[N][0]; return 0; }

Compilation message (stderr)

kas.cpp: In function 'int main()':
kas.cpp:11:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kas.cpp:27:5: note: in expansion of macro 'file'
   27 |     file("coci1617_r4_kas");
      |     ^~~~
kas.cpp:11:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kas.cpp:27:5: note: in expansion of macro 'file'
   27 |     file("coci1617_r4_kas");
      |     ^~~~
kas.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
kas.cpp:30:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     for (int i = 1; i <= N; ++i) scanf("%d", C + i), sumVal += C[i];
      |                                  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...