답안 #685099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685099 2023-01-23T12:02:51 Z speedyArda Money (IZhO17_money) C++14
100 / 100
1080 ms 51556 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6+5;
int pos[MAXN];
int in[MAXN];
int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> in[i];
    in[0] = 0;
    set<int> last; // so that we don't have duplicates
    int idx = 1, res = 1; // First segment
    while(idx <= n && in[idx] >= in[idx - 1])
    {
        last.insert(in[idx]);
        idx++;
    }
    if(idx > n)
    {
        cout << res << "\n";
        return 0;
    }

    for(idx; idx <= n; idx++)
    {
        int endidx = idx + 1;
        int firstnum = 0;
        if(last.lower_bound(in[idx]) != last.end())
        {
            firstnum = *(last.lower_bound(in[idx]));
        }
        int secondnum = 1e9;
        if(last.upper_bound(in[idx]) != last.end())
            secondnum = *(last.upper_bound(in[idx]));
        last.insert(in[idx]);
        idx++;
        while(idx <= n && in[idx] >= in[idx-1] && in[idx] <= secondnum)
        {
            last.insert(in[idx]);
            idx++;
        }
        res++; // New range
        idx--;
    }

    cout << res << "\n";
    
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:28:9: warning: statement has no effect [-Wunused-value]
   28 |     for(idx; idx <= n; idx++)
      |         ^~~
money.cpp:30:13: warning: unused variable 'endidx' [-Wunused-variable]
   30 |         int endidx = idx + 1;
      |             ^~~~~~
money.cpp:31:13: warning: variable 'firstnum' set but not used [-Wunused-but-set-variable]
   31 |         int firstnum = 0;
      |             ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 216 KB Output is correct
4 Correct 0 ms 216 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 216 KB Output is correct
11 Correct 0 ms 224 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 224 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 216 KB Output is correct
4 Correct 0 ms 216 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 216 KB Output is correct
11 Correct 0 ms 224 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 224 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 224 KB Output is correct
17 Correct 1 ms 224 KB Output is correct
18 Correct 1 ms 224 KB Output is correct
19 Correct 0 ms 224 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 224 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 224 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 216 KB Output is correct
4 Correct 0 ms 216 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 216 KB Output is correct
11 Correct 0 ms 224 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 224 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 224 KB Output is correct
17 Correct 1 ms 224 KB Output is correct
18 Correct 1 ms 224 KB Output is correct
19 Correct 0 ms 224 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 224 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 224 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 220 KB Output is correct
27 Correct 1 ms 220 KB Output is correct
28 Correct 1 ms 220 KB Output is correct
29 Correct 1 ms 220 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 328 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 216 KB Output is correct
4 Correct 0 ms 216 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 216 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 1 ms 216 KB Output is correct
10 Correct 0 ms 216 KB Output is correct
11 Correct 0 ms 224 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 224 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 224 KB Output is correct
17 Correct 1 ms 224 KB Output is correct
18 Correct 1 ms 224 KB Output is correct
19 Correct 0 ms 224 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 224 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 224 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 220 KB Output is correct
27 Correct 1 ms 220 KB Output is correct
28 Correct 1 ms 220 KB Output is correct
29 Correct 1 ms 220 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 328 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 47 ms 2440 KB Output is correct
40 Correct 85 ms 3648 KB Output is correct
41 Correct 41 ms 1996 KB Output is correct
42 Correct 39 ms 1920 KB Output is correct
43 Correct 27 ms 1392 KB Output is correct
44 Correct 99 ms 4408 KB Output is correct
45 Correct 102 ms 4480 KB Output is correct
46 Correct 115 ms 4368 KB Output is correct
47 Correct 85 ms 4416 KB Output is correct
48 Correct 86 ms 4472 KB Output is correct
49 Correct 444 ms 23044 KB Output is correct
50 Correct 415 ms 22932 KB Output is correct
51 Correct 431 ms 23136 KB Output is correct
52 Correct 457 ms 22956 KB Output is correct
53 Correct 472 ms 22976 KB Output is correct
54 Correct 425 ms 22984 KB Output is correct
55 Correct 1014 ms 51392 KB Output is correct
56 Correct 1073 ms 51432 KB Output is correct
57 Correct 1020 ms 51460 KB Output is correct
58 Correct 1080 ms 51500 KB Output is correct
59 Correct 996 ms 51556 KB Output is correct
60 Correct 1047 ms 51444 KB Output is correct
61 Correct 1006 ms 51460 KB Output is correct
62 Correct 1047 ms 51360 KB Output is correct