답안 #161707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161707 2019-11-03T20:11:30 Z sans Flood (IOI07_flood) C++14
20 / 100
2000 ms 35340 KB
#include <bits/stdc++.h>
using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(int yy = 0; yy < YY; ++yy)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;

int N, W;
vector<ii> cor;
vector<pair<ii, int>> corSorted;

vvi AdjList;
map<ii, int> walls;
map<int, bool> saglam;

//Input
void input(void)
{
    cin >> N; AdjList.resize(N);
    for(int i = 0; i < N; ++i)
    {
        int x, y;
        cin >> x >> y;
        cor.pb(mp(x, y));
        corSorted.pb(mp(mp(x, y), i));
    }
    sort(corSorted.begin(), corSorted.end());
    cin >> W;
    for(int i = 0; i < W; ++i)
    {
        int u, v; cin >> u >> v; u--; v--;
        walls[mp(u, v)] = walls[mp(v, u)] = i;
        saglam[i] = true;
        AdjList[u].pb(v);
        AdjList[v].pb(u);
    }
}

vector<bool> visited;
int startNode;
stack<int> nodes;

void duvaryik(stack<int> &s)
{
    while(!s.empty())
    {
        int top1 = s.top(); s.pop();
        if(!s.empty())
        {
            int top2 = s.top();
            saglam[walls[mp(top1, top2)]] = false;
        }
        else continue;
    }
    return;
}

bool compare(const pair<ii, int> &p1, const pair<ii, int> &p2)
{
    if(p1.st.st > p2.st.st and p1.st.nd > p2.st.nd) return true;
    if(p2.st.st > p1.st.st and p2.st.nd > p1.st.nd) return false;

    if(p1.st.st < p2.st.st and p1.st.nd < p2.st.nd) return true;
    if(p2.st.st < p1.st.st and p2.st.nd < p1.st.nd) return false;

    if(p1.st.st < p2.st.st and p1.st.nd > p2.st.nd) return true;
    if(p2.st.st < p1.st.st and p2.st.nd > p1.st.nd) return false;

    if(p1.st.st < p2.st.st and p1.st.nd > p2.st.nd) return true;
    if(p2.st.st < p1.st.st and p2.st.nd > p1.st.nd) return false;

    return true;
}

bool bitti = false;
void traverse(int n, int b)
{
    //cout << n << endl;
    visited[n] = true;
    if(n == startNode and b != 0){ duvaryik(nodes); bitti = true; return; }

    vector<pair<ii, int>> VN;
    for(int i = 0; i < (int)AdjList[n].size(); ++i)
    {
        if(saglam[walls[mp(n, AdjList[n][i])]] and (!visited[AdjList[n][i]] or (AdjList[n][i] == startNode and b > 2)))
            VN.pb(mp(cor[AdjList[n][i]], AdjList[n][i]));
    }

    sort(VN.begin(), VN.end(), compare);
    for(int i = 0; i < (int)VN.size(); ++i)
    {
        nodes.push(VN[i].nd);
        traverse(VN[i].nd, b+1);
        if(bitti) return;
        nodes.pop();
    }

    visited[n] = false;
    return;
}

int main(int argc, char **argv)
{
    input();

    for(int i = 0; i < corSorted.size(); ++i)
    {
        bitti = false;
        visited.assign(N, false);
        startNode = corSorted[i].nd;

        nodes.push(startNode);
        traverse(startNode, 0);
    }

    int sum = 0; vi ans;
    for(auto itr = saglam.begin(); itr != saglam.end(); ++itr)
        if(itr->nd){ ans.pb((itr->st)+1); sum++; }

    cout << sum << endl;
    for(int i = 0; i < ans.size(); ++i) cout << ans[i] << endl;

    return 0;
}

//cikisir

Compilation message

flood.cpp: In function 'int main(int, char**)':
flood.cpp:119:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < corSorted.size(); ++i)
                    ~~^~~~~~~~~~~~~~~~~~
flood.cpp:134:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ans.size(); ++i) cout << ans[i] << endl;
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 341 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 358 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 7216 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 26252 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Incorrect 486 ms 26484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2060 ms 31756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2072 ms 35340 KB Time limit exceeded
2 Halted 0 ms 0 KB -