Submission #419402

# Submission time Handle Problem Language Result Execution time Memory
419402 2021-06-07T05:00:56 Z cpp219 Money (IZhO17_money) C++14
100 / 100
1243 ms 58044 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
set<ll> s;
ll n,a[N],L = inf,R,ans = 1;

bool chk(ll l,ll r){
    ll p = *s.upper_bound(l),q = *prev(s.lower_bound(r));
    return (q < p);
}

ll Travel(ll now){
    ll kq = now;
    ll l = a[now],r = a[now];
    for (ll i = now + 1;i <= n;i++){
        l = min(l,a[i]); r = max(r,a[i]);
        if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
    }

    return kq;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n; s.insert(0); s.insert(inf);
    for (ll i = 1;i <= n;i++) cin>>a[i];
    for (ll i = 1;i <= n;){
        ll nxt = Travel(i); //cout<<nxt<<"x\n"; //return 0;
        for (ll j = i;j <= nxt;j++) s.insert(a[j]);
        ans++;
        i = nxt + 1;
    }
    cout<<ans - 1;
}

Compilation message

money.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
money.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
money.cpp: In function 'int Travel(int)':
money.cpp:27:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |         if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
      |         ^~
money.cpp:27:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   27 |         if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
      |                                                  ^~
money.cpp: In function 'int main()':
money.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
money.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 1 ms 320 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 1 ms 320 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 73 ms 2372 KB Output is correct
40 Correct 129 ms 3688 KB Output is correct
41 Correct 58 ms 2076 KB Output is correct
42 Correct 63 ms 1840 KB Output is correct
43 Correct 41 ms 1444 KB Output is correct
44 Correct 156 ms 4424 KB Output is correct
45 Correct 170 ms 4384 KB Output is correct
46 Correct 154 ms 4520 KB Output is correct
47 Correct 136 ms 4368 KB Output is correct
48 Correct 141 ms 4420 KB Output is correct
49 Correct 537 ms 23044 KB Output is correct
50 Correct 562 ms 22872 KB Output is correct
51 Correct 543 ms 22872 KB Output is correct
52 Correct 562 ms 22952 KB Output is correct
53 Correct 551 ms 22952 KB Output is correct
54 Correct 547 ms 22992 KB Output is correct
55 Correct 1152 ms 51380 KB Output is correct
56 Correct 1243 ms 57896 KB Output is correct
57 Correct 1240 ms 58044 KB Output is correct
58 Correct 1215 ms 57840 KB Output is correct
59 Correct 1199 ms 58024 KB Output is correct
60 Correct 1181 ms 57988 KB Output is correct
61 Correct 1173 ms 57960 KB Output is correct
62 Correct 1203 ms 57868 KB Output is correct