Submission #66997

# Submission time Handle Problem Language Result Execution time Memory
66997 2018-08-13T07:46:03 Z yusufake Maxcomp (info1cup18_maxcomp) C++
100 / 100
330 ms 8560 KB
#include<bits/stdc++.h>
using namespace std;

#define _   int v, int tl, int tr, int l, int r, pp x
#define tm  (tl + tr >> 1)
#define sol v,tl,tm,l,r,x
#define sag v,tm+1,tr,l,r,x

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < int , int > pp;
typedef vector < int > vi;

const int mod = 1e9 + 7;
const int N   = 1e3 + 3;

ll F[N],A[N][N],n,m,i,j,t,ans;

void up(int x, ll t){
    for(; x <= n ; x += x&-x) 
        F[x] = min(F[x] , t);
}
ll qry(int x){
    ll t=1LL<<55;
    for(; x ; x -= x&-x)
        t = min(t , F[x]);
    return t;
}

int main(){
    scanf("%lld%lld",&m,&n);
    memset(F , 127 , sizeof F);
    for(i=1;i<=m;i++)
        for(j=1;j<=n;j++){
            scanf("%lld",&A[i][j]);
            t = A[i][j] - i - j;
            up(j,t);
            ans = max(ans , t-qry(j));
         //   cout << i << " " << j << " " << t << " " << ans << " aa\n";
        }    
    //cout << F[n+1]; return 0;
    memset(F , 127 , sizeof F);
    for(i=1;i<=m;i++)
        for(j=n; j ;j--){
            t = A[i][j] - i + j;
            up(n-j+1,t);
            ans = max(ans , t-qry(n-j+1));
        }    
    memset(F , 127 , sizeof F);
    for(i=m; i ;i--)
        for(j=1;j<=n;j++){
            t = A[i][j] + i - j;
            up(j,t);
            ans = max(ans , t-qry(j));
        }    
    memset(F , 127 , sizeof F);
    for(i=m; i ;i--)
        for(j=n; j ;j--){
            t = A[i][j] + i + j;
            up(n-j+1,t);
            ans = max(ans , t-qry(n-j+1));
        }    
    
    printf("%lld",ans-1);    
  return 0;
}

Compilation message

maxcomp.cpp: In function 'int main()':
maxcomp.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&m,&n);
     ~~~~~^~~~~~~~~~~~~~~~~~
maxcomp.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&A[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 3 ms 704 KB Output is correct
10 Correct 4 ms 704 KB Output is correct
11 Correct 4 ms 704 KB Output is correct
12 Correct 4 ms 704 KB Output is correct
13 Correct 4 ms 704 KB Output is correct
14 Correct 3 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 3 ms 644 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 3 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 644 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 4 ms 704 KB Output is correct
14 Correct 4 ms 704 KB Output is correct
15 Correct 4 ms 704 KB Output is correct
16 Correct 4 ms 704 KB Output is correct
17 Correct 3 ms 704 KB Output is correct
18 Correct 285 ms 8436 KB Output is correct
19 Correct 286 ms 8436 KB Output is correct
20 Correct 274 ms 8520 KB Output is correct
21 Correct 251 ms 8520 KB Output is correct
22 Correct 276 ms 8520 KB Output is correct
23 Correct 330 ms 8560 KB Output is correct
24 Correct 242 ms 8560 KB Output is correct