Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 문자열
- XR Interaction Toolkit
- 재귀
- 트리
- VR
- 백트래킹
- 백준
- DFS
- 그래프
- 우선순위 큐
- 다이나믹 프로그래밍
- ue5
- 자료구조
- 투 포인터
- 시뮬레이션
- 유니온 파인드
- 수학
- 누적 합
- 유니티
- 구현
- 브루트포스
- 다익스트라
- 알고리즘
- BFS
- 정렬
- c++
- 그리디 알고리즘
- Team Fortress 2
- 스택
- Unreal Engine 5
Archives
- Today
- Total
1일1알
백준 11332번 시간초과 C++ 본문
https://www.acmicpc.net/problem/11332
11332번: 시간초과
각 테스트 케이스들에 대하여 시간 초과가 나면 "TLE!", 시간 초과가 나지 않으면 "May Pass." 를 출력한다.
www.acmicpc.net
범위를 넘어가는 수는 미리 차단해서 오버플로우를 방지한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int c;
const int TLENUM = 1000000001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> c;
while (c--) {
string str;
cin >> str;
int n, t, l;
cin >> n >> t >> l;
string com = "";
bool start = false;
for (int i = 0; i < str.length(); i++) {
if (start == false) {
if (str[i] == '(') start = true;
}
else {
if (str[i] == ')') break;
com += str[i];
}
}
int64 maxVal = 1;
int64 time = 100000000 * l;
bool pass = true;
if (com == "N") {
maxVal = n;
}
else if (com == "N^2") {
if (n >= 31263) pass = false;
maxVal = pow(n, 2);
}
else if (com == "N^3") {
if (n >= 1001) pass = false;
maxVal = pow(n, 3);
}
else if (com == "2^N") {
if (n >= 30) pass = false;
else maxVal = pow(2, n);
}
else if (com == "N!") {
if (n >= 13) pass = false;
else {
for (int i = 1; i <= n; i++) {
maxVal *= i;
}
}
}
maxVal *= t;
if (pass) {
if (maxVal > time) pass = false;
}
if (pass) cout << "May Pass.\n";
else cout << "TLE!\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 2942번 퍼거슨과 사과 C++ (0) | 2023.03.02 |
---|---|
백준 20208번 진우의 민트초코우유 C++ (0) | 2023.03.01 |
백준 14713번 앵무새 C++ (0) | 2023.02.27 |
백준 1972번 놀라운 문자열 C++ (0) | 2023.02.25 |
백준 18513번 샘터 C++ (0) | 2023.02.24 |