Submission #50307

# Submission time Handle Problem Language Result Execution time Memory
50307 2018-06-10T01:05:30 Z mra2322001 Money (IZhO17_money) C++14
45 / 100
1500 ms 101684 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)

using namespace std;
typedef long long ll;
const int N = 1e6 + 5;

int n, a[N], f[N];
set <int> s;

int solve(int u, int sl){
    if(u== n + 1) return printf("%d", sl), 0;
    int v = f[u];
    int l = u, r = v, ans = u;
    auto it = s.upper_bound(a[u]);
    int x = *it;
    for(int k = u; k <= f[u]; k++){
        if(a[k] > x){
            solve(k, sl + 1);
            return 0;
        }
        else{
            s.insert(a[k]);
        }
    }
    solve(f[u] + 1, sl + 1);
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
   
    scanf("%d", &n);
    f1(i, n) scanf("%d", &a[i]);
    for(int i = n; i >= 1; i--){
        if(i==n) f[i] = n;
        else{
            if(a[i] <= a[i + 1]) f[i] = f[i + 1];
            else f[i] = i;
        }
    }
    s.insert(0); s.insert(1e6 + 5);
    solve(1, 0);
}

Compilation message

money.cpp: In function 'int solve(int, int)':
money.cpp:15:9: warning: unused variable 'l' [-Wunused-variable]
     int l = u, r = v, ans = u;
         ^
money.cpp:15:16: warning: unused variable 'r' [-Wunused-variable]
     int l = u, r = v, ans = u;
                ^
money.cpp:15:23: warning: unused variable 'ans' [-Wunused-variable]
     int l = u, r = v, ans = u;
                       ^~~
money.cpp: In function 'int main()':
money.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
money.cpp:35:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     f1(i, n) scanf("%d", &a[i]);
              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
9 Correct 2 ms 528 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 3 ms 684 KB Output is correct
12 Correct 2 ms 684 KB Output is correct
13 Correct 2 ms 684 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 3 ms 684 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
9 Correct 2 ms 528 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 3 ms 684 KB Output is correct
12 Correct 2 ms 684 KB Output is correct
13 Correct 2 ms 684 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 3 ms 684 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 2 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
9 Correct 2 ms 528 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 3 ms 684 KB Output is correct
12 Correct 2 ms 684 KB Output is correct
13 Correct 2 ms 684 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 3 ms 684 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 2 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 3 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 2 ms 528 KB Output is correct
9 Correct 2 ms 528 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 3 ms 684 KB Output is correct
12 Correct 2 ms 684 KB Output is correct
13 Correct 2 ms 684 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 3 ms 684 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 2 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 3 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 748 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 109 ms 19400 KB Output is correct
40 Correct 194 ms 37632 KB Output is correct
41 Correct 81 ms 37632 KB Output is correct
42 Correct 93 ms 37632 KB Output is correct
43 Correct 76 ms 37632 KB Output is correct
44 Correct 225 ms 44948 KB Output is correct
45 Correct 265 ms 44948 KB Output is correct
46 Correct 245 ms 44964 KB Output is correct
47 Correct 191 ms 44964 KB Output is correct
48 Correct 236 ms 44964 KB Output is correct
49 Correct 781 ms 66172 KB Output is correct
50 Correct 709 ms 66172 KB Output is correct
51 Correct 793 ms 68220 KB Output is correct
52 Correct 796 ms 68220 KB Output is correct
53 Correct 706 ms 68220 KB Output is correct
54 Correct 698 ms 68220 KB Output is correct
55 Execution timed out 1523 ms 101684 KB Time limit exceeded
56 Halted 0 ms 0 KB -