[BaekJoon] #15439 - 베라의 패션 [Java][C++]
[BaekJoon] #15439 - 베라의 패션 [Java][C++]
1. 아이디어
상의와 하의가 각각 $N$개씩 있으므로 상의에서 하나, 하의에서 하나를 뽑는 모든 조합은 $N^2$가지다. 같은 색상이 한 세트씩 있으므로 같은 색상 조합은 $N$가지이고, 따라서 서로 다른 색상 조합은 $N^2 - N$가지다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
System.out.println(n * n - n);
}
}
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
cout << n * n - n;
}
This post is licensed under CC BY 4.0 by the author.