Submission #621243

# Submission time Handle Problem Language Result Execution time Memory
621243 2022-08-03T15:31:57 Z moyindavid Fountain Parks (IOI21_parks) C++17
0 / 100
1024 ms 2097152 KB
#include <bits/stdc++.h>
#include "parks.h"
#define pb push_back

using namespace std;

vector<bool> vis(200100,false);int cnt=0;set<int> node[200100];vector<int> u,v,a,b;
void dsf(int i, vector<int> x, vector<int> y){
    vis[i]=true;
    cnt++;
    for(auto j: node[i]){
        if(!vis[j]){
            u.pb(i);v.pb(j);

            if(x[i]==x[j]){
                b.pb((y[i]+y[j])/2);
                if(x[i]==2)a.pb(x[i]-1);
                else a.pb(x[i]+1);
            }
            else{
                a.pb((x[i]+x[j])/2);
                b.pb(y[i]-1);
            }
            dsf(j,x,y);
        }
    }
}

int construct_roads(vector<int> x, vector<int> y){


    map<pair<int,int>,bool> m;
    map<pair<int,int>,int> n;

    for(int i=0;i<x.size();i++){
        m[{x[i],y[i]}]=1;
        n[{x[i],y[i]}]=i;
    }

    for(int i=0;i<x.size();i++){
        if(m.count({x[i]-2,y[i]})>0){node[i].insert(n[{x[i]-2,y[i]}]);node[n[{x[i]-2,y[i]}]].insert(i);}
        if(m.count({x[i]+2,y[i]})>0){node[i].insert(n[{x[i]+2,y[i]}]);node[n[{x[i]+2,y[i]}]].insert(i);}
        if(m.count({x[i],y[i]-2})>0){node[i].insert(n[{x[i],y[i]-2}]);node[n[{x[i],y[i]-2}]].insert(i);}
        if(m.count({x[i],y[i]+2})>0){node[i].insert(n[{x[i],y[i]+2}]);node[n[{x[i],y[i]+2}]].insert(i);}
    }

    dsf(0,x,y);
    if(cnt==x.size()){
        build(u,v,a,b);
        return 1;
    }
    return 0;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
parks.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
parks.cpp:48:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     if(cnt==x.size()){
      |        ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 8 ms 9724 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9688 KB Output is correct
6 Correct 5 ms 9720 KB Output is correct
7 Correct 5 ms 9620 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Runtime error 1024 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -