답안 #843178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843178 2023-09-03T18:44:23 Z manizare 수열 (BOI14_sequence) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h> 

#define int long long 
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int> 
#define int long long
using namespace std ;
mt19937 rng(time(0)) ;

const int maxn = 1e5 + 10 , inf = 1e17 + 10  ;
int a10[18] ;

int dfs(vector <int> vec , int ok = 1){
  if(vec.size() == 1){
    int s = vec.back() ;
    vector <int> vj ;  
    for(int i = 0 ;i < 10 ; i++){
      if(s>>i&1){
        vj.pb(i) ;
      }
    }
    if(vj.size() >= 2){
      if(vj[0] == 0){
        swap(vj[0] , vj[1]) ;
      }
    }else{
      if(ok == 0 && vj[0] == 0)return 0 ; 
      if(vj[0] == 0)return 10; 
    }
    int ans= 0 ;
    for(int i = 0 ; i < vj.size() ; i++){
      ans*=10;
      ans +=vj[i] ;
    }
    return ans ;
  }
  int ans = inf ; 
  for(int i = 0 ; i < 10 ; i++){
    int k = i , t = 0 ;
    vector <int> vec2 ; 
    for(int j = 0 ;j < vec.size() ; j++){
      if(k==10){
        k = 0 ;
        vec2.pb(t) ;
        t = 0 ;
      }
      if(vec[j]>>k&1){
        vec[j]-=(1<<k);
        t |= vec[j] ;
    }
    vec2.pb(t) ;
    if(vec == vec2 && ok == (i==0)){
      continue ;
    }
    ans = min(ans , dfs(vec2 , (i == 0)) * 10 + i) ;
  }
  return ans ;
}

signed main(){
  ios::sync_with_stdio(false); cin.tie(0) ;  
  a10[0] = 1;
  for(int i =1 ;i <= 17 ; i++){
    a10[i] = a10[i-1] * 10 ;
  }
  int n ;cin >> n ;
  vector <int> vec; 
  for(int i = 1; i <= n; i++){
    int x;
    cin >> x ;
    vec.pb((1<<x)) ;
  }
  cout << dfs(vec) ;
}

Compilation message

sequence.cpp: In function 'long long int dfs(std::vector<long long int>, long long int)':
sequence.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0 ; i < vj.size() ; i++){
      |                     ~~^~~~~~~~~~~
sequence.cpp:44:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int j = 0 ;j < vec.size() ; j++){
      |                    ~~^~~~~~~~~~~~
sequence.cpp:63:14: error: a function-definition is not allowed here before '{' token
   63 | signed main(){
      |              ^
sequence.cpp:77:1: error: expected '}' at end of input
   77 | }
      | ^
sequence.cpp:16:39: note: to match this '{'
   16 | int dfs(vector <int> vec , int ok = 1){
      |                                       ^
sequence.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      | ^