목록Algorithm (55)
눈송이의 개발생활

문제 https://www.acmicpc.net/problem/17427 코드 #1 - WRONG❌ #약수의 합 구하는 함수 def f(x): global list sum=0 for i in range(1, x+1): if(x%i==0): list.append(i) for z in list: sum += z list = [] return sum list = [] totalSum =0 n = int(input()) for j in range(1, n+1): totalSum += f(j) print(totalSum) 풀이 #1 - WRONG❌ 처음에는 모든 약수를 구하고, 그 약수의 합을 또 구하는 방법으로 풀었었다. 예제5에서 시간이 조금 걸리기는 했지만 pypy로 하면 될거라고 생각하고 제출했는데 시간초..

문제 https://www.acmicpc.net/problem/13305 코드 #include #include using namespace std; long long km[100000]; long long pr[100000]; int main(){ cin.tie(0), cout.tie(0); ios_base::sync_with_stdio(0); long long total = 0; int n; cin >> n; for(int i=0; i> km[i]; } for(int i=0; i> pr[i]; } long long pr_now = pr[0]; for (int i=1; i pr[i]){ total += pr_now * km[i-1]; pr_now = pr[i]; } else{ total += pr_now..

문제 https://www.acmicpc.net/problem/11047 코드 #include #include #include using namespace std; vector v; int main(){ cin.tie(0), cout.tie(0); ios_base::sync_with_stdio(0); int n, k, x; int count = 0; cin >> n >> k; for(int i=0; i> x ; v.push_back(x); } sort(v.begin(), v.end(), greater()); for(int i=0; i= 0){ k = k-v[i]; count++; } } cout

문제 https://www.acmicpc.net/problem/11568 코드 #include #include using namespace std; int dp[1001]; int arr[1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for(int i=0; i> arr[i]; dp[i]=1; } //LIS 사용 int result = 1; for(int i=0; i

문제 https://www.acmicpc.net/problem/11048 코드 #include #include using namespace std; int dp[1001][1001]; int arr[1001][1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i=1; i arr[i][j]; } } for(int i=1; i

문제 https://www.acmicpc.net/problem/11726 코드 #include #include using namespace std; int dp[1001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; dp[1]=1; dp[2]=2; for(int i=3; i

문제 https://www.acmicpc.net/problem/9095 코드 #include #include using namespace std; int dp[10001]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int tc, n; dp[1]= 1; dp[2]=2; dp[3]=4; cin >> tc; for(int i=0; i> n; for (int i=4; i

문제 https://www.acmicpc.net/problem/2346 코드 #include #include using namespace std; typedef pair pairs; deque dq; int main(void){ cin.tie(0);cout.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for(int i=0; i> x; dq.push_back(make_pair(i+1, x)); } while(!dq.empty()){ pairs poped = dq.front(); cout