답안 #197084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197084 2020-01-18T14:33:03 Z Zhmyh Maxcomp (info1cup18_maxcomp) C++17
100 / 100
179 ms 17204 KB
#include <bits/stdc++.h>
#define FI(_n) for(int i = 0; i < _n; ++i)
#define FJ(_n) for(int j = 0; j < _n; ++j)
#define mp make_pair
#define pb push_back
#define endl '\n'

#ifdef LOCAL
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define LOCAL 0
    #define dbg(...)
#endif
#define cerr if (!LOCAL) {} else std::cerr

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;

int Get(vector<vector<int>> a)
{
    int n = a.size();
    int m = a.back().size();

    /// minimizing min - x - y
    int best = -1;
    FI(n)
    {
        FJ(m)
        {
            int mn = min(a[i][j] - i - j, min(i ? a[i - 1][j] : INT_MAX, j ? a[i][j - 1] : INT_MAX));
            best = max(best, a[i][j] - i - j - mn - 1);
            a[i][j] = mn;
        }
    }

    return best;
}

void LeftRight(vector<vector<int>>& a)
{
    FI(a.size())
        reverse(a[i].begin(), a[i].end());
}

void UpDown(vector<vector<int>>& a)
{
    reverse(a.begin(), a.end());
}

int main()
{
#if !LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    ifstream cin("input.txt");
//    ofstream cout("output.txt");
#endif

    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    FI(n)
        FJ(m)
            cin >> a[i][j];

    int ans = INT_MIN;
    ans = max(ans, Get(a));
    LeftRight(a);
    ans = max(ans, Get(a));
    UpDown(a);
    ans = max(ans, Get(a));
    LeftRight(a);
    ans = max(ans, Get(a));
    cout << ans;

    dbg("\nIt took %f ms to run.", 1000.0 * clock() / CLOCKS_PER_SEC);
    return 0;
}

Compilation message

maxcomp.cpp: In function 'void LeftRight(std::vector<std::vector<int> >&)':
maxcomp.cpp:2:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FI(_n) for(int i = 0; i < _n; ++i)
                               ~~^~~~~~~~~~~
 #define FJ(_n) for(int j = 0; j < _n; ++j)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #define mp make_pair
 ~~~~~~~~~~~~~~~~~~~~~            
 #define pb push_back
 ~~~~~~~~~~~~~~~~~~~~~            
 #define endl '\n'
 ~~~~~~~~~~~~~~~~~~               
 
 ~                                
 #ifdef LOCAL
 ~~~~~~~~~~~~~                    
     #define dbg(...) fprintf(stderr, __VA_ARGS__)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #else
 ~~~~~~                           
     #define LOCAL 0
     ~~~~~~~~~~~~~~~~             
     #define dbg(...)
     ~~~~~~~~~~~~~~~~~            
 #endif
 ~~~~~~~                          
 #define cerr if (!LOCAL) {} else std::cerr
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 ~                                
 using ll = long long;
 ~~~~~~~~~~~~~~~~~~~~~~           
 using ull = unsigned long long;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 using ld = long double;
 ~~~~~~~~~~~~~~~~~~~~~~~~         
 using namespace std;
 ~~~~~~~~~~~~~~~~~~~~~            
 
 ~                                
 int Get(vector<vector<int>> a)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
 {
 ~~                               
     int n = a.size();
     ~~~~~~~~~~~~~~~~~~           
     int m = a.back().size();
     ~~~~~~~~~~~~~~~~~~~~~~~~~    
 
 ~                                
     /// minimizing min - x - y
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     int best = -1;
     ~~~~~~~~~~~~~~~              
     FI(n)
     ~~~~~~                       
     {
     ~~                           
         FJ(m)
         ~~~~~~                   
         {
         ~~                       
             int mn = min(a[i][j] - i - j, min(i ? a[i - 1][j] : INT_MAX, j ? a[i][j - 1] : INT_MAX));
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             best = max(best, a[i][j] - i - j - mn - 1);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             a[i][j] = mn;
             ~~~~~~~~~~~~~~       
         }
         ~~                       
     }
     ~~                           
 
 ~                                
     return best;
     ~~~~~~~~~~~~~                
 }
 ~~                               
 
 ~                                
 void LeftRight(vector<vector<int>>& a)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 {
 ~~                               
     FI(a.size())
     ~~~~~~~~~~~                  
maxcomp.cpp:43:5: note: in expansion of macro 'FI'
     FI(a.size())
     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 171 ms 8316 KB Output is correct
19 Correct 167 ms 8360 KB Output is correct
20 Correct 157 ms 7984 KB Output is correct
21 Correct 179 ms 16808 KB Output is correct
22 Correct 171 ms 16812 KB Output is correct
23 Correct 175 ms 16808 KB Output is correct
24 Correct 168 ms 17204 KB Output is correct