Submission #685098

# Submission time Handle Problem Language Result Execution time Memory
685098 2023-01-23T12:01:56 Z speedyArda Money (IZhO17_money) C++14
100 / 100
1238 ms 58064 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6+5;
int pos[MAXN];
int in[MAXN];
int main() 
{
    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:26:9: warning: statement has no effect [-Wunused-value]
   26 |     for(idx; idx <= n; idx++)
      |         ^~~
money.cpp:28:13: warning: unused variable 'endidx' [-Wunused-variable]
   28 |         int endidx = idx + 1;
      |             ^~~~~~
money.cpp:29:13: warning: variable 'firstnum' set but not used [-Wunused-but-set-variable]
   29 |         int firstnum = 0;
      |             ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 308 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 308 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 164 ms 5356 KB Output is correct
40 Correct 241 ms 8696 KB Output is correct
41 Correct 110 ms 4344 KB Output is correct
42 Correct 116 ms 3884 KB Output is correct
43 Correct 96 ms 2788 KB Output is correct
44 Correct 320 ms 10824 KB Output is correct
45 Correct 300 ms 10760 KB Output is correct
46 Correct 318 ms 11088 KB Output is correct
47 Correct 309 ms 10976 KB Output is correct
48 Correct 288 ms 10932 KB Output is correct
49 Correct 661 ms 29596 KB Output is correct
50 Correct 605 ms 29464 KB Output is correct
51 Correct 600 ms 29396 KB Output is correct
52 Correct 651 ms 29624 KB Output is correct
53 Correct 620 ms 29764 KB Output is correct
54 Correct 604 ms 29380 KB Output is correct
55 Correct 1147 ms 57900 KB Output is correct
56 Correct 1220 ms 57900 KB Output is correct
57 Correct 1146 ms 57916 KB Output is correct
58 Correct 1193 ms 57796 KB Output is correct
59 Correct 1190 ms 57940 KB Output is correct
60 Correct 1180 ms 58064 KB Output is correct
61 Correct 1217 ms 57912 KB Output is correct
62 Correct 1238 ms 58048 KB Output is correct