Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- ///for ordered set///
- // #include <ext/pb_ds/assoc_container.hpp>
- // #include <ext/pb_ds/trie_policy.hpp>
- using namespace std;
- ///For ordered set///
- // using namespace __gnu_pbds;
- ///For ordered set///
- // typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
- ///Compiler Optimizer///
- // #pragma GCC optimize("Ofast,no-stack-protector")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- // #pragma GCC optimize("unroll-loops")
- ///define///
- #define ll long long int
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define unq(s) sort(all(s)),(s).erase(unique(all(s)),s.end())
- #define pb push_back
- #define pob pop_back
- #define MP make_pair
- #define ff first
- #define ss second
- #define Log(b,x) (log(x)/log(b))
- #define clr(a,x) memset(a,x,sizeof(a))
- #define vout(v,sz) for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
- ///IO///
- #define sc scanf
- #define pf printf
- #define cspf(i) pf("Case #%d: ", i)
- #define spc pf(" ")
- #define line pf("\n")
- #define sc1(x) sc("%d", &x)
- #define sc2(x,y) sc("%d %d", &x, &y)
- #define scl1(x) sc("%lld", &x)
- #define pf1(x) pf("%d",x)
- #define pfl1(x) pf("%lld",x)
- #define fastIO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
- ///constants///
- #define MOD (int)(998244353)
- #define MaxN 100000
- #define inf 0x3f3f3f3f
- #define PI acos(-1.0) // 3.1415926535897932
- #define eps 1e-6
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
- template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
- template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
- template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
- int dx[] = { 1,-1, 0, 0}; //graph moves
- int dy[] = { 0, 0, 1,-1}; //graph moves
- int main()
- {
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n; sc1(n);
- int grid[n+1][n+1], sum[n+1][n+1];
- for(int i=0; i<=n; i++){
- sum[i][0] = 0;
- sum[0][i] = 0;
- }
- for(int i=1; i<=n; i++){
- for(int j=1; j<=n; j++){
- sc1(grid[i][j]);
- }
- }
- for(int i=1; i<=n; i++){
- for(int j=1; j<=n; j++){
- sum[i][j] = sum[i-1][j] + sum[i][j-1] + grid[i][j] - sum[i-1][j-1];
- }
- }
- int ans = 0;
- for(int i=1; i<=n; i++){
- for(int j=1; j<=n; j++){
- for(int k=i; k<=n; k++){
- for(int l=j; l<=n; l++){
- int val = sum[k][l] - sum[k][j-1] - sum[i-1][l] + sum[i-1][j-1];
- ans = max(ans, val);
- }
- }
- }
- }
- printf("%d\n", ans);
- #ifdef ERFANUL007
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement