제출 #1136020

#제출 시각아이디문제언어결과실행 시간메모리
1136020banh@@notpro33Džumbus (COCI19_dzumbus)C++20
50 / 110
36 ms33096 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define fi first #define se second #define pii pair<int, int> #define pb push_back #define eb emplace_back #define task "file" const int nmax = 1005; int dp[nmax][nmax][2][2], sz[nmax], d[nmax], vis[nmax], n, m; int res[nmax]; vector<int> adj[nmax]; void dfs(int u, int p = -1) { vis[u] = 1; sz[u] = 1; dp[u][0][0][0] = 0; dp[u][1][1][0] = d[u]; for (int v : adj[u]) { if (v == p) continue; dfs(v, u); for (int i = sz[u]; i >= 0; i--) { for (int j = 0; j <= sz[v]; j++) { dp[u][i + j][0][0] = min(dp[u][i + j][0][0], dp[u][i][0][0] + dp[v][j][1][1]); dp[u][i + j][0][0] = min(dp[u][i + j][0][0], dp[u][i][0][0] + dp[v][j][0][0]); dp[u][i + j][1][0] = min(dp[u][i + j][1][0], dp[u][i][1][0] + dp[v][j][0][0]); dp[u][i + j][1][1] = min(dp[u][i + j][1][1], dp[u][i][1][0] + dp[v][j][1][0]); dp[u][i + j][1][1] = min(dp[u][i + j][1][1], dp[u][i][1][0] + dp[v][j][1][1]); dp[u][i + j][1][1] = min(dp[u][i + j][1][1], dp[u][i][1][1] + dp[v][j][1][1]); dp[u][i + j][1][1] = min(dp[u][i + j][1][1], dp[u][i][1][1] + dp[v][j][0][0]); dp[u][i + j][1][1] = min(dp[u][i + j][1][1], dp[u][i][1][1] + dp[v][j][1][0]); } } sz[u] += sz[v]; } } signed main() { if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> d[i]; } for (int u, v, i = 1; i <= m; i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } memset(dp, 0x3f3f3f3f3f, sizeof(dp)); for (int i = 1; i <= n; i++) { if (!vis[i]) { dfs(i); } } memset(res, 0x3f3f3f3f3f, sizeof(res)); for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { res[j] = min({res[j], dp[i][j][0][0], dp[i][j][1][1]}); } } for (int i = n - 1; i >= 0; i--) { res[i] = min(res[i], res[i + 1]); } int q; cin >> q; while (q--) { int x; cin >> x; int l = 2, r = n, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (res[mid] <= x) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans << '\n'; } return 0; }

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

dzumbus.cpp: In function 'int main()':
dzumbus.cpp:67:16: warning: overflow in conversion from 'long int' to 'int' changes value from '271644049215' to '1061109567' [-Woverflow]
   67 |     memset(dp, 0x3f3f3f3f3f, sizeof(dp));
      |                ^~~~~~~~~~~~
dzumbus.cpp:75:17: warning: overflow in conversion from 'long int' to 'int' changes value from '271644049215' to '1061109567' [-Woverflow]
   75 |     memset(res, 0x3f3f3f3f3f, sizeof(res));
      |                 ^~~~~~~~~~~~
dzumbus.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dzumbus.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...