Gidhub BE Developer

2018 SW 교육 페스티벌 디지털 과거 Code+ 후기

2018-10-03
goodGid


1번

  • 문자열 처리 로직이 까다로울 것 같아서 우선 패스했다.

2번

#include <string>
#include <vector>
#include <iostream>
#include <sstream>
using namespace std;

int max_arr[9];
int init_arr[9];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> max_arr[i];
    }
    
    for(int i=1; i<=n; i++){
        cin >> init_arr[i];
        if(max_arr[i] < init_arr[i]){
            cout << "-1" << '\n';
            return 0;
        }
    }
    
    int cnt;
    cin >> cnt;
    int tmp = 0;
    while (cnt) {
        init_arr[n]++;
        cnt--;
        tmp++;
        if(init_arr[n] > max_arr[n]){
            init_arr[n-1]++;
            init_arr[n] = 0;
        }
    }
    
    for(int i=n-1; i>0; i--){
        while(init_arr[i] > max_arr[i]){
            init_arr[i] -= max_arr[i]+1; //[1]
            init_arr[i-1]++;
        }
    }
    
    for(int i=1; i<=n; i++){
        cout << init_arr[i];
    }
    
    return 0;
}
  • [1] : init_arr[i] -= max_arr[i]+1 가 아닌
    init_arr[i] -= max_arr[i]로 해서 잘못된 부분을 찾는데 시간이 걸렸다.

3번

#include <queue>
#include <iostream>
#include<cstring>
using namespace std;

int map[51][51];
int dp[51][51];
int n,m;
bool inRange(int x, int y){
    if( x >= 0 && x < n && y >= 0 && y < m)
        return true;
    return false;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    memset(dp,-1,sizeof(dp));
    
    cin >> n >> m;
    
    queue<pair<int,int>> q;
    q.push({0,0});
    dp[0][0] = 0;

    int ans= -1;
    while (! q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
    
        int nx;
        int ny;
        
        nx = x + 2;
        ny = y + 1;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        nx = x + 1;
        ny = y + 2;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        nx = x - 2;
        ny = y + 1;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        
        nx = x - 1;
        ny = y + 2;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        
        nx = x - 2;
        ny = y - 1;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        
        nx = x - 1;
        ny = y - 2;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        
        nx = x + 2;
        ny = y - 1;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
        
        nx = x + 1;
        ny = y - 2;
        if(inRange(nx, ny) && dp[nx][ny] == -1){
            dp[nx][ny] = dp[x][y] + 1;
            ans = ans < dp[nx][ny] ? dp[nx][ny] : ans ;
            q.push({nx,ny});
        }
    
    }
    
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(dp[i][j] == -1){
                cout << "F" << ans << endl;
                return 0;
            }
        }
    }
    
    cout << "T" << ans << endl;
    return 0;
}

4번

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

int dp[21];
int arr[21];
int target;
int flag;
void dfs(vector<int> v, int st_idx, int cnt, int sum){
    int size = (int) v.size();
    if( cnt == 3 ){
        if( sum == target){
            flag = true;
            vector<int> tmp;
            for(int i=0; i<size; i++){
                if(dp[i] == 1)
                    tmp.push_back(v[i]);
            }
            cout << tmp[0] << " " << tmp[1] << " " << tmp[2] << '\n';
        }
        return ;
    }
    
    for(int i=st_idx; i < size; i++){
        dp[i] = 1;
        dfs(v, i+1, cnt+1, sum + v[i]);
        dp[i] = 0;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    //[1]
    int size = 0;
    for(int i=0 ; ; i++){
        int tmp;
        tmp = cin.get();
        if( tmp == '\n')
            break;
        arr[i] = tmp - '0';
        size++;
    }

    vector<int> v;
    for(int i=0; i<size; i+=2){
        v.push_back(arr[i]);
    }
    
    cin >> target;

    sort(v.begin(), v.end());
    
    dfs(v, 0, 0, 0);
    if(!flag)
        cout << "NO" << endl;

    return 0;
}
  • 입력 N값이 주어지지 않는 상태로 입력을 받아야해서 난감했다.

  • cin.get()은 char 형으로 입력을 받아서 ‘0’을 빼줬다.


Review

  • 전체적으로 무난했는데 시간 분배와 정확성 있는 코딩을 못했던 점이 아쉽다.

  • 그리고 예선전 결과 연락이 왔다.

  • (뇌피셜…) 2,3,4번을 풀었으면 합격
    나처럼 2,3번을 풀었으면 예비 합격자인듯 하다.


Similar Posts

Comments