답안 #916186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916186 2024-01-25T12:42:37 Z Abito Golf (JOI17_golf) C++14
0 / 100
6066 ms 392112 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
/*
⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⢻⣿⣿⣿⣿⣿⣿⣿⣿⣯⢻⣿⣿⣿⣿⣆⠄⠄⠄
⠄⠄⣼⢀⣿⣿⣿⣿⣏⡏⠄⠹⣿⣿⣿⣿⣿⣿⣿⣿⣧⢻⣿⣿⣿⣿⡆⠄⠄
⠄⠄⡟⣼⣿⣿⣿⣿⣿⠄⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⣿⣇⢻⣿⣿⣿⣿⠄⠄
⠄⢰⠃⣿⣿⠿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠙⠿⣿⣿⣿⣿⣿⠄⢿⣿⣿⣿⡄⠄
⠄⢸⢠⣿⣿⣧⡙⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠈⠛⢿⣿⣿⡇⠸⣿⡿⣸⡇⠄
⠄⠈⡆⣿⣿⣿⣿⣦⡙⠳⠄⠄⠄⠄⠄⠄⢀⣠⣤⣀⣈⠙⠃⠄⠿⢇⣿⡇⠄
⠄⠄⡇⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⣠⣶⣿⣿⣿⣿⣿⣿⣷⣆⡀⣼⣿⡇⠄
⠄⠄⢹⡘⣿⣿⣿⢿⣷⡀⠄⢀⣴⣾⣟⠉⠉⠉⠉⣽⣿⣿⣿⣿⠇⢹⣿⠃⠄
⠄⠄⠄⢷⡘⢿⣿⣎⢻⣷⠰⣿⣿⣿⣿⣦⣀⣀⣴⣿⣿⣿⠟⢫⡾⢸⡟⠄.
⠄⠄⠄⠄⠻⣦⡙⠿⣧⠙⢷⠙⠻⠿⢿⡿⠿⠿⠛⠋⠉⠄⠂⠘⠁⠞⠄⠄⠄
⠄⠄⠄⠄⠄⠈⠙⠑⣠⣤⣴⡖⠄⠿⣋⣉⣉⡁⠄⢾⣦⠄⠄⠄⠄⠄⠄⠄⠄
*/
typedef unsigned long long ull;
using namespace std;
struct tri{
    int x,y,z;
};
const int N=1505;
int s,t,u,v,n,a[N],b[N],c[N],d[N],p[N][N],dis[N][N][5],mvx[]={1,0,-1,0},mvy[]={0,1,0,-1};
bool vis[N][N][5];
bool ok(int x,int y,int i){
    return x>=0 && x<N && y>=0 && y<N && !vis[x][y][i] && !p[x][y];
}
void bfs(){
    priority_queue<vector<int>> pq;
    dis[s][t][4]=0;
    pq.push({0,s,t,4});
    while (!pq.empty()){
        vector<int> x=pq.top();
        pq.pop();
        if (vis[x[1]][x[2]][x[3]]) continue;
        vis[x[1]][x[2]][x[3]]=true;
        x[0]*=-1;
        for (int i=0;i<4;i++){
            int nx=x[1]+mvx[i],ny=x[2]+mvy[i];
            if (!ok(nx,ny,i)) continue;
            if (dis[nx][ny][i]<=x[0]+bool(i!=x[3])) continue;
            dis[nx][ny][i]=x[0]+bool(i!=x[3]);
            pq.push({-dis[nx][ny][i],nx,ny,i});
        }
    }return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>s>>t>>u>>v>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]++;c[i]++;
        p[a[i]][c[i]]++;
        p[a[i]][d[i]+1]--;
        p[b[i]+1][c[i]]--;
        p[b[i]+1][d[i]+1]++;
    }
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            if (i-1) p[i][j]+=p[i-1][j];
            if (j-1) p[i][j]+=p[i][j-1];
            if (i-1 && j-1) p[i][j]-=p[i-1][j-1];
        }
    }
    for (int i=0;i<N;i++) for (int j=0;j<N;j++) for (int k=0;k<5;k++) dis[i][j][k]=INT_MAX;
    /*for (int i=0;i<N;i++){
        for (int j=0;j<N;j++) cout<<p[i][j]<<' ';
        cout<<endl;
    }*/
    bfs();
    /*for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            if (p[i][j]){
                cout<<"B ";
                continue;
            }
            int mn=INT_MAX;
            for (int k=0;k<5;k++) if (vis[i][j][k]) mn=min(mn,dis[i][j][k]);
            cout<<mn<<' ';
        }cout<<endl;
    }*/
    int ans=INT_MAX;
    for (int i=0;i<4;i++) if (vis[u][v][i]) ans=min(ans,dis[u][v][i]);
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4693 ms 392112 KB Output is correct
2 Correct 6066 ms 293652 KB Output is correct
3 Correct 5479 ms 292964 KB Output is correct
4 Correct 4547 ms 246996 KB Output is correct
5 Correct 4306 ms 230732 KB Output is correct
6 Incorrect 3945 ms 239568 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4693 ms 392112 KB Output is correct
2 Correct 6066 ms 293652 KB Output is correct
3 Correct 5479 ms 292964 KB Output is correct
4 Correct 4547 ms 246996 KB Output is correct
5 Correct 4306 ms 230732 KB Output is correct
6 Incorrect 3945 ms 239568 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4693 ms 392112 KB Output is correct
2 Correct 6066 ms 293652 KB Output is correct
3 Correct 5479 ms 292964 KB Output is correct
4 Correct 4547 ms 246996 KB Output is correct
5 Correct 4306 ms 230732 KB Output is correct
6 Incorrect 3945 ms 239568 KB Output isn't correct
7 Halted 0 ms 0 KB -