본문 바로가기

Programmers/효율성 시간초과 모음

[프로그래머스] 최고의 집합

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <string>
#include <vector>
#include <iostream>
using namespace std;
 
typedef long long ll;
 
//효율성 테스트 시간 초과 
vector<int> solution(int n, int s) {
    vector<int> answer;
    
    // vector<int> eles;
    
    if (n == 1 && s == 1) {
        answer.push_back(1); 
        return answer;
    }
    else if (n > s){
        answer.push_back(-1); 
        return answer;
    } 
    else {
        for (int i = n; i >= 1; i--) {
            int num = s/i;
            s -= num;
            answer.push_back(num);
        }
    }
 
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter