Submission #765486

# Submission time Handle Problem Language Result Execution time Memory
765486 2023-06-24T14:53:54 Z Username4132 Flood (IOI07_flood) C++14
73 / 100
76 ms 10848 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using pii = pair<int, int>;
using ppi = pair<pii, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
 
const int MAXN=200000;
int n, w, cou[2*MAXN];
pii edges[2*MAXN], g[MAXN][4], pt[MAXN];
vector<ppi> remaining;
 
int getDir(int a, int b){
    pii pa = pt[a], pb = pt[b];
    if(pa.F == pb.F) return pa.S < pb.S? 1 : 3;
    else return pa.F < pb.F? 0 : 2;
}
 
int main(){
    scanf("%d", &n);
    forn(i, n) scanf("%d %d", &pt[i].F, &pt[i].S);
    forn(i, n) forn(j, 4) g[i][j] = {-1, -1};
    scanf("%d", &w);
    remaining.resize(w);
    forn(i, w){
        int a, b; scanf("%d %d", &a, &b); --a, --b;
        if(pt[a].F<pt[b].F) swap(a, b);
        edges[i]={a, b};
        remaining[i]={edges[i], i};
        g[a][getDir(a, b)] = {b, i};
        g[b][getDir(b, a)] = {a, i};
    }
    sort(remaining.begin(), remaining.end(), [](ppi a, ppi b){
        return pt[a.F.F].F < pt[b.F.F].F;
    });
 
    while(!remaining.empty()){
        ppi ed = remaining.back();
        remaining.pop_back();
 
        if(cou[ed.S]) continue;
 
        bool stop = false;
        int cur = ed.F.F, dir=2, ind=ed.S, fin, finDir;
        vector<int> toClear;
        while(true){
            dir = (dir+3)&3;
            while(g[cur][dir].F==-1) dir = (dir+1)&3;
            ind = g[cur][dir].S;
            if(!stop) fin = ind, finDir = dir;
            if(ind==fin && finDir==dir && stop) break;
            stop = true;
            cur = g[cur][dir].F;
            toClear.PB(ind);
        }
        for(int e:toClear){
            cou[e]++;
            int a = edges[e].F, b = edges[e].S;
            g[a][getDir(a, b)] = {-1, -1};
            g[b][getDir(b, a)] = {-1, -1};
        } 
    }
 
    int total=0;
    forn(i, w) if(cou[i]>1) ++total;
    printf("%d\n", total);
    forn(i, w) if(cou[i]>1) printf("%d\n", i+1);
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
flood.cpp:25:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     forn(i, n) scanf("%d %d", &pt[i].F, &pt[i].S);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flood.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &w);
      |     ~~~~~^~~~~~~~~~
flood.cpp:30:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8132 KB Output is correct
2 Incorrect 63 ms 10848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 9996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 10796 KB Output isn't correct
2 Halted 0 ms 0 KB -