답안 #812812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812812 2023-08-07T11:11:37 Z lollipop 분수 공원 (IOI21_parks) C++17
15 / 100
434 ms 61504 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 tt= 0 ;
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{
                if( dak.find({ 3 , x[ 4 ][ i ] + 1 } ) != dak.end() ) tt = -1 ;
                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{
          if( dak.find({ 3 , x[ 4 ][ i ] + 1 } ) != dak.end() ) tt = -1 ;
          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{
          if( dak.find({ 5 , x[ 4 ][ i ] + 1 } ) != dak.end() ) tt = -1 ;
          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 ] } ] ) ;
          }
      }
    }
    if( tt == -1 ) return 0 ;
   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 ++ )
......
  117 |     FOR( i , x[ 4 ].size() ){
      |          ~~~~~~~~~~~~~~~~~               
parks.cpp:117:5: note: in expansion of macro 'FOR'
  117 |     FOR( i , x[ 4 ].size() ){
      |     ^~~
parks.cpp:119:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |       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 ++ )
......
  180 |     FOR( i , x[ 6 ].size() ){
      |          ~~~~~~~~~~~~~~~~~               
parks.cpp:180:5: note: in expansion of macro 'FOR'
  180 |     FOR( i , x[ 6 ].size() ){
      |     ^~~
parks.cpp:181:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |       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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 KB Output is correct
17 Correct 4 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9652 KB Output is correct
23 Correct 434 ms 61504 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 5 ms 9940 KB Output is correct
26 Correct 7 ms 10324 KB Output is correct
27 Correct 8 ms 10580 KB Output is correct
28 Correct 144 ms 30332 KB Output is correct
29 Correct 230 ms 40660 KB Output is correct
30 Correct 325 ms 51000 KB Output is correct
31 Correct 425 ms 61412 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 4 ms 9684 KB Output is correct
34 Correct 4 ms 9672 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 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 9692 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 8 ms 10268 KB Output is correct
45 Correct 181 ms 34112 KB Output is correct
46 Correct 253 ms 44588 KB Output is correct
47 Correct 279 ms 44548 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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 KB Output is correct
17 Correct 4 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9652 KB Output is correct
23 Correct 434 ms 61504 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 5 ms 9940 KB Output is correct
26 Correct 7 ms 10324 KB Output is correct
27 Correct 8 ms 10580 KB Output is correct
28 Correct 144 ms 30332 KB Output is correct
29 Correct 230 ms 40660 KB Output is correct
30 Correct 325 ms 51000 KB Output is correct
31 Correct 425 ms 61412 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 4 ms 9684 KB Output is correct
34 Correct 4 ms 9672 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 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 9692 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 8 ms 10268 KB Output is correct
45 Correct 181 ms 34112 KB Output is correct
46 Correct 253 ms 44588 KB Output is correct
47 Correct 279 ms 44548 KB Output is correct
48 Correct 4 ms 9684 KB Output is correct
49 Incorrect 4 ms 9684 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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 KB Output is correct
17 Incorrect 4 ms 9684 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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 KB Output is correct
17 Incorrect 247 ms 42676 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 4 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 3 ms 9684 KB Output is correct
7 Correct 5 ms 9656 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 157 ms 29972 KB Output is correct
10 Correct 13 ms 11956 KB Output is correct
11 Correct 64 ms 20572 KB Output is correct
12 Correct 19 ms 12884 KB Output is correct
13 Correct 40 ms 17536 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9940 KB Output is correct
16 Correct 145 ms 29960 KB Output is correct
17 Correct 4 ms 9684 KB Output is correct
18 Correct 4 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 4 ms 9684 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9652 KB Output is correct
23 Correct 434 ms 61504 KB Output is correct
24 Correct 4 ms 9684 KB Output is correct
25 Correct 5 ms 9940 KB Output is correct
26 Correct 7 ms 10324 KB Output is correct
27 Correct 8 ms 10580 KB Output is correct
28 Correct 144 ms 30332 KB Output is correct
29 Correct 230 ms 40660 KB Output is correct
30 Correct 325 ms 51000 KB Output is correct
31 Correct 425 ms 61412 KB Output is correct
32 Correct 4 ms 9684 KB Output is correct
33 Correct 4 ms 9684 KB Output is correct
34 Correct 4 ms 9672 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 4 ms 9684 KB Output is correct
37 Correct 4 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 9692 KB Output is correct
41 Correct 4 ms 9684 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 6 ms 10068 KB Output is correct
44 Correct 8 ms 10268 KB Output is correct
45 Correct 181 ms 34112 KB Output is correct
46 Correct 253 ms 44588 KB Output is correct
47 Correct 279 ms 44548 KB Output is correct
48 Correct 4 ms 9684 KB Output is correct
49 Incorrect 4 ms 9684 KB Solution announced impossible, but it is possible.
50 Halted 0 ms 0 KB -