제출 #538642

#제출 시각아이디문제언어결과실행 시간메모리
538642ddy888Cloud Computing (CEOI18_clo)C++17
100 / 100
490 ms1284 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) struct event { int c, f, v, flag; } items[5010]; const int INF = 1e18, lim = 100010; int N, M, st, ans = 0; int dp[100010]; signed main() { cin >> N; for (int i = 1; i <= N; ++i) { cin >> items[i].c >> items[i].f >> items[i].v; items[i].flag = 1; } cin >> M; for (int i = N + 1; i <= N + M; ++i) { cin >> items[i].c >> items[i].f >> items[i].v; items[i].flag = 0; } sort(items + 1, items + 1 + N + M, [](event a, event b) { if (a.f == b.f) return a.flag > b.flag; return a.f > b.f; }); for (int i = 0; i <= lim; ++i) dp[i] = -INF; dp[0] = 0; for (int i = 1; i <= N + M; ++i) { if (items[i].flag) { for (int j = lim - 1; j >= 0; --j) { int index = j + items[i].c; int profit = dp[j] - items[i].v; if (index < lim) dp[index] = max(dp[index], profit); } } else { for (int j = 0; j < lim; ++j) { int index = j - items[i].c; int profit = dp[j] + items[i].v; if (index >= 0 && dp[j] != -INF) dp[index] = max(dp[index], profit); } } } // push dp for (int i = 0; i < lim; ++i) ans = max(ans, dp[i]); cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'int main()':
clo.cpp:40:42: warning: iteration 100010 invokes undefined behavior [-Waggressive-loop-optimizations]
   40 |     for (int i = 0; i <= lim; ++i) dp[i] = -INF;
      |                                    ~~~~~~^~~~~~
clo.cpp:40:23: note: within this loop
   40 |     for (int i = 0; i <= lim; ++i) dp[i] = -INF;
      |                     ~~^~~~~~
#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...