답안 #1095362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095362 2024-10-02T02:00:11 Z doducanh Flood (IOI07_flood) C++14
82 / 100
120 ms 33876 KB
///breaker
///every second counts
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
const int maxn=1e5+7;
int x[maxn],y[maxn];
int side[maxn][4][2];
int lev[maxn*4];
int vst[maxn*4];
vector<int>adj[4*maxn];
int xof[2*maxn];
int w;
int n;
void ghep(int x,int y)
{
    adj[x].push_back(y);
    adj[y].push_back(x);
}
set<ii>s;
void sol(void){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
    }
    cin>>w;
    for(int i=1;i<=w;i++){
        int a,b;
        cin>>a>>b;
        if(x[a]==x[b]){
            if(y[a]>y[b])swap(a,b);
            side[a][2][1]=i;
            side[a][2][0]=i+w;
            side[b][0][0]=i;
            side[b][0][1]=i+w;
            xof[i]=x[a];
            s.insert({xof[i],i});
        }
        else{
            if(x[a]>x[b])swap(a,b);
            side[a][1][0]=i;
            side[a][1][1]=i+w;
            side[b][3][1]=i;
            side[b][3][0]=i+w;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<4;j++)if(side[i][j][1]){
            for(int k=(j+1)%4;;k=(k+1)%4)if(side[i][k][0]){
                ghep(side[i][j][1],side[i][k][0]);
                break;
            }
        }
    }
    for(int i=1;i<=w;i++){
        lev[i]=lev[i+w]=1e9+7;
    }
    while(1){
        if(s.empty())break;
        int tmp=s.begin()->se;
        s.erase(s.begin());
        deque<int>q;
        q.push_front(tmp);
        lev[tmp]=0;
        while(q.size()){
            int x=q.front();
            q.pop_front();
            if(vst[x])continue;
            if(x<=w)s.erase({xof[x],x});
            vst[x]=1;
            for(int y:adj[x]){
                if(lev[y]>lev[x]){
                    lev[y]=lev[x];
                    q.push_front(y);
                }
            }
            adj[x].clear();
            int k=(x>w?x-w:x+w);
            if(lev[k]>lev[x]+1){
                lev[k]=lev[x]+1;
                q.push_back(k);
            }
        }
    }
    vector<int>ans;
    for(int i=1;i<=w;i++){
        if(lev[i]==lev[i+w]){
            ans.push_back(i);
        }
    }
    cout<<ans.size()<<"\n";
    for(int x:ans){
        cout<<x<<"\n";
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--){
        sol();
    }
    // you should actually read the stuff at the bottom
    return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 3 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Correct 3 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 24576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 25164 KB Output is correct
2 Runtime error 120 ms 33316 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 28240 KB Output is correct
2 Runtime error 113 ms 33876 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 30292 KB Output is correct
2 Correct 50 ms 27084 KB Output is correct