Submission #342800

#TimeUsernameProblemLanguageResultExecution timeMemory
342800ivan_tudorMoney (IZhO17_money)C++14
45 / 100
1598 ms51436 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...