[BaekJoon] #10162 - 전자레인지 [Java][C++]
[BaekJoon] #10162 - 전자레인지 [Java][C++]
1. 아이디어
각 버튼이 서로 배수, 약수 관계에 있어서 최소 조작을 하려면 지정된 시간이 큰 버튼부터 누르면 된다. 지정된 시간이 가장 작은 버튼이 10초를 더하므로 초기 요리시간을 10으로 나눈 나머지가 0이 아니면 불가능한 경우이다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int a = t / 300;
t %= 300;
int b = t / 60;
t %= 60;
int c = t / 10;
t %= 10;
if (t == 0) {
System.out.println(a + " " + b + " " + c);
} else {
System.out.println(-1);
}
}
}
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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
int a = t / 300;
t %= 300;
int b = t / 60;
t %= 60;
int c = t / 10;
t %= 10;
if (t) {
cout << -1;
} else {
cout << a << ' ' << b << ' ' << c;
}
}
This post is licensed under CC BY 4.0 by the author.