View difference between Paste ID: CsrQbKc5 and JxSnbsL7
SHOW: | | - or go back to the newest paste.
1-
#include <bits/stdc++.h>
1+
#include <bits/stdc++.h>
2-
///for ordered set///
2+
///for ordered set///
3-
// #include <ext/pb_ds/assoc_container.hpp>
3+
// #include <ext/pb_ds/assoc_container.hpp>
4-
// #include <ext/pb_ds/trie_policy.hpp>
4+
// #include <ext/pb_ds/trie_policy.hpp>
5
6-
using namespace std;
6+
using namespace std;
7-
///For ordered set///
7+
///For ordered set///
8-
// using namespace __gnu_pbds;
8+
// using namespace __gnu_pbds;
9-
///For ordered set///
9+
///For ordered set///
10-
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
10+
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
11
12-
///Compiler Optimizer///
12+
///Compiler Optimizer///
13-
// #pragma GCC optimize("Ofast,no-stack-protector")
13+
// #pragma GCC optimize("Ofast,no-stack-protector")
14-
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
14+
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
15-
// #pragma GCC optimize("unroll-loops")
15+
// #pragma GCC optimize("unroll-loops")
16
17-
///define///
17+
///define///
18-
#define ll          long long int
18+
#define ll          long long int
19-
#define all(v)      v.begin(),v.end()
19+
#define all(v)      v.begin(),v.end()
20-
#define rall(v)     v.rbegin(),v.rend()
20+
#define rall(v)     v.rbegin(),v.rend()
21-
#define unq(s)      sort(all(s)),(s).erase(unique(all(s)),s.end())
21+
#define unq(s)      sort(all(s)),(s).erase(unique(all(s)),s.end())
22-
#define pb          push_back
22+
#define pb          push_back
23-
#define pob         pop_back
23+
#define pob         pop_back
24-
#define MP          make_pair
24+
#define MP          make_pair
25-
#define ff          first
25+
#define ff          first
26-
#define ss          second
26+
#define ss          second
27-
#define Log(b,x)    (log(x)/log(b))
27+
#define Log(b,x)    (log(x)/log(b))
28-
#define clr(a,x)    memset(a,x,sizeof(a))
28+
#define clr(a,x)    memset(a,x,sizeof(a))
29-
#define vout(v,sz)  for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
29+
#define vout(v,sz)  for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
30-
///IO///
30+
///IO///
31-
#define sc          scanf
31+
#define sc          scanf
32-
#define pf          printf
32+
#define pf          printf
33-
#define cspf(i)     pf("Case #%d: ", i)
33+
#define cspf(i)     pf("Case #%d: ", i)
34-
#define spc         pf(" ")
34+
#define spc         pf(" ")
35-
#define line        pf("\n")
35+
#define line        pf("\n")
36-
#define sc1(x)      sc("%d", &x)
36+
#define sc1(x)      sc("%d", &x)
37-
#define sc2(x,y)    sc("%d %d", &x, &y)
37+
#define sc2(x,y)    sc("%d %d", &x, &y)
38-
#define scl1(x)     sc("%lld", &x)
38+
#define scl1(x)     sc("%lld", &x)
39-
#define pf1(x)      pf("%d",x)
39+
#define pf1(x)      pf("%d",x)
40-
#define pfl1(x)     pf("%lld",x)
40+
#define pfl1(x)     pf("%lld",x)
41-
#define fastIO      ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
41+
#define fastIO      ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
42-
///constants///
42+
///constants///
43-
#define MOD         (int)(998244353)
43+
#define MOD         (int)(998244353)
44-
#define MaxN        100000
44+
#define MaxN        100000
45-
#define inf         0x3f3f3f3f
45+
#define inf         0x3f3f3f3f
46-
#define PI          acos(-1.0)  // 3.1415926535897932
46+
#define PI          acos(-1.0)  // 3.1415926535897932
47-
#define eps         1e-6
47+
#define eps         1e-6
48
49-
#ifdef ERFANUL007
49+
#ifdef ERFANUL007
50-
    #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
50+
    #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
51-
    template < typename Arg1 >
51+
    template < typename Arg1 >
52-
    void __f(const char* name, Arg1&& arg1){
52+
    void __f(const char* name, Arg1&& arg1){
53-
        cout << name << " = " << arg1 << std::endl;
53+
        cout << name << " = " << arg1 << std::endl;
54-
    }
54+
    }
55-
    template < typename Arg1, typename... Args>
55+
    template < typename Arg1, typename... Args>
56-
    void __f(const char* names, Arg1&& arg1, Args&&... args){
56+
    void __f(const char* names, Arg1&& arg1, Args&&... args){
57-
        const char* comma = strchr(names, ',');
57+
        const char* comma = strchr(names, ',');
58-
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
58+
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
59-
        __f(comma+1, args...);
59+
        __f(comma+1, args...);
60-
    }
60+
    }
61-
#else
61+
#else
62-
    #define debug(...)
62+
    #define debug(...)
63-
#endif
63+
#endif
64
65-
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;}
65+
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;}
66-
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
66+
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
67-
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
67+
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
68-
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
68+
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
69
70-
int dx[] = { 1,-1, 0, 0};                //graph moves
70+
int dx[] = { 1,-1, 0, 0};                //graph moves
71-
int dy[] = { 0, 0, 1,-1};               //graph moves
71+
int dy[] = { 0, 0, 1,-1};               //graph moves
72
73-
 
73+
 
74-
int main()
74+
int main()
75-
{
75+
{
76-
    #ifdef ERFANUL007
76+
    #ifdef ERFANUL007
77-
        clock_t tStart = clock();
77+
        clock_t tStart = clock();
78-
        freopen("input.txt", "r", stdin);
78+
        freopen("input.txt", "r", stdin);
79-
        freopen("output.txt", "w", stdout);
79+
        freopen("output.txt", "w", stdout);
80-
    #endif
80+
    #endif
81
82-
    int n; sc1(n);
82+
    int n; sc1(n);
83-
    int grid[n+1][n+1], sum[n+1][n+1];
83+
    int grid[n+1][n+1], sum[n+1][n+1];
84-
    for(int i=0; i<=n; i++){
84+
    for(int i=0; i<=n; i++){
85-
        sum[i][0] = 0;
85+
        sum[i][0] = 0;
86-
        sum[0][i] = 0;
86+
        sum[0][i] = 0;
87-
    }
87+
    }
88-
    for(int i=1; i<=n; i++){
88+
    for(int i=1; i<=n; i++){
89-
        for(int j=1; j<=n; j++){
89+
        for(int j=1; j<=n; j++){
90-
            sc1(grid[i][j]);
90+
            sc1(grid[i][j]);
91-
        }
91+
        }
92-
    }
92+
    }
93-
    for(int i=1; i<=n; i++){
93+
    for(int i=1; i<=n; i++){
94-
        for(int j=1; j<=n; j++){
94+
        for(int j=1; j<=n; j++){
95-
            sum[i][j] = sum[i-1][j] + sum[i][j-1] + grid[i][j] - sum[i-1][j-1];
95+
            sum[i][j] = sum[i-1][j] + sum[i][j-1] + grid[i][j] - sum[i-1][j-1];
96-
        }
96+
        }
97-
    }
97+
    }
98-
    int ans = 0;
98+
    int ans = 0;
99-
    for(int i=1; i<=n; i++){
99+
    for(int i=1; i<=n; i++){
100-
        for(int j=1; j<=n; j++){
100+
        for(int j=1; j<=n; j++){
101-
            for(int k=i; k<=n; k++){
101+
            for(int k=i; k<=n; k++){
102-
                for(int l=j; l<=n; l++){
102+
                for(int l=j; l<=n; l++){
103-
                    int val = sum[k][l] - sum[k][j-1] - sum[i-1][l] + sum[i-1][j-1];
103+
                    int val = sum[k][l] - sum[k][j-1] - sum[i-1][l] + sum[i-1][j-1];
104-
                    ans = max(ans, val);
104+
                    ans = max(ans, val);
105-
                }
105+
                }
106-
            }
106+
            }
107-
        }
107+
        }
108-
    }
108+
    }
109-
    printf("%d\n", ans);
109+
    printf("%d\n", ans);
110-
    
110+
    
111
112-
    #ifdef ERFANUL007
112+
    #ifdef ERFANUL007
113-
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
113+
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
114-
    #endif
114+
    #endif
115-
 
115+
 
116-
    return 0;
116+
    return 0;
117-
}
117+
}
118