답안 #781472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781472 2023-07-13T06:48:04 Z lollipop 곤돌라 (IOI14_gondola) C++17
90 / 100
228 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 long long mod =  1000000009 ;
const int mod1 = 998244353 ;
const int N = 2e6 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;


signed valid(signed n, signed 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 ;
}
signed replacement(signed n, signed a[], signed replacementSeq[]){
    signed mx = 0 , mn = INT_MAX ;
    signed 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 ] ;   
signed countReplacement(signed n, signed a[]){
	se.clear() ;
	v.clear();
    ma.clear() ;	
		    long long ans = 1 ;
    signed x = valid( n , a ) ;
    if( x == 0 ) return 0 ; 
	signed mx = 0 ;
	FOR( i , n ) mx = max( mx , a[ i ] ) ;
	if( mx <= n ) return 1 ; 


   signed 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:153:9: warning: unused variable 'cnt' [-Wunused-variable]
  153 |     int cnt = 0 ;
      |         ^~~
gondola.cpp:176:6: warning: unused variable 'pas' [-Wunused-variable]
  176 |  int pas = ans ;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 11 ms 2920 KB Output is correct
7 Correct 7 ms 760 KB Output is correct
8 Correct 23 ms 5184 KB Output is correct
9 Correct 6 ms 1940 KB Output is correct
10 Correct 26 ms 5848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 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 12 ms 2932 KB Output is correct
7 Correct 7 ms 724 KB Output is correct
8 Correct 22 ms 5176 KB Output is correct
9 Correct 6 ms 1876 KB Output is correct
10 Correct 25 ms 5896 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 13 ms 2772 KB Output is correct
14 Correct 1 ms 268 KB Output is correct
15 Correct 44 ms 6148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 580 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 7 ms 992 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 21 ms 4892 KB Output is correct
14 Correct 7 ms 976 KB Output is correct
15 Correct 43 ms 10300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 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 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 36 ms 7760 KB Output is correct
10 Correct 27 ms 6412 KB Output is correct
11 Correct 12 ms 4048 KB Output is correct
12 Correct 13 ms 3660 KB Output is correct
13 Correct 6 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 37 ms 7680 KB Output is correct
10 Correct 27 ms 6340 KB Output is correct
11 Correct 12 ms 4092 KB Output is correct
12 Correct 16 ms 3660 KB Output is correct
13 Correct 5 ms 2888 KB Output is correct
14 Runtime error 228 ms 262144 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -