티스토리 뷰

백준/실버

[백준 11332번] 시간초과 (C++)

게임개발기원 2023. 2. 14. 22:55

문제링크 : https://www.acmicpc.net/problem/11332

 

11332번: 시간초과

각 테스트 케이스들에 대하여 시간 초과가 나면 "TLE!", 시간 초과가 나지 않으면 "May Pass." 를 출력한다.

www.acmicpc.net

 

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MAX 100000000

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int C;
    LL N, T, L;
    string S;

    cin >> C;

    while(C--)
    {
        cin >> S >> N >> T >> L;
        if(S == "O(N)")
        {
            if(N*T <= (L * MAX))
            {
                cout << "May Pass.\n";
            }    
            else
            {
                cout << "TLE!" <<"\n";
            }
        }
        else if (S == "O(N^2)")
        {
            if (N >= 31623) {
			    cout << "TLE!\n";
		    }
            else
            {
                if(N * N * T <= (L * MAX))
                {
                    cout << "May Pass.\n";
                }    
                else
                {
                    cout << "TLE!\n";
                }
            }
        }
        else if (S == "O(N^3)")
        {
            if (N >= 1001) {
			    cout << "TLE!\n";
		    }
            else
            {
                if(N * N * N * T <= (L * MAX))
                {
                    cout << "May Pass.\n";
                }    
                else
                {
                    cout << "TLE!\n";
                }
            }
        }
        else if (S == "O(2^N)")
        {
            if (N >= 30) {
			    cout << "TLE!\n";
		    }
            else
            {
                long long result = 1;
                for(int i=0; i<N; i++)
                {
                    result *=2;
                }
                if(result * T <= (L * MAX))
                {
                    cout << "May Pass.\n";
                }    
                else
                {
                    cout << "TLE!\n";
                }
            }
        }
        else if (S == "O(N!)")
        {
            if (N >= 13) {
			    cout << "TLE!\n";
		    }
            else
            {
                LL result = 1;
                for(LL i=1; i<=N; i++)
                {
                    result*=i;
                }
                if(result * T <= (L * MAX))
                {
                    cout << "May Pass.\n";
                }    
                else
                {
                    cout << "TLE!\n";
                }
            }
        }      
    }   
    return 0;
}

정신건강에 해로운 문제다..

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/11   »
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
글 보관함