Submission #1141596

#TimeUsernameProblemLanguageResultExecution timeMemory
1141596KasymKMaxcomp (info1cup18_maxcomp)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1e3+5; const ll INF = 1e18; const int INF_ = 1e9; int v[N][N], pn[N][N], px[N][N]; void reload(int n, int m){ for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) pn[i][j]=INF, px[i][j]=-INF; } void rev(int x, int m){ for(int i = 1; i <= m/2; ++i) swap(v[x][i], v[x][m-i+1]); } struct node { int mx, mn, sz; ll val; node(){ mx=-INF_, mn=INF_, sz=0; val=-INF; }; } dp[N][N]; int main(){ int n, m; scanf("%d%d", &n, &m); auto is=[&](int a, int b) -> bool { return (a>=1 and a<=n and b>=1 and b<=m); }; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) scanf("%d", &v[i][j]); ll answer=-INF; reload(n, m); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){ ll val=INF, val2=-INF; if(is(i-1, j)) umin(val, pn[i-1][j]), umax(val2, px[i-1][j]); if(is(i, j-1)) umin(val, pn[i][j-1]), umax(val2, px[i][j-1]); umax(answer, max(v[i][j]-val, val2-v[i][j])-i-j-1); pn[i][j]=min(val, (v[i][j]-i-j)*1ll), px[i][j]=max(val2, (v[i][j]+i+j)*1ll); } for(int i = 1; i <= n; ++i) rev(i, m); reload(n, m); for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){ ll val=INF, val2=-INF; if(is(i-1, j)) umin(val, pn[i-1][j]), umax(val2, px[i-1][j]); if(is(i, j-1)) umin(val, pn[i][j-1]), umax(val2, px[i][j-1]); umax(answer, max(v[i][j]-val, val2-v[i][j])-i-j-1); pn[i][j]=min(val, (v[i][j]-i-j)*1ll), px[i][j]=max(val2, (v[i][j]+i+j)*1ll); } for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){ // 1-> up if(is(i-1, j)){ if(umax(dp[i][j].val, (max(dp[i-1][j].mx, v[i][j])-min(dp[i-1][j].mn, v[i][j])-dp[i-1][j].sz-1)*1ll)) umax(dp[i][j].mx, max(dp[i-1][j].mx, v[i][j])), umin(dp[i][j].mn, min(dp[i-1][j].mn, v[i][j])), dp[i][j].sz=dp[i-1][j].sz+1; } // 2-> left if(is(i, j-1)){ if(umax(dp[i][j].val, (max(dp[i][j-1].mx, v[i][j])-min(dp[i][j-1].mn, v[i][j])-dp[i][j-1].sz-1)*1ll)) umax(dp[i][j].mx, max(dp[i][j-1].mx, v[i][j])), umin(dp[i][j].mn, min(dp[i][j-1].mn, v[i][j])), dp[i][j].sz=dp[i][j-1].sz+1; } // 3-> start new if(umax(dp[i][j].val, -1*1ll)) dp[i][j].mx=v[i][j], dp[i][j].mn=v[i][j], dp[i][j].sz=1; } for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) umax(answer, dp[i][j].val); printf("%lld\n", answer); return 0; }

Compilation message (stderr)

maxcomp.cpp: In function 'void reload(int, int)':
maxcomp.cpp:23:22: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   23 |             pn[i][j]=INF, px[i][j]=-INF;
      |                      ^~~
maxcomp.cpp:23:36: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow]
   23 |             pn[i][j]=INF, px[i][j]=-INF;
      |                                    ^~~~
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:55:21: error: no matching function for call to 'umin(long long int&, int&)'
   55 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:13:23: note: candidate: 'template<class T> bool umin(T&, T)'
   13 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:13:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:55:21: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   55 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:55:44: error: no matching function for call to 'umax(long long int&, int&)'
   55 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:14:23: note: candidate: 'template<class T> bool umax(T&, T)'
   14 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:14:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:55:44: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   55 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:57:21: error: no matching function for call to 'umin(long long int&, int&)'
   57 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:13:23: note: candidate: 'template<class T> bool umin(T&, T)'
   13 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:13:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:57:21: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   57 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:57:44: error: no matching function for call to 'umax(long long int&, int&)'
   57 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:14:23: note: candidate: 'template<class T> bool umax(T&, T)'
   14 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:14:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:57:44: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   57 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:68:21: error: no matching function for call to 'umin(long long int&, int&)'
   68 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:13:23: note: candidate: 'template<class T> bool umin(T&, T)'
   13 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:13:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:68:21: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   68 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:68:44: error: no matching function for call to 'umax(long long int&, int&)'
   68 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:14:23: note: candidate: 'template<class T> bool umax(T&, T)'
   14 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:14:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:68:44: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   68 |                 umin(val, pn[i-1][j]), umax(val2, px[i-1][j]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:70:21: error: no matching function for call to 'umin(long long int&, int&)'
   70 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:13:23: note: candidate: 'template<class T> bool umin(T&, T)'
   13 | template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:13:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:70:21: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   70 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                 ~~~~^~~~~~~~~~~~~~~~~
maxcomp.cpp:70:44: error: no matching function for call to 'umax(long long int&, int&)'
   70 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:14:23: note: candidate: 'template<class T> bool umax(T&, T)'
   14 | template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
      |                       ^~~~
maxcomp.cpp:14:23: note:   template argument deduction/substitution failed:
maxcomp.cpp:70:44: note:   deduced conflicting types for parameter 'T' ('long long int' and 'int')
   70 |                 umin(val, pn[i][j-1]), umax(val2, px[i][j-1]);
      |                                        ~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |             scanf("%d", &v[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~