답안 #528294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528294 2022-02-19T20:17:21 Z doowey Sandcastle 2 (JOI22_ho_t5) C++14
80 / 100
5000 ms 17100 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

vector<vector<int>> A;
vector<vector<ll>> S4;
vector<vector<ll>> S5;
vector<vector<ll>> S6;
vector<vector<ll>> S7;
vector<vector<ll>> S8;

int n, m;

const int inf = 1e6;
int calc(int i, int j, int mode){
    vector<int> V;
    if(mode == 0){
        V = {A[i + 1][j], A[i][j+1]};
    }
    else if(mode == 1){
        V = {A[i + 1][j], A[i][j-1]};
    }
    else if(mode == 2){
        V = {A[i - 1][j], A[i][j+1]};
    }
    else if(mode == 3){
        V = {A[i - 1][j], A[i][j-1]};
    }
    else if(mode == 4){
        V = {A[i][j-1], A[i+1][j], A[i][j+1]};
    }
    else if(mode == 5){
        V = {A[i-1][j], A[i+1][j], A[i][j-1]};
    }
    else if(mode == 6){
        V = {A[i-1][j], A[i][j-1], A[i][j+1]};
    }
    else if(mode == 7){
        V = {A[i-1][j], A[i+1][j], A[i][j+1]};
    }
    else{
        V = {A[i-1][j], A[i+1][j], A[i][j+1],A[i][j-1]};
    }
    int maxi = 0;
    for(auto x : V){
        if(x < A[i][j]){
            maxi = max(maxi, x);
        }
    }

    int high = inf;
    for(auto x : V){
        if(x > A[i][j]){
            high = min(high, x);
        }
    }
    int cum = high - A[i][j];
    if(maxi == 0) cum += A[i][j];
    return cum;
}


int main(){
    fastIO;
    cin >> n >> m;
    A.resize(n);
    S4.resize(n);
    S5.resize(n);
    S6.resize(n);
    S7.resize(n);
    S8.resize(n);
    for(int i = 0 ; i < n; i ++ ){
        A[i].resize(m);
        S4[i].resize(m);
        S5[i].resize(m);
        S6[i].resize(m);
        S7[i].resize(m);
        S8[i].resize(m);
    }
    vector<int> C;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            cin >> A[i][j];
            C.push_back(A[i][j]);
        }
    }
    sort(C.begin(), C.end());
    C.resize(unique(C.begin(), C.end()) - C.begin());
    int id;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < m; j ++ ){
            A[i][j] = upper_bound(C.begin(), C.end(), A[i][j]) - C.begin();
        }
    }
    for(int i = 0; i < n; i ++ ){
        for(int j = 0; j < m; j ++ ){
            if(j > 0 && j + 1 < m && i + 1 < n)S4[i][j] = calc(i, j, 4);
            if(i > 0 && i + 1 < n && j > 0) S5[i][j] = calc(i, j, 5);
            if(i > 0 && j > 0 && j + 1 < m) S6[i][j] = calc(i, j, 6);
            if(j + 1 < m && i > 0 && i + 1 < n) S7[i][j] = calc(i, j, 7);
            if(i > 0 && j > 0 && i + 1 < n && j + 1 < m)S8[i][j] = calc(i, j, 8);
            if(i){
                S5[i][j] += S5[i-1][j];
                S7[i][j] += S7[i-1][j];
                S8[i][j] += S8[i-1][j];
            }
            if(j){
                S4[i][j] += S4[i][j-1];
                S6[i][j] += S6[i][j-1];
                S8[i][j] += S8[i][j-1];
            }
            if(i && j){
                S8[i][j] -= S8[i-1][j-1];
            }
        }
    }
    ll res = 0;
    res += n * m;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            for(int k = j + 1 ; k < m ; k ++ ){
                if(A[i][k] > A[i][k - 1]){
                    break;
                }
                res ++ ;
            }
            for(int k = j - 1; k >= 0 ; k -- ){
                if(A[i][k] > A[i][k + 1]){
                    break;
                }
                res ++ ;
            }
            for(int k = i + 1; k < n; k ++ ){
                if(A[k][j] > A[k - 1][j]){
                    break;
                }
                res ++ ;
            }
            for(int k = i - 1; k >= 0; k -- ){
                if(A[k][j] > A[k + 1][j]){
                    break;
                }
                res ++ ;
            }
        }
    }
    ll cummy;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            for(int ii = i + 1; ii < n; ii ++ ){
                for(int jj = j + 1; jj < m ; jj ++ ){
                    cummy = 0;
                    cummy += S8[ii-1][jj-1] + S8[i][j] - S8[i][jj-1] - S8[ii-1][j];
                    cummy += calc(i,j,0);
                    cummy += calc(ii,jj,3);
                    cummy += calc(i,jj,1);
                    cummy += calc(ii,j,2);
                    cummy += S4[i][jj-1]-S4[i][j];
                    cummy += S6[ii][jj-1]-S6[ii][j];
                    cummy += S5[ii-1][jj]-S5[i][jj];
                    cummy += S7[ii-1][j]-S7[i][j];
                    if(cummy == inf){
                        res ++ ;
                    }
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:97:9: warning: unused variable 'id' [-Wunused-variable]
   97 |     int id;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 443 ms 2788 KB Output is correct
3 Correct 16 ms 2764 KB Output is correct
4 Correct 344 ms 2768 KB Output is correct
5 Correct 31 ms 2768 KB Output is correct
6 Correct 15 ms 2768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 78 ms 380 KB Output is correct
10 Correct 72 ms 332 KB Output is correct
11 Correct 39 ms 332 KB Output is correct
12 Correct 41 ms 460 KB Output is correct
13 Correct 67 ms 332 KB Output is correct
14 Correct 38 ms 332 KB Output is correct
15 Correct 77 ms 400 KB Output is correct
16 Correct 82 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 78 ms 380 KB Output is correct
10 Correct 72 ms 332 KB Output is correct
11 Correct 39 ms 332 KB Output is correct
12 Correct 41 ms 460 KB Output is correct
13 Correct 67 ms 332 KB Output is correct
14 Correct 38 ms 332 KB Output is correct
15 Correct 77 ms 400 KB Output is correct
16 Correct 82 ms 332 KB Output is correct
17 Correct 102 ms 2636 KB Output is correct
18 Correct 1664 ms 688 KB Output is correct
19 Correct 1574 ms 660 KB Output is correct
20 Correct 1540 ms 668 KB Output is correct
21 Correct 1520 ms 664 KB Output is correct
22 Correct 1461 ms 672 KB Output is correct
23 Correct 1463 ms 660 KB Output is correct
24 Correct 1396 ms 648 KB Output is correct
25 Correct 1594 ms 676 KB Output is correct
26 Correct 1586 ms 672 KB Output is correct
27 Correct 1626 ms 684 KB Output is correct
28 Correct 1606 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 78 ms 380 KB Output is correct
10 Correct 72 ms 332 KB Output is correct
11 Correct 39 ms 332 KB Output is correct
12 Correct 41 ms 460 KB Output is correct
13 Correct 67 ms 332 KB Output is correct
14 Correct 38 ms 332 KB Output is correct
15 Correct 77 ms 400 KB Output is correct
16 Correct 82 ms 332 KB Output is correct
17 Correct 102 ms 2636 KB Output is correct
18 Correct 1664 ms 688 KB Output is correct
19 Correct 1574 ms 660 KB Output is correct
20 Correct 1540 ms 668 KB Output is correct
21 Correct 1520 ms 664 KB Output is correct
22 Correct 1461 ms 672 KB Output is correct
23 Correct 1463 ms 660 KB Output is correct
24 Correct 1396 ms 648 KB Output is correct
25 Correct 1594 ms 676 KB Output is correct
26 Correct 1586 ms 672 KB Output is correct
27 Correct 1626 ms 684 KB Output is correct
28 Correct 1606 ms 672 KB Output is correct
29 Execution timed out 5055 ms 17100 KB Time limit exceeded
30 Halted 0 ms 0 KB -