Submission #342800

# Submission time Handle Problem Language Result Execution time Memory
342800 2021-01-02T20:43:34 Z ivan_tudor Money (IZhO17_money) C++14
45 / 100
1500 ms 51436 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int v[N];
multiset<int> ms;
void dbg(){
  cerr<<ms.size()<<"\n";
  for(auto x: ms)
    cerr<<x<<" ";
  cerr<<"\nok\n";
}

const int SIZE=1<<10;
char buffer[SIZE];
int point=SIZE;
inline char adv(){
  if(point==SIZE){
    fread(buffer,1,SIZE,stdin);
    point=0;
  }
  return buffer[point++];
}
inline int read(){
  char c;
  int x=0,sgn=1;
  c=adv();
  while(isdigit(c)==false && c!='-')
    c=adv();
  while(c=='-'){
    sgn*=-1;
    c=adv();
  }
  while(isdigit(c)){
    x=x*10+c-'0';
    c=adv();
  }
  return x*sgn;
}
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n;
  n = read();
  for(int i=1;i<=n;i++){
    v[i] = read();
    ms.insert(v[i]);
  }
  int ans = 0;
  for(int i= n; i>=1;){
    int j = i;
    ans++;
    multiset<int>::iterator num = ms.find(v[i]);

    while(j>=1 && v[j] == v[i]){
      multiset<int>::iterator nxt = num;
      num++;
      ms.erase(nxt);
      j--;
    }
    multiset<int>::iterator itr = num;
    if(itr != ms.begin()){
      itr = prev(itr);
      while(j>=1 && v[j] == (*itr)){
        j--;
        if(itr == ms.begin()){
          ms.erase(itr);
          break;
        }
        multiset<int>::iterator newitr = itr;
        newitr = prev(newitr);
        ms.erase(itr);
        itr = newitr;
      }
    }
    i = j;
  }
  cout<<ans;
  return 0;
}

Compilation message

money.cpp: In function 'char adv()':
money.cpp:18:10: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     fread(buffer,1,SIZE,stdin);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 171 ms 24812 KB Output is correct
40 Correct 393 ms 40536 KB Output is correct
41 Correct 127 ms 20076 KB Output is correct
42 Correct 163 ms 17900 KB Output is correct
43 Correct 110 ms 12652 KB Output is correct
44 Correct 447 ms 51308 KB Output is correct
45 Correct 416 ms 51308 KB Output is correct
46 Correct 442 ms 51284 KB Output is correct
47 Correct 283 ms 51204 KB Output is correct
48 Correct 311 ms 51308 KB Output is correct
49 Correct 1063 ms 51308 KB Output is correct
50 Correct 979 ms 51436 KB Output is correct
51 Correct 1106 ms 51308 KB Output is correct
52 Correct 1002 ms 51180 KB Output is correct
53 Correct 1098 ms 51180 KB Output is correct
54 Correct 1081 ms 51312 KB Output is correct
55 Execution timed out 1598 ms 51308 KB Time limit exceeded
56 Halted 0 ms 0 KB -