Submission #781460

# Submission time Handle Problem Language Result Execution time Memory
781460 2023-07-13T06:39:13 Z lollipop Gondola (IOI14_gondola) C++17
90 / 100
272 ms 262144 KB
#include "gondola.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
//#define int 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 =  1000000009 ;
const int mod1 = 998244353 ;
const int N = 2e6 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;


int valid(int n, int a[]){
    int pos = 0 ;
    FOR( i , n ){
    	if( a[ i ] <= n ){
    		pos = i ; break ; 
		}
	}
	ma.clear() ;
    FOR( i , n ) if( a[ i ] == 0 ){
    	return 0 ; 
	} 
	FOR( i , n ){
		if( ma[ a[ i ] ] == 1 ) return 0 ;
		ma[ a[ i ] ] = 1 ; 
	} 
	int j = pos , cur = a[ pos ] ; 
	while( true ){
		if( a[ j ] <= n ){
			if( a[ j ] != cur ) return 0 ;
		}
		cur ++ ; if( cur == n + 1 ) cur = 1 ;
		j ++ ; j %= n ; 
		if( j == pos ) break ; 
	}
	return 1 ;
}
int replacement(int n, int a[], int replacementSeq[]){
    int mx = 0 , mn = INT_MAX ;
    int b[ n ] ;
    set < int > se ; 
    FOR( i , n ){
    	mn = min( mn , a[ i ] ) ;
    	mx = max( mx , a[ i ] ) ;
	}
	for( int j = n + 1 ; j <= mx ; j ++ ) se.insert( j ) ;
//	FOR( i , n ){
//		if( a[ i ] > n ) se.erase( se.find( a[ i ] ) ) ; 
//	}
    if( mn > n ){
    	FOR( i , n ) b[ i ] = i + 1 ; 
	}
    else{
       int pos = 0 ;
  	   FOR( i , n ){
     		if( a[ i ] <= n ){
    	 		pos = i ; break ; 
		 	}
	   }
		int j = pos , cur = a[ pos ] ; 
		while( true ){
			b[ j ] = cur ; 
			cur ++ ; if( cur == n + 1 ) cur = 1 ;
			j ++ ; j %= n ; 
			if( j == pos ) break ; 
		}	  
	}
    int cnt = 0 ;
    vector < pair < int , int > > v ; 
    FOR( i , n ){
    	if( a[ i ] == b[ i ] ) continue ;
    	v.pb( { a[ i ] , b[ i ] } ) ;
	}
    sort( v.begin() , v.end() ) ;
    for( auto x : v ){
    	int lst = x.s ;
    	int nd = x.f ;
    	while( true ){
    		int x = *se.begin() ;
    		replacementSeq[ cnt ] = lst ;
    		cnt ++ ;
    		lst = x ;
    		se.erase( se.begin() ) ;
    		//cout << x << " " << nd << endl ;
    		if( x == nd ) break ; 
		}
	}
	return cnt ;
}
vector < int > se ;
vector < int > v ; 
int b[ N ] ;   
int countReplacement(int n, int a[]){
	se.clear() ;
	v.clear();
    ma.clear() ;	
		    long long ans = 1 ;
int pos = 0 ;
    FOR( i , n ){
    	if( a[ i ] <= n ){
    		pos = i ; break ; 
		}
	}
	ma.clear() ;
    FOR( i , n ) if( a[ i ] == 0 ){
    	return 0 ; 
	} 
	FOR( i , n ){
		if( ma[ a[ i ] ] == 1 ) return 0 ;
		ma[ a[ i ] ] = 1 ; 
	} 
	int j = pos , cur = a[ pos ] ; 
	while( true ){
		if( a[ j ] <= n ){
			if( a[ j ] != cur ) return 0 ;
		}
		cur ++ ; if( cur == n + 1 ) cur = 1 ;
		j ++ ; j %= n ; 
		if( j == pos ) break ; 
	}
	int mx = 0 ;
	FOR( i , n ) mx = max( mx , a[ i ] ) ;
	if( mx <= n ) return 1 ; 


   int mn = INT_MAX ; 
    FOR( i , n ){
    	mn = min( mn , a[ i ] ) ;
    	mx = max( mx , a[ i ] ) ;
	}
	for( int j = n + 1 ; j <= mx ; j ++ ) se.pb( j ) ;
    if( mn > n ){
    	ans = n ; 
    	FOR( i , n ) b[ i ] = i + 1 ; 
	}
    else{
       int pos = 0 ;
  	   FOR( i , n ){
     		if( a[ i ] <= n ){
    	 		pos = i ; break ; 
		 	}
	   }
		int j = pos , cur = a[ pos ] ; 
		while( true ){
			b[ j ] = cur ; 
			cur ++ ; if( cur == n + 1 ) cur = 1 ;
			j ++ ; j %= n ; 
			if( j == pos ) break ; 
		}	  
	}
    int cnt = 0 ;
    FOR( i , n ){
    	if( a[ i ] == b[ i ] ) continue ;
    	v.pb( a[ i ] ) ;
	}
    sort( v.begin() , v.end() ) ;
    long long lf = v.size() ;
	int st = 0 ; 
    for( auto x : v ){
   // 	int lst = x.s ;
    	int nd = x ;
    	while( true ){
    		int x = se[ st ] ;
    		if( x != nd ){
    			ans = ans * lf ; 
    			ans %= mod ;
			}
    		st ++ ;
    		if( x == nd ) break ; 
		}
		lf -- ; 
	}	
	ans %= mod ; 
	int pas = ans ; 
	
	return ans ; 
		
}


//int gondolaSequence[100001];
//int replacementSequence[250001];
//
//int main() {
//  int i, n, tag;
//  int nr;
//  assert(scanf("%d", &tag) == 1);
//  assert(scanf("%d", &n) == 1);
//  for (i = 0; i < n; i++)
//    assert(scanf("%d", &gondolaSequence[i]) == 1);
//
//  switch (tag) {
//  case 1:
//  case 2:
//  case 3:
//    printf("%d\n", valid(n, gondolaSequence));
//    break;
//
//  case 4:
//  case 5:
//  case 6:
//    nr = replacement(n, gondolaSequence, replacementSequence);
//    printf("%d ", nr);
//    if (nr > 0) {
//      for (i = 0; i < nr - 1; i++)
//        printf("%d ", replacementSequence[i]);
//      printf("%d\n", replacementSequence[nr - 1]);
//    } else
//      printf("\n");
//    break;
//
//  case 7:
//  case 8:
//  case 9:
//  case 10:
//    printf("%d\n", countReplacement(n, gondolaSequence));
//    break;
//  }
//
//  return 0;
//}




Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:174:9: warning: unused variable 'cnt' [-Wunused-variable]
  174 |     int cnt = 0 ;
      |         ^~~
gondola.cpp:197:6: warning: unused variable 'pas' [-Wunused-variable]
  197 |  int pas = ans ;
      |      ^~~
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 18 ms 3924 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 22 ms 4568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 2132 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 19 ms 3844 KB Output is correct
9 Correct 5 ms 1364 KB Output is correct
10 Correct 24 ms 4436 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 13 ms 2004 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 32 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 6 ms 844 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 22 ms 4692 KB Output is correct
14 Correct 6 ms 844 KB Output is correct
15 Correct 43 ms 10272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 33 ms 5188 KB Output is correct
10 Correct 33 ms 4312 KB Output is correct
11 Correct 11 ms 2516 KB Output is correct
12 Correct 13 ms 2352 KB Output is correct
13 Correct 5 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 36 ms 5220 KB Output is correct
10 Correct 25 ms 4384 KB Output is correct
11 Correct 13 ms 2516 KB Output is correct
12 Correct 14 ms 2340 KB Output is correct
13 Correct 5 ms 1740 KB Output is correct
14 Runtime error 272 ms 262144 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -