-
Notifications
You must be signed in to change notification settings - Fork 0
/
11332.c
85 lines (77 loc) · 1.75 KB
/
11332.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
//
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
double factorial(int n);
void getComplexity(char*);
int main(void)
{
int cases;
scanf("%d", &cases);
for (int i = 0; i < cases; ++i) {
int n;
int localCases;
int timeLimit;
double timeElapsed;
char complexity[100];
getComplexity(complexity);
scanf("%d", &n);
scanf("%d", &localCases);
scanf("%d", &timeLimit);
if (!strcmp(complexity, "N")) {
timeElapsed = (double) n;
}
else if (!strcmp(complexity, "N^2")) {
timeElapsed = (double) n * n;
}
else if (!strcmp(complexity, "N^3")) {
timeElapsed = (double) n * n * n;
}
else if (!strcmp(complexity, "2^N")) {
timeElapsed = pow(2.0, (double) n);
}
else if (!strcmp(complexity, "N!")) {
timeElapsed = factorial(n);
}
timeElapsed *= localCases;
timeElapsed /= 100000000;
if (timeElapsed > timeLimit) {
printf("TLE!\n");
}
else {
printf("May Pass.\n");
}
}
return 0;
}
double factorial(int n)
{
double fact = 1;
double prev = fact;
for (int i = 0; i < n; ++i) {
prev = fact;
fact *= i + 1;
if (prev > fact) {
return prev;
}
}
return fact;
}
void getComplexity(char* complexity)
{
// char* const complexity = malloc(100);
int i = 0;
char ch;
bool store = false;
while ((ch = getchar()) != ')') {
if (ch == '(') {
store = true;
}
else if (store) {
complexity[i++] = ch;
}
}
complexity[i] = '\0';
}