Submission #1154294

#TimeUsernameProblemLanguageResultExecution timeMemory
1154294AgentPenginMaja (COCI18_maja)C++20
110 / 110
97 ms784 KiB
/** * author: AgentPengin ( Độc cô cầu bại ) * created: 23.12.2022 10:08:02 * too lazy to update time **/ #include<bits/stdc++.h> #define EL '\n' #define fi first #define se second #define NAME "TASK" #define ll long long #define lcm(a,b) (a/gcd(a,b))*b #define db(val) "["#val" = " << (val) << "] " #define bend(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define ex exit(0) #define int ll using namespace std; const ll mod = 1e9 + 7; const int inf = 0x1FFFFFFF; const int MAXN = 105; int n, m, a, b, k; int mat[MAXN][MAXN], pp[MAXN][MAXN]; int dp[2][MAXN][MAXN]; signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (ifstream(NAME".inp")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin >> n >> m >> a >> b >> k; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) cin >> mat[i][j]; } for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { pp[i][j] = max({mat[i - 1][j], mat[i][j - 1], mat[i + 1][j], mat[i][j + 1]}) + mat[i][j]; } } memset(dp, -0x3f, sizeof dp); dp[0][a][b] = 0; int ans = 0; for (int p = 1;p <= min(k / 2, n * m);p++) { int cur = p & 1; int lst = cur ^ 1; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { dp[cur][i][j] = max({dp[lst][i][j - 1], dp[lst][i - 1][j], dp[lst][i + 1][j], dp[lst][i][j + 1]}) + mat[i][j]; ans = max(ans, dp[cur][i][j] * 2 - mat[i][j] + pp[i][j] * ((k - p * 2) / 2)); } } } cout << ans; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } // agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

maja.cpp: In function 'int main()':
maja.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
maja.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(NAME".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...
#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...