Submission #294290

#TimeUsernameProblemLanguageResultExecution timeMemory
294290BadrangiikhGondola (IOI14_gondola)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "gondola.h" using namespace std; int valid(int n, int inputSeq[]){ vector < pair < int , int > > vec ; vector < int > vc ; for ( int i = 0 ; i < n ; i ++ ) { if ( inputSeq [ i ] <= n ) { vec . push_back ( { inputSeq [ i ] , i } ) ; } vc . push_back ( inputSeq [ i ] ) ; } sort ( vc . begin ( ) , vc . end ( ) ) ; for ( int i = 1 ; i < vc . size ( ) ; i ++ ) { if ( vc [ i - 1 ] == vc [ i ] ) return 0 ; } sort ( vec . begin ( ) , vec . end ( ) ) ; for ( int i = 1 ; i < vec . size ( ) ; i ++ ) { if ( vec [ i ] . first - vec [ i - 1 ] . first != ( ( vec [ i ] . second - vec [ i - 1 ] . second ) % n + n ) % n ) { return 0 ; } } return 1 ; } int replacement(int n, int gondolaSeq[], int replacementSeq[]){ int maxx , minn , indx , x ; vector < int > vec ; vector < pair < int , int > > vc ; minn = n + 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( minn > gondolaSeq [ i ] ) { indx = i ; minn = gondolaSeq [ i ] ; } maxx = max ( maxx , gondolaSeq [ i ] ) ; } if ( minn <= n ) { for ( int i = ( n + indx - minn ) % n + 1 ; i <= ( n + indx - minn ) % n + n ; i ++ ) { vc . push_back ( { gondolaSeq [ i % n ] , i - ( ( n + indx - minn ) % n + 1 ) } ) ; } } else { for ( int i = 0 ; i < n ; i ++ ) { vc . push_back ( { gondolaSeq [ i ] , i } ) ; } } sort ( vc . begin ( ) , vc . end ( ) ) ; x = n + 1 ; for ( int i = 0 ; i < vc . size ( ) ; i ++ ) { if ( vc [ i ] . first == vc [ i ] . second + 1 ) continue ; vec . push_back ( vc [ i ] . second + 1 ) ; for ( int j = x ; j <= vc [ i ] . first - 1 ; j ++ ) { vec . push_back ( j ) ; } x = vc [ i ] . first + 1 ; } for ( int i = 0 ; i < vec . size ( ) ; i ++ ) { replacementSeq [ i ] = vec [ i ] ; } return maxx - n ; } long long zeregt ( int s1 , int s2 ) { long long zer [ 45 ] ; long long mod1 = 1e9+9 ; zer [ 0 ] = s1 ; for ( int i = 1 ; i <= 30 ; i ++ ) { zer [ i ] = zer [ i - 1 ] * zer [ i - 1 ] ; zer [ i ] %= mod1 ; } long long s3 = 1 ; for ( int i = 0 ; i <= 30 ; i ++ ) { if ( s2 % 2 == 1 ) { s3 *= zer [ i ] ; s3 %= mod1 ; } s2 /= 2 ; } return s3 ; } int countReplacement(int n, int inputSeq[]) { long long ans , mod ; int x , y , z , maxx , minn , indx ; vector < int > ch , vec ; vector < pair < int , int > > hc , vc ; for ( int i = 0 ; i < n ; i ++ ) { ch . push_back ( inputSeq [ i ] ) ; if ( inputSeq [ i ] <= n ) { hc . push_back ( { inputSeq [ i ] , i + 1 } ) ; } } sort ( ch . begin ( ) , ch . end ( ) ) ; for ( int i = 1 ; i < ch . size ( ) ; i ++ ) { if ( ch [ i ] == ch [ i - 1 ] ) { return 0 ; } } sort ( hc . begin ( ) , hc . end ( ) ) ; for ( int i = 1 ; i < hc . size ( ) ; i ++ ) { if ( hc [ i ] . first - hc [ i - 1 ] . first != ( ( hc [ i ] . second - hc [ i - 1 ] . second ) % n + n ) % n ) { return 0 ; } } minn = n + 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( minn > inputSeq [ i ] ) { indx = i ; minn = inputSeq [ i ] ; } maxx = max ( maxx , inputSeq [ i ] [ i ] ) ; } if ( minn <= n ) { for ( int i = ( n + indx - minn ) % n + 1 ; i <= ( n + indx - minn ) % n + n ; i ++ ) { vc . push_back ( { inputSeq [ i ] [ i % n ] , i - ( ( n + indx - minn ) % n + 1 ) } ) ; } } else { for ( int i = 0 ; i < n ; i ++ ) { vc . push_back ( { inputSeq [ i ] , i } ) ; } } sort ( vc . begin ( ) , vc . end ( ) ) ; mod = 1000000009 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vc [ i ] . first != i + 1 ) { x = i + 1 ; y = n - i ; break ; } } ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vc [ i ] . first == i + 1 ) { continue ; } z = vc [ i ] . first - x ; ans *= ( zeregt ( y , z ) % mod ) ; ans %= mod ; x = vc [ i ] . first + 1 ; y -- ; } x = ans ; return x ; }

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for ( int i = 1 ; i < vc . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~
gondola.cpp:19:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for ( int i = 1 ; i < vec . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for ( int i = 0 ; i < vc . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~
gondola.cpp:58:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for ( int i = 0 ; i < vec . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:95:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for ( int i = 1 ; i < ch . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~
gondola.cpp:101:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for ( int i = 1 ; i < hc . size ( ) ; i ++ ) {
      |                       ~~^~~~~~~~~~~~~~~
gondola.cpp:112:48: error: invalid types 'int[int]' for array subscript
  112 |         maxx = max ( maxx , inputSeq [ i ] [ i ] ) ;
      |                                                ^
gondola.cpp:116:55: error: invalid types 'int[int]' for array subscript
  116 |             vc . push_back ( { inputSeq [ i ] [ i % n ] , i - ( ( n + indx - minn ) % n + 1 ) } ) ;
      |                                                       ^
gondola.cpp:116:97: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
  116 |             vc . push_back ( { inputSeq [ i ] [ i % n ] , i - ( ( n + indx - minn ) % n + 1 ) } ) ;
      |                                                                                                 ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from gondola.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~