답안 #989800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989800 2024-05-28T19:57:42 Z PedroBigMan Flood (IOI07_flood) C++14
33 / 100
201 ms 65536 KB
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007;

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

class WG //everything works for weighted directed graphs except dynamic graph
{
    public:
    ll N; vector<vector<pl> > adj;
    vector<bool> pr; 
    
    WG(vector<vector<pl> > ad)
    {
        adj=ad; N=adj.size();
        REP(i,0,N) {pr.pb(false);}
    }
    
    vector<ll> Djikstra(ll s)
    {
        vector<ll> d; REP(i,0,N) {d.pb(INF);}
        d[s]=0;
        priority_queue<pl> q;
        q.push(mp(0,s));
        ll cur;
        while(!q.empty())
        {
            cur=q.top().ss; q.pop();
            if(pr[cur]) {continue;}
            pr[cur]=true; 
            REP(i,0,adj[cur].size())
            {
                if(d[adj[cur][i].ff]>d[cur]+adj[cur][i].ss)
                {
                    d[adj[cur][i].ff]=d[cur]+adj[cur][i].ss;
                    q.push(mp(-d[adj[cur][i].ff],adj[cur][i].ff));
                }
            }
        }
        return d;
    }
};


vector<vector<pl> > adj;

void add_edge(ll A, ll B, ll we)
{
    adj[A].pb({B,we}); adj[B].pb({A,we});
}

ll clockwise(ll dir)
{
    if(dir==0) {return 1;}
    if(dir==1) {return 0;}
    if(dir==2) {return 0;}
    if(dir==3) {return 1;}
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	cout.precision(20);
	ll N; vector<pl> p; pl cur; cin>>N; REP(i,0,N) {cin>>cur.ff>>cur.ss; p.pb(cur);}
    ll W; cin>>W; vector<vector<pl> > walls(N,vector<pl>()); ll A,B;
    ll outside = -1; ll outside_coord = INF;
    REP(w,0,W) 
    {
        cin>>A>>B; A--; B--;
        if(p[A].ff==p[B].ff) 
        {
            if(p[A].ff<outside_coord) {outside_coord=p[A].ff; outside=w;}
            if(p[A].ss>p[B].ss) {swap(A,B);}
            walls[A].pb({0,w}); walls[B].pb({2,w});
        }
        if(p[A].ss==p[B].ss) 
        {
            if(p[A].ff>p[B].ff) {swap(A,B);}
            walls[A].pb({1,w}); walls[B].pb({3,w});
        }
    }
    REP(i,0,N) {sort(whole(walls[i]));}
    adj = vector<vector<pl> >(2*W,vector<pl>());
    REP(i,0,W) {add_edge(2*i,2*i+1,1);} 
    ll dirA, dirB; ll nodeA, nodeB;
    REP(i,0,N)
    {
        REP(j,0,walls[i].size())
        {
            A=walls[i][j].ss; dirA = walls[i][j].ff;
            B = walls[i][(j+1)%walls[i].size()].ss; dirB = walls[i][(j+1)%walls[i].size()].ff;
            nodeA = 2*A+clockwise(dirA); nodeB = 2*B + 1 - clockwise(dirB);
            add_edge(nodeA,nodeB,0);
        }
    }
    if(outside==-1)
    {
        cout<<W<<endl;
        REP(i,0,W) {cout<<i+1<<endl;} 
        return 0;
    }
    WG G(adj);
    vector<ll> d = G.Djikstra(2*outside);
    vector<ll> ans; 
    REP(i,0,W) {if(d[2*i]==d[2*i+1]) {ans.pb(i+1);}}
    cout<<ans.size()<<endl; REP(i,0,ans.size()) {cout<<ans[i]<<endl;}
    return 0;
}

Compilation message

flood.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization ("O3")
      | 
flood.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 14848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 156 ms 53960 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 201 ms 59796 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 147 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 189 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -