답안 #50308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50308 2018-06-10T01:07:11 Z mra2322001 Money (IZhO17_money) C++14
45 / 100
1500 ms 101656 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;
        }
    }
    if(f[1]==n){
        cout << 1;
        return 0;
    }
    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]);
              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 2 ms 748 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 3 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 2 ms 748 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 3 ms 748 KB Output is correct
26 Correct 3 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 2 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 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 2 ms 748 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 3 ms 748 KB Output is correct
26 Correct 3 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 2 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 2 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 98 ms 19452 KB Output is correct
40 Correct 179 ms 37724 KB Output is correct
41 Correct 78 ms 37724 KB Output is correct
42 Correct 83 ms 37724 KB Output is correct
43 Correct 61 ms 37724 KB Output is correct
44 Correct 228 ms 44904 KB Output is correct
45 Correct 213 ms 44904 KB Output is correct
46 Correct 214 ms 44924 KB Output is correct
47 Correct 174 ms 44924 KB Output is correct
48 Correct 195 ms 44924 KB Output is correct
49 Correct 782 ms 66044 KB Output is correct
50 Correct 663 ms 66044 KB Output is correct
51 Correct 660 ms 68092 KB Output is correct
52 Correct 665 ms 68092 KB Output is correct
53 Correct 766 ms 68092 KB Output is correct
54 Correct 722 ms 68092 KB Output is correct
55 Execution timed out 1549 ms 101656 KB Time limit exceeded
56 Halted 0 ms 0 KB -