답안 #907098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907098 2024-01-15T06:58:10 Z 089487 Sandcastle 2 (JOI22_ho_t5) C++14
0 / 100
860 ms 1048576 KB
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cout<<"\n";
}
template<class T,class ...U>
void debug(T a,U ...b){
    cout<<a<<" ",debug(b...);
}
const int N=5e4+7;
const int INF=1e18;
struct quest{
    int lx,rx,ly,ry,cnt;
    quest(int a,int b,int c,int d,int e) : lx(a),rx(b),ly(c),ry(d),cnt(e){
    }
};
quest operator + (quest &a,quest &b){
    return quest(min(a.lx,b.lx),max(a.rx,b.rx),min(a.ly,b.ly),max(a.ry,b.ry),a.cnt+b.cnt);
} 
vector<quest> ans[N];
vector<int> v[N];
pii mv[4]={mp(0,1),mp(0,-1),mp(1,0),mp(-1,0)};
pii pos[N];
bool ok(quest &q){
    return (q.rx-q.lx+1)*(q.ry-q.ly+1)==q.cnt;
}
signed main(){
	quick
    int h,w;
    cin>>h>>w;
    vector<vector<int>> c(h,vector<int>(w));
    vector<int> idx;
    rep(i,0,h-1){
        rep(j,0,w-1){
            cin>>c[i][j];
            idx.eb(c[i][j]);
        }
    }
    sort(all(idx));
    rep(i,0,h-1){
        rep(j,0,w-1){
            c[i][j]=lower_bound(all(idx),c[i][j])-idx.begin();
            pos[c[i][j]]=mp(i,j);
        }
    }
    rep(i,0,h-1){
        rep(j,0,w-1){
            for(pii p2:mv){
                int x=p2.F+i;
                int y=p2.S+j;
                if(x>=0&&x<h&&y>=0&&y<w&&c[x][y]>c[i][j]){
                    v[c[i][j]].eb(c[x][y]);
                }
            }

        }
    }
    int num=0;
    rep(i,0,h*w-1){
        ans[i].eb(quest(pos[i].F,pos[i].F,pos[i].S,pos[i].S,1));
        rep(j,0,sz(ans[i])-2){
            ans[i][j]=ans[i][j]+ans[i].back();
        }
        for(quest &q:ans[i]){
            if(ok(q)) num++;
            for(int j:v[i]) ans[j].eb(q);
        }
    }
    cout<<num<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Runtime error 860 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Runtime error 664 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Runtime error 664 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Runtime error 664 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Runtime error 664 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -