답안 #781446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781446 2023-07-13T06:32:23 Z lollipop 곤돌라 (IOI14_gondola) C++17
90 / 100
262 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() , 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 ++ ;
    		//cout << x << " " << nd << endl ;
    		if( x == nd ) break ; 
		}
		lf -- ; 
	}	
	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 ;
      |         ^~~
# 결과 실행 시간 메모리 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 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 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 212 KB Output is correct
6 Correct 10 ms 2388 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 19 ms 4272 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 22 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2428 KB Output is correct
7 Correct 7 ms 1096 KB Output is correct
8 Correct 19 ms 4336 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 26 ms 4940 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 13 ms 2352 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 31 ms 5180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 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 316 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 212 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 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 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 468 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 6 ms 1364 KB Output is correct
12 Correct 7 ms 1480 KB Output is correct
13 Correct 21 ms 4936 KB Output is correct
14 Correct 6 ms 1276 KB Output is correct
15 Correct 42 ms 10308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 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 324 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 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 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 320 KB Output is correct
5 Correct 1 ms 212 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
9 Correct 35 ms 5700 KB Output is correct
10 Correct 31 ms 4648 KB Output is correct
11 Correct 11 ms 2772 KB Output is correct
12 Correct 13 ms 2516 KB Output is correct
13 Correct 5 ms 1860 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 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 36 ms 5696 KB Output is correct
10 Correct 26 ms 4668 KB Output is correct
11 Correct 11 ms 2772 KB Output is correct
12 Correct 13 ms 2596 KB Output is correct
13 Correct 5 ms 1868 KB Output is correct
14 Runtime error 262 ms 262144 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -