답안 #812758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812758 2023-08-07T10:54:35 Z lollipop 분수 공원 (IOI21_parks) C++17
15 / 100
469 ms 63040 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
//#define ll long long
#define ll long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 4e5 + 10 ;
//mt19937 R(time(0));
map < int , int > ma , ma1 ;

#include "parks.h"


// static void check(bool cond, string message) {
// 	if (!cond) {
// 		printf("%s\n", message.c_str());
// 		fclose(stdout);
// 		exit(0);
// 	}
// }

// static int n;
// static bool build_called;
// static int m;
// static vector<int> _u, _v, _a, _b;

// void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
// 	check(!build_called, "build is called more than once");
// 	build_called = true;
// 	m = u.size();
// 	check(int(v.size()) == m, "u.size() != v.size()");
// 	check(int(a.size()) == m, "u.size() != a.size()");
// 	check(int(b.size()) == m, "u.size() != b.size()");
// 	check(m <= 2*n, "Construction too large"); // Vertex degrees are at most 4
// 	_u = u;
// 	_v = v;
// 	_a = a;
// 	_b = b;
// }



// for DSU to check in the end 
map < pair < int , int > , int > pos ; 
int ss[ N ] , pp[ N ] ;
void create( int node ){
     pp[ node ] = node ;
     ss[ node ] = 1 ;
     return ; 
}
int find( int node ){
    if( pp[ node ] == node ) return node ;
    return pp[ node ] = find( pp[ node ] ) ; 
}
void unite( int a , int b ){
   a = find( a ) ; b = find( b ) ;
   if( a == b ) return ;
   if( ss[ a ] < ss[ b ] ) swap( a , b ) ;
   if( ss[ a ] == ss[ b ] ) ss[ a ] ++ ;
   pp[ b ] = a ;
   return ;
}
// done DSU UPP


vector < int > x[ N ] ;
map < pair < int , int > , int > fn , dak ;
int construct_roads( vector<int> X, vector<int> Y){
    int n = X.size() ;
    FOR( i , n ){
       x[ X[ i ] ].pb( Y[ i ] ) ;
       fn[ { X[ i ] , Y[ i ] } ] = i ; 
       pos[ { X[ i ] , Y[ i ] } ] = i ;
       create( i ) ;
    }
 //   if( ( x[ 2 ].size() + x[ 4 ].size() ) == n )
    sort( x[ 2 ].begin() , x[ 2 ].end() ) ;
    sort( x[ 4 ].begin() , x[ 4 ].end() ) ;   
    vector < int > u , v , a , b ;  
    FOR( i , x[ 2 ].size() ){
      if( i != x[ 2 ].size() - 1 ){
          if( x[ 2 ][ i + 1 ] - x[ 2 ][ i ] == 2 ){
              u.pb( pos[ { 2 , x[ 2 ][ i ] } ] ) ;
              v.pb( pos[ { 2 , x[ 2 ][ i + 1 ] } ] ) ;
              a.pb( 1 ) ; 
              b.pb( x[ 2 ][ i ] + 1 ) ;
              unite( pos[ { 2 , x[ 2 ][ i ] } ] , pos[ { 2 , x[ 2 ][ i + 1 ] } ] ) ;
          }
      }
    }
// now the important stuff
int A = 0 , B = 0 ;
    FOR( i , x[ 4 ].size() ){      

      if( i != x[ 4 ].size() - 1 ){
          if( x[ 4 ][ i + 1 ] - x[ 4 ][ i ] == 2 ){
              u.pb( pos[ { 4 , x[ 4 ][ i ] } ] ) ;
              v.pb( pos[ { 4 , x[ 4 ][ i + 1 ] } ] ) ;
              
              if( dak.find( { 5 , x[ 4 ][ i ] + 1 } ) == dak.end() ){
                a.pb( 5 ) ;
                b.pb( x[ 4 ][ i ] + 1 ) ; 
                dak[ { 5 , x[ 4 ][ i ] + 1 } ] = 1 ;
              }
              else{
                a.pb( 3 ) ;
                b.pb( x[ 4 ][ i ] + 1 ) ; 
                dak[ { 3 , x[ 4 ][ i ] + 1 } ] = 1 ;            
              }
              unite( pos[ { 4 , x[ 4 ][ i ] } ] , pos[ { 4 , x[ 4 ][ i + 1 ] } ] ) ;
          }
      }

if( A == 0 || ( i != 0 && x[ 4 ][ i ] - x[ 4 ][ i - 1 ] != 2 ) ){
        if( fn.find( { 2 , x[ 4 ][ i ] } ) == fn.end() ){
          A = 0 ; 
        }
        else{ 
        int ot = fn[ { 2 , x[ 4 ][ i ] } ] ;
        u.pb( ot ) ;
        v.pb( pos[ { 4 , x[ 4 ][ i ] } ] ) ; 
        a.pb( 3 ) ;
        if( dak.find( { 3 , x[ 4 ][ i ] - 1 } ) == dak.end() ){
          b.pb( x[ 4 ][ i ] - 1 ) ; dak[ { 3 , x[ 4 ][ i ] - 1 } ] = 1 ; }
        else{
          b.pb( x[ 4 ][ i ] + 1 ) ; dak[ { 3 , x[ 4 ][ i ] + 1 } ] = 1 ;         
        }
        unite( ot , pos[ { 4 , x[ 4 ][ i ] } ] ) ;   
        A = 1 ;
        }      
      } else A = 0 ; 

      if( B == 0 || ( i != 0 && x[ 4 ][ i ] - x[ 4 ][ i - 1 ] != 2 ) ){
        if( fn.find( { 6 , x[ 4 ][ i ] } ) == fn.end() ){
          B = 0 ; 
        }
        else{ 
        int ot = fn[ { 6 , x[ 4 ][ i ] } ] ;
        u.pb( ot ) ;
        v.pb( pos[ { 4 , x[ 4 ][ i ] } ] ) ; 
        a.pb( 5 ) ;
        if( dak.find( { 5 , x[ 4 ][ i ] - 1 } ) == dak.end() ){
          b.pb( x[ 4 ][ i ] - 1 ) ; dak[ { 5 , x[ 4 ][ i ] - 1 } ] = 1 ; }
        else{
          b.pb( x[ 4 ][ i ] + 1 ) ; dak[ { 5 , x[ 4 ][ i ] + 1 } ] = 1 ;         
        }
        unite( ot , pos[ { 4 , x[ 4 ][ i ] } ] ) ;   
        B = 1 ;
        }      
      } else B = 0 ; 
    } 

    FOR( i , x[ 6 ].size() ){
      if( i != x[ 6 ].size() - 1 ){
          if( x[ 6 ][ i + 1 ] - x[ 6 ][ i ] == 2 ){
              u.pb( pos[ { 6 , x[ 6 ][ i ] } ] ) ;
              v.pb( pos[ { 6 , x[ 6 ][ i + 1 ] } ] ) ;
              a.pb( 7 ) ; 
              b.pb( x[ 6 ][ i ] + 1 ) ;
              unite( pos[ { 6 , x[ 6 ][ i ] } ] , pos[ { 6 , x[ 6 ][ i + 1 ] } ] ) ;
          }
      }
    }

    int tt = find( 0 ) ;
    int tit = 0 ;
    FOR( i , n ) if( find( i ) != tt ) tit = -1 ;
    if( tit == -1 ) return 0 ;
    build( u , v , a , b ) ;
    return 1 ;

}



// int main() {
// 	assert(scanf("%d", &n) == 1);
// 	vector<int> x(n), y(n);
// 	for (int i = 0; i < n; i++) {
// 		assert(scanf("%d%d", &x[i], &y[i]) == 2);
// 	}
// 	fclose(stdin);

// 	build_called = false;
// 	const int possible = construct_roads(x, y);

// 	check(possible == 0 || possible == 1, "Invalid return value of construct_roads()");
// 	if (possible == 1) {
// 		check(build_called, "construct_roads() returned 1 without calling build()");
// 	} else {
// 		check(!build_called, "construct_roads() called build() but returned 0");
// 	}

// 	printf("OK\n");
// 	printf("%d\n", possible);
// 	if (possible == 1) {
// 		printf("%d\n", m);
// 		for (int j = 0; j < m; j++) {
// 			printf("%d %d %d %d\n", _u[j], _v[j], _a[j], _b[j]);
// 		}
// 	}
// 	fclose(stdout);
// 	return 0;
// }

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:13:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
......
  103 |     FOR( i , x[ 2 ].size() ){
      |          ~~~~~~~~~~~~~~~~~               
parks.cpp:103:5: note: in expansion of macro 'FOR'
  103 |     FOR( i , x[ 2 ].size() ){
      |     ^~~
parks.cpp:104:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |       if( i != x[ 2 ].size() - 1 ){
      |           ~~^~~~~~~~~~~~~~~~~~~~
parks.cpp:13:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
......
  116 |     FOR( i , x[ 4 ].size() ){
      |          ~~~~~~~~~~~~~~~~~               
parks.cpp:116:5: note: in expansion of macro 'FOR'
  116 |     FOR( i , x[ 4 ].size() ){
      |     ^~~
parks.cpp:118:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |       if( i != x[ 4 ].size() - 1 ){
      |           ~~^~~~~~~~~~~~~~~~~~~~
parks.cpp:13:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
......
  176 |     FOR( i , x[ 6 ].size() ){
      |          ~~~~~~~~~~~~~~~~~               
parks.cpp:176:5: note: in expansion of macro 'FOR'
  176 |     FOR( i , x[ 6 ].size() ){
      |     ^~~
parks.cpp:177:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |       if( i != x[ 6 ].size() - 1 ){
      |           ~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 4 ms 9656 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9596 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 447 ms 63040 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 6 ms 10068 KB Output is correct
26 Correct 9 ms 10324 KB Output is correct
27 Correct 9 ms 10580 KB Output is correct
28 Correct 149 ms 30932 KB Output is correct
29 Correct 233 ms 41768 KB Output is correct
30 Correct 334 ms 52372 KB Output is correct
31 Correct 469 ms 63024 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 6 ms 9716 KB Output is correct
34 Correct 5 ms 9704 KB Output is correct
35 Correct 5 ms 9704 KB Output is correct
36 Correct 5 ms 9700 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 4 ms 9684 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 4 ms 9704 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 10 ms 10324 KB Output is correct
45 Correct 182 ms 34652 KB Output is correct
46 Correct 319 ms 45792 KB Output is correct
47 Correct 267 ms 45736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 4 ms 9656 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9596 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 447 ms 63040 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 6 ms 10068 KB Output is correct
26 Correct 9 ms 10324 KB Output is correct
27 Correct 9 ms 10580 KB Output is correct
28 Correct 149 ms 30932 KB Output is correct
29 Correct 233 ms 41768 KB Output is correct
30 Correct 334 ms 52372 KB Output is correct
31 Correct 469 ms 63024 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 6 ms 9716 KB Output is correct
34 Correct 5 ms 9704 KB Output is correct
35 Correct 5 ms 9704 KB Output is correct
36 Correct 5 ms 9700 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 4 ms 9684 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 4 ms 9704 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 10 ms 10324 KB Output is correct
45 Correct 182 ms 34652 KB Output is correct
46 Correct 319 ms 45792 KB Output is correct
47 Correct 267 ms 45736 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Incorrect 4 ms 9700 KB Solution announced impossible, but it is possible.
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
17 Incorrect 5 ms 9632 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
17 Incorrect 252 ms 44776 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 147 ms 30768 KB Output is correct
10 Correct 14 ms 11988 KB Output is correct
11 Correct 65 ms 21060 KB Output is correct
12 Correct 19 ms 13012 KB Output is correct
13 Correct 45 ms 17904 KB Output is correct
14 Correct 6 ms 9836 KB Output is correct
15 Correct 7 ms 9988 KB Output is correct
16 Correct 149 ms 30856 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 4 ms 9656 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9596 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 447 ms 63040 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 6 ms 10068 KB Output is correct
26 Correct 9 ms 10324 KB Output is correct
27 Correct 9 ms 10580 KB Output is correct
28 Correct 149 ms 30932 KB Output is correct
29 Correct 233 ms 41768 KB Output is correct
30 Correct 334 ms 52372 KB Output is correct
31 Correct 469 ms 63024 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 6 ms 9716 KB Output is correct
34 Correct 5 ms 9704 KB Output is correct
35 Correct 5 ms 9704 KB Output is correct
36 Correct 5 ms 9700 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 4 ms 9684 KB Output is correct
39 Correct 4 ms 9684 KB Output is correct
40 Correct 4 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 4 ms 9704 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 10 ms 10324 KB Output is correct
45 Correct 182 ms 34652 KB Output is correct
46 Correct 319 ms 45792 KB Output is correct
47 Correct 267 ms 45736 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Incorrect 4 ms 9700 KB Solution announced impossible, but it is possible.
50 Halted 0 ms 0 KB -