제출 #1219608

#제출 시각아이디문제언어결과실행 시간메모리
1219608AishaT-Covering (eJOI19_covering)C++20
10 / 100
12 ms1348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, m; cin >> n >> m; vector <vector <int>> a(n + 1, vector <int> (m + 1)); for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { cin >> a[i][j]; } } int k; cin >> k; vector <int> r(n + 1), c(m + 1); int j = 0; for (int i = 0; i < k; i ++) { int x, y; cin >> x >> y; j = x + 1; r[x + 1] = 1; c[y + 1] = 1; } vector <int> dp(m + 1); for (int i = 1; i <= m; i ++) { if (c[i] == 0) { dp[i] = max(dp[i], dp[i - 1]); continue; } bool ok = false; if (i + 1 <= m) { int s = 0; if (j - 1 > 0 && j + 1 <= n) { s = a[j][i] + a[j][i + 1] + a[j - 1][i] + a[j + 1][i]; } //cout << s << endl; //cout << dp[i + 1] << endl; dp[i + 1] = max(dp[i + 1], s + dp[i - 1]); ok = true; } if (i - 1 > 0) { int s = 0; if (j - 1 > 0 && j + 1 <= n) { s = a[j][i] + a[j][i - 1] + a[j - 1][i] + a[j + 1][i]; } dp[i] = max(dp[i], s + dp[i - 2]); ok = true; } if (i + 1 <= m && i - 1 > 0) { int s1 = 0, s2 = 0; if (j - 1 > 0) { s1 = a[j][i] + a[j][i - 1] + a[j - 1][i] + a[j][i + 1]; } if (j + 1 <= n) { s2 = a[j][i] + a[j][i - 1] + a[j + 1][i] + a[j][i + 1]; } dp[i + 1] = max(dp[i + 1], dp[i - 2] + max(s1, s2)); ok = true; } if (!ok) { cout << "No" << endl; return 0; } } // for (int i = 1; i <= m; i ++) cout << dp[i] << endl; cout << dp[m] << endl; return 0; }
#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...