Submission #593807

# Submission time Handle Problem Language Result Execution time Memory
593807 2022-07-11T15:43:18 Z oleh1421 Sandcastle 2 (JOI22_ho_t5) C++17
24 / 100
5000 ms 912 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#define y2 y_2
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
const ll inf=1e18;
mt19937 rnd(time(NULL));
const ll mod=998244353;
const int N=510;
const int Lg=16;
vector<vector<int> >a;
bool ok(int x1,int y1,int x2,int y2){
    int cnt=0;
    int cnt1=0;
    for (int i=x1;i<=x2;i++){
        for (int j=y1;j<=y2;j++){
            int x=-1,y=-1;
            for (int dx=-1;dx<=1;dx++){
                for (int dy=-1;dy<=1;dy++){
                    if (dx && dy) continue;
                    if (!dx && !dy) continue;
                    int nx=i+dx,ny=j+dy;
                    if (nx<x1 || nx>x2 || ny<y1 || ny>y2) continue;
                    if (a[nx][ny]<a[i][j]) continue;
                    if (x==-1 || a[x][y]>a[nx][ny]){
                        x=nx;
                        y=ny;
                    }
                }
            }
            if (x==-1) continue;
            cnt++;
            for (int dx=-1;dx<=1;dx++){
                for (int dy=-1;dy<=1;dy++){
                    if (dx && dy) continue;
                    if (!dx && !dy) continue;
                    int nx=x+dx,ny=y+dy;
                    if (nx<x1 || nx>x2 || ny<y1 || ny>y2) continue;
                    if (a[nx][ny]<a[x][y] && a[i][j]<a[nx][ny]) cnt1++;
                }
            }
        }
    }

    return (cnt==((x2-x1+1)*(y2-y1+1)-1) && cnt1==0);
}
void solve(){
    int n,m;cin>>n>>m;
    if (n>m){
        swap(n,m);
        a.resize(n);
        for (int i=0;i<n;i++){
            a[i].resize(m);
        }
        for (int j=0;j<m;j++){
            for (int i=0;i<n;i++){
                cin>>a[i][j];
            }
        }
    } else {
        a.resize(n);
        for (int i=0;i<n;i++){
            a[i].resize(m);
        }
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                cin>>a[i][j];
            }
        }
    }





    if (n==1){
        vector<int>v;
        for (int i=1;i<m;i++){
            v.push_back(a[0][i-1]<a[0][i]);
        }
        int res=m;
        int cnt=0;
        for (int i=0;i<v.size();i++){
            if (i>0 && v[i]==v[i-1]) cnt++;
            else cnt=1;
            res+=cnt;
        }
        cout<<res<<endl;
        return;

    }

    int res=0;
    for (int x1=0;x1<n;x1++){
        for (int y1=0;y1<m;y1++){
            for (int x2=x1;x2<n;x2++){
                int cnt=0;
                int cnt1=0;
                for (int y2=y1;y2<m;y2++){
                    for (int i=x1;i<=x2;i++){

                        for (int j=max(y1,y2-2);j<y2;j++){
                            {
                                int x=-1,y=-1;
                                for (int dx=-1;dx<=1;dx++){
                                    for (int dy=-1;dy<=1;dy++){
                                        if (dx && dy) continue;
                                        if (!dx && !dy) continue;
                                        int nx=i+dx,ny=j+dy;
                                        if (nx<x1 || nx>x2 || ny<y1 || ny>=y2) continue;
                                        if (a[nx][ny]<a[i][j]) continue;
                                        if (x==-1 || a[x][y]>a[nx][ny]){
                                            x=nx;
                                            y=ny;
                                        }
                                    }
                                }
                                if (x==-1) continue;
                                cnt--;
                                for (int dx=-1;dx<=1;dx++){
                                    for (int dy=-1;dy<=1;dy++){
                                        if (dx && dy) continue;
                                        if (!dx && !dy) continue;
                                        int nx=x+dx,ny=y+dy;
                                        if (nx<x1 || nx>x2 || ny<y1 || ny>=y2) continue;
                                        if (a[nx][ny]<a[x][y] && a[i][j]<a[nx][ny]) cnt1--;
                                    }
                                }

                            }

                        }
                    }
                    for (int i=x1;i<=x2;i++){
                        for (int j=max(y1,y2-2);j<=y2;j++){
                            {
                                int x=-1,y=-1;
                                for (int dx=-1;dx<=1;dx++){
                                    for (int dy=-1;dy<=1;dy++){
                                        if (dx && dy) continue;
                                        if (!dx && !dy) continue;
                                        int nx=i+dx,ny=j+dy;
                                        if (nx<x1 || nx>x2 || ny<y1 || ny>y2) continue;
                                        if (a[nx][ny]<a[i][j]) continue;
                                        if (x==-1 || a[x][y]>a[nx][ny]){
                                            x=nx;
                                            y=ny;
                                        }
                                    }
                                }
                                if (x==-1) continue;
                                cnt++;
                                for (int dx=-1;dx<=1;dx++){
                                    for (int dy=-1;dy<=1;dy++){
                                        if (dx && dy) continue;
                                        if (!dx && !dy) continue;
                                        int nx=x+dx,ny=y+dy;
                                        if (nx<x1 || nx>x2 || ny<y1 || ny>y2) continue;
                                        if (a[nx][ny]<a[x][y] && a[i][j]<a[nx][ny]) cnt1++;
                                    }
                                }

                            }

                        }
                    }
                    if (cnt==((x2-x1+1)*(y2-y1+1)-1) && cnt1==0) res++;
                }
            }
        }
    }
    cout<<res<<endl;
}
int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt=1;
//    cin>>tt;
    while (tt--){
        solve();
    }
    return 0;

}


/**
3
5 2 7 3 1 6 8 4
**/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for (int i=0;i<v.size();i++){
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 912 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2383 ms 340 KB Output is correct
10 Correct 1946 ms 340 KB Output is correct
11 Correct 247 ms 340 KB Output is correct
12 Correct 286 ms 320 KB Output is correct
13 Correct 2001 ms 340 KB Output is correct
14 Correct 1124 ms 340 KB Output is correct
15 Correct 2111 ms 340 KB Output is correct
16 Correct 2353 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2383 ms 340 KB Output is correct
10 Correct 1946 ms 340 KB Output is correct
11 Correct 247 ms 340 KB Output is correct
12 Correct 286 ms 320 KB Output is correct
13 Correct 2001 ms 340 KB Output is correct
14 Correct 1124 ms 340 KB Output is correct
15 Correct 2111 ms 340 KB Output is correct
16 Correct 2353 ms 336 KB Output is correct
17 Correct 1 ms 532 KB Output is correct
18 Execution timed out 5048 ms 340 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2383 ms 340 KB Output is correct
10 Correct 1946 ms 340 KB Output is correct
11 Correct 247 ms 340 KB Output is correct
12 Correct 286 ms 320 KB Output is correct
13 Correct 2001 ms 340 KB Output is correct
14 Correct 1124 ms 340 KB Output is correct
15 Correct 2111 ms 340 KB Output is correct
16 Correct 2353 ms 336 KB Output is correct
17 Correct 1 ms 532 KB Output is correct
18 Execution timed out 5048 ms 340 KB Time limit exceeded
19 Halted 0 ms 0 KB -